From 8a12624f604da5049f0ab463de1254b8fcfa1b8c Mon Sep 17 00:00:00 2001 From: Patrick Arlt Date: Mon, 13 Oct 2014 09:06:16 -0700 Subject: [PATCH 1/2] always expose window.L --- src/Leaflet.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Leaflet.js b/src/Leaflet.js index 507c781d..bb1558fb 100644 --- a/src/Leaflet.js +++ b/src/Leaflet.js @@ -23,6 +23,6 @@ if (typeof module === 'object' && typeof module.exports === 'object') { define(L); // define Leaflet as a global L variable, saving the original L to restore later if needed -} else { - expose(); } + +expose(); \ No newline at end of file From f3c802c97cf7c0ea3e89e7bb9d8886d267f3b1fc Mon Sep 17 00:00:00 2001 From: Patrick Arlt Date: Sat, 28 Mar 2015 19:20:56 -0700 Subject: [PATCH 2/2] add test for new popup functionality --- spec/suites/layer/PopupSpec.js | 80 ++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/spec/suites/layer/PopupSpec.js b/spec/suites/layer/PopupSpec.js index 9c970939..9dfc72f5 100644 --- a/spec/suites/layer/PopupSpec.js +++ b/spec/suites/layer/PopupSpec.js @@ -66,6 +66,86 @@ describe('Popup', function () { expect(map.hasLayer(marker._popup)).to.be(false); }); + it("it should use a popup with a fuction as content with a FeatureGroup", function () { + var marker1 = new L.Marker(new L.LatLng(55.8, 37.6)); + var marker2 = new L.Marker(new L.LatLng(54.6, 38.2)); + var group = new L.FeatureGroup([marker1, marker2]).addTo(map); + + marker1.description = "I'm marker 1."; + marker2.description = "I'm marker 2."; + group.bindPopup(function(layer) { + return layer.description; + }); + + map.options.closePopupOnClick = true; + + // toggle popup on marker1 + group.fire('click', { + latlng: new L.LatLng(55.8, 37.6), + layer: marker1 + }); + expect(map.hasLayer(group._popup)).to.be(true); + expect(group._popup._contentNode.innerHTML).to.be("I'm marker 1."); + + // toggle popup on marker2 + group.fire('click', { + latlng: new L.LatLng(54.6, 38.2), + layer: marker2 + }); + expect(map.hasLayer(group._popup)).to.be(true); + expect(group._popup._contentNode.innerHTML).to.be("I'm marker 2."); + }); + + it("it should function for popup content after bindPopup is called", function () { + var marker1 = new L.Marker(new L.LatLng(55.8, 37.6)); + var marker2 = new L.Marker(new L.LatLng(54.6, 38.2)); + var group = new L.FeatureGroup([marker1]).addTo(map); + + marker1.description = "I'm marker 1."; + marker2.description = "I'm marker 2."; + group.bindPopup(function(layer) { + return layer.description; + }); + + group.addLayer(marker2); + + map.options.closePopupOnClick = true; + + // toggle popup on marker1 + group.fire('click', { + latlng: new L.LatLng(55.8, 37.6), + layer: marker1 + }); + expect(map.hasLayer(group._popup)).to.be(true); + expect(group._popup._contentNode.innerHTML).to.be("I'm marker 1."); + + // toggle popup on marker2 + group.fire('click', { + latlng: new L.LatLng(54.6, 38.2), + layer: marker2 + }); + expect(map.hasLayer(group._popup)).to.be(true); + expect(group._popup._contentNode.innerHTML).to.be("I'm marker 2."); + }); + + it("should use a function for popup content when a source is passed to Popup", function() { + var marker = new L.Marker(new L.LatLng(55.8, 37.6)).addTo(map); + var popup = L.popup({}, marker); + + marker.description = "I am a marker."; + + marker.bindPopup(function(layer) { + return layer.description; + }); + + marker.fire('click', { + latlng: new L.LatLng(55.8, 37.6) + }); + + expect(map.hasLayer(marker._popup)).to.be(true); + expect(marker._popup._contentNode.innerHTML).to.be("I am a marker."); + }); + it("triggers popupopen on marker when popup opens", function () { var marker1 = new L.Marker(new L.LatLng(55.8, 37.6)); var marker2 = new L.Marker(new L.LatLng(57.123076977278, 44.861962891635));