From 502b0e4862c30c7b5bbaa8b05cc698180ef7de60 Mon Sep 17 00:00:00 2001
From: Brandon Bergren <bdragon@rtk0.net>
Date: Fri, 5 Nov 2010 18:47:05 +0000
Subject: [PATCH] RMT cache -- clicking on the same rmt marker more than once
 will show the previously fetched data instead of loading again.

---
 js/marker.js | 39 ++++++++++++++++++++++++---------------
 1 file changed, 24 insertions(+), 15 deletions(-)

diff --git a/js/marker.js b/js/marker.js
index e1e85da..8b6ddcf 100644
--- a/js/marker.js
+++ b/js/marker.js
@@ -65,22 +65,31 @@ Drupal.gmap.addHandler('gmap', function (elem) {
     }
     // AJAX content
     if (marker.rmt) {
-      var uri = marker.rmt;
-      // If there was a callback, prefix that.
-      // (If there wasn't, marker.rmt was the FULL path.)
-      if (obj.vars.rmtcallback) {
-        uri = obj.vars.rmtcallback + '/' + marker.rmt;
+      obj.rmtcache = obj.rmtcache || {};
+      
+      // Cached RMT.
+      if (obj.rmtcache[marker.rmt]) {
+        marker.marker.openInfoWindowHtml(obj.rmtcache[marker.rmt]);
+      }
+      else {
+        var uri = marker.rmt;
+        // If there was a callback, prefix that.
+        // (If there wasn't, marker.rmt was the FULL path.)
+        if (obj.vars.rmtcallback) {
+          uri = obj.vars.rmtcallback + '/' + marker.rmt;
+        }
+        // @Bevan: I think it makes more sense to do it in this order.
+        // @Bevan: I don't like your choice of variable btw, seems to me like
+        // @Bevan: it belongs in the map object, or at *least* somewhere in
+        // @Bevan: the gmap settings proper...
+        //if (!marker.text && Drupal.settings.loadingImage) {
+        //  marker.marker.openInfoWindowHtml(Drupal.settings.loadingImage);
+        //}
+        $.get(uri, {}, function (data) {
+          obj.rmtcache[marker.rmt] = data;
+          marker.marker.openInfoWindowHtml(data);
+        });
       }
-      // @Bevan: I think it makes more sense to do it in this order.
-      // @Bevan: I don't like your choice of variable btw, seems to me like
-      // @Bevan: it belongs in the map object, or at *least* somewhere in
-      // @Bevan: the gmap settings proper...
-      //if (!marker.text && Drupal.settings.loadingImage) {
-      //  marker.marker.openInfoWindowHtml(Drupal.settings.loadingImage);
-      //}
-      $.get(uri, {}, function (data) {
-        marker.marker.openInfoWindowHtml(data);
-      });
     }
     // Tabbed content
     else if (marker.tabs) {
-- 
GitLab