From 23352fc2a9068161e20bc7265333d36127f5f7c1 Mon Sep 17 00:00:00 2001 From: Anton Sarukhanov <code@ant.sr> Date: Wed, 4 May 2016 17:14:50 -0400 Subject: [PATCH] If a stop has been clicked on the map, default to that stop in the Embed dialog. --- static/js/embed.js | 15 ++++++++++----- static/js/map.js | 14 +++++++++----- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/static/js/embed.js b/static/js/embed.js index ab9f736..5d2db04 100644 --- a/static/js/embed.js +++ b/static/js/embed.js @@ -1,14 +1,13 @@ BusMap.Embed = function(opts) { - this.opts = opts; var embedVars = {}; - var that = this; + var that = this.Embed; + that.opts = opts; /* Constructor - initialize the embed form */ function init() { bindEventHandlers(); populateOptions(); } - var updateEmbedCode = function() { // Grab HTML representation of preview; trim whitespace. var code = $("#embed-preview").html().trim(); @@ -33,8 +32,14 @@ BusMap.Embed = function(opts) { opt.appendTo("#embed-stop"); } if ($("#embed-stop option").length > 1 && !$("#embed-stop").val()) { - // We have stops. Select the first one. - $("#embed-stop option:nth-child(2)").prop('selected', true); + // We have stops. + if (window._busmap.selectedStop) { + // Select the last one clicked if available. + $("#embed-stop").val(window._busmap.selectedStop); + } else { + // Select the first one. + $("#embed-stop option:nth-child(2)").prop('selected', true); + } $("#embed-stop").change(); // fire event to handle the change } } diff --git a/static/js/map.js b/static/js/map.js index 197b920..966d6c3 100644 --- a/static/js/map.js +++ b/static/js/map.js @@ -13,7 +13,7 @@ var BusMap = { BusMap.Map = function(opts) { var stops = {}; var routes = {}; - var modal_cache = {}; + var modalCache = {}; var that = this.Map; that.opts = opts; window._busmap = this.Map; @@ -292,10 +292,14 @@ BusMap.Map = function(opts) { title: stops[s].title, icon: markerIcon, opacity: 1, + stopId: s }; that.stopMarkers[s] = L.marker( [stops[s].lat, stops[s].lon], - markerOpts).bindPopup(text, popupOpts); + markerOpts).bindPopup(text, popupOpts) + .on('click', function(e) { + that.selectedStop = this.options.stopId; + }); that.stopMarkersClusterGroup.addLayer(that.stopMarkers[s]); } // Add predictions to the marker popup, if available @@ -399,12 +403,12 @@ BusMap.Map = function(opts) { query: "modal", modal_name: name, }; - if (modal_cache[name]) { - modal.append(modal_cache[name]); + if (modalCache[name]) { + modal.append(modalCache[name]); setUrlFromView(); } else { $.get("ajax", params).done(function(contents) { - modal_cache[name] = contents; + modalCache[name] = contents; modal.append(contents); setUrlFromView(); }).fail(function() { -- GitLab