From ade9c943ffc66ad5edc73ac19561268aefad257e Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 10 May 2013 15:22:03 -0700 Subject: [PATCH] Popup-specific closeOnClick option --- spec/suites/layer/PopupSpec.js | 40 ++++++++++++++++++++++++++++++++-- src/layer/Popup.js | 2 +- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/spec/suites/layer/PopupSpec.js b/spec/suites/layer/PopupSpec.js index 6708fa3b..0fb52260 100644 --- a/spec/suites/layer/PopupSpec.js +++ b/spec/suites/layer/PopupSpec.js @@ -1,15 +1,51 @@ describe('Popup', function() { - var map; + var c, map; beforeEach(function () { - var c = document.createElement('div'); + c = document.createElement('div'); c.style.width = '400px'; c.style.height = '400px'; map = new L.Map(c); map.setView(new L.LatLng(55.8, 37.6), 6); }); + it("closes on map click when map has closePopupOnClick option", function() { + map.options.closePopupOnClick = true; + + var popup = new L.Popup() + .setLatLng(new L.LatLng(55.8, 37.6)) + .openOn(map); + + happen.click(c); + + expect(map.hasLayer(popup)).to.be(false); + }); + + it("closes on map click when popup has closeOnClick option", function() { + map.options.closePopupOnClick = false; + + var popup = new L.Popup({closeOnClick: true}) + .setLatLng(new L.LatLng(55.8, 37.6)) + .openOn(map); + + happen.click(c); + + expect(map.hasLayer(popup)).to.be(false); + }); + + it("does not close on map click when popup has closeOnClick: false option", function() { + map.options.closePopupOnClick = true; + + var popup = new L.Popup({closeOnClick: false}) + .setLatLng(new L.LatLng(55.8, 37.6)) + .openOn(map); + + happen.click(c); + + expect(map.hasLayer(popup)).to.be(true); + }); + it("should trigger 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)); diff --git a/src/layer/Popup.js b/src/layer/Popup.js index 99314c25..8c190e93 100644 --- a/src/layer/Popup.js +++ b/src/layer/Popup.js @@ -113,7 +113,7 @@ L.Popup = L.Class.extend({ if (this._animated) { events.zoomanim = this._zoomAnimation; } - if (this._map.options.closePopupOnClick) { + if ('closeOnClick' in this.options ? this.options.closeOnClick : this._map.options.closePopupOnClick) { events.preclick = this._close; } if (this.options.keepInView) {