Skip to content
Snippets Groups Projects
Commit 23352fc2 authored by Anton Sarukhanov's avatar Anton Sarukhanov
Browse files

If a stop has been clicked on the map, default to that stop in the Embed dialog.

parent 0b9f9edb
No related branches found
No related tags found
1 merge request!1Implemented Embed-code generator interface
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
}
}
......
......@@ -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() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment