diff --git a/static/js/map.js b/static/js/map.js index 8fb12057bee89be4c6ce3437f347c0b22610d8ed..0f682ad94c1e86a0e8272b82d6cca91cd79bc81d 100644 --- a/static/js/map.js +++ b/static/js/map.js @@ -15,6 +15,7 @@ BusMap.Map = function(opts) { this.opts = opts; var stops = {}; var routes = {}; + var modal_cache = {}; var that = this; window._busmap = this; @@ -399,10 +400,18 @@ BusMap.Map = function(opts) { query: "modal", modal_name: name, }; - $.get("ajax", params).done(function(contents) { - modal.append(contents); - }); - setUrlFromView(); + if (modal_cache[name]) { + modal.append(modal_cache[name]); + setUrlFromView(); + } else { + $.get("ajax", params).done(function(contents) { + modal_cache[name] = contents; + modal.append(contents); + setUrlFromView(); + }).fail(function() { + modal.append("Please refresh the page and try again."); + }); + } } // Scaling: update what is displayed based on zoom level @@ -428,7 +437,7 @@ BusMap.Map = function(opts) { return; } var hash = window.location.hash.substring(1); - if (hash == "") return false; + if (hash == "") return; var parts = hash.split(";"); // First part: view string (lat,lon,zoom; vehicle; or stop) applyViewString(parts[0]);