diff --git a/static/js/map.js b/static/js/map.js index 39d8f37e0cc4b5f7daaaee28b132c6ba579462e8..b780ebb1bbef64f6a591f1e822bba356c2f0aa4c 100644 --- a/static/js/map.js +++ b/static/js/map.js @@ -51,6 +51,8 @@ BusMap.Map = function(opts) { that.leaflet.on('moveend', setUrlFromView); } + // Hide any opened modals when map is clicked. + $(that.map).on('click', hideModal); // Show/hide markers based on zoom. that.leaflet.on('zoomend', zoomShowHide); @@ -388,14 +390,7 @@ BusMap.Map = function(opts) { $('div.modal').remove(); var modal = $('<div class="modal" id="modal-'+name+'"></div>'); var closeBtn = $('<div class="close">×</div>').appendTo(modal); - closeBtn.click(function() { - $(this).parent().remove(); - setUrlFromView(); - }); - $(that.map).click(function() { - modal.remove(); - setUrlFromView; - }); + closeBtn.on('click', hideModal); $(that.opts.mapElement).after(modal); modal.show(); var params = { @@ -417,6 +412,13 @@ BusMap.Map = function(opts) { } } + // Hide modal popup if open + function hideModal() { + if ($('div.modal').length == 0) return; + $('div.modal').remove(); + setUrlFromView(); + } + // Scaling: update what is displayed based on zoom level function zoomShowHide() { var zoom = that.leaflet.getZoom();