From 0d3448d494b4c6191f20282c679ecefa27bb3c50 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Fri, 13 Mar 2015 22:08:50 +0100 Subject: [PATCH 1/9] Always fire DOM event on the map too --- debug/tests/mousemove_on_polygons.html | 48 ++++++++++++++++ spec/suites/map/MapSpec.js | 76 ++++++++++++++++++++++++++ src/dom/DomEvent.js | 4 +- src/map/Map.js | 10 +++- 4 files changed, 135 insertions(+), 3 deletions(-) create mode 100644 debug/tests/mousemove_on_polygons.html diff --git a/debug/tests/mousemove_on_polygons.html b/debug/tests/mousemove_on_polygons.html new file mode 100644 index 00000000..ea374dae --- /dev/null +++ b/debug/tests/mousemove_on_polygons.html @@ -0,0 +1,48 @@ + + + + Leaflet debug page + + + + + + + + + + + + +
+ + + + diff --git a/spec/suites/map/MapSpec.js b/spec/suites/map/MapSpec.js index eeb033fe..e1d7ac5b 100644 --- a/spec/suites/map/MapSpec.js +++ b/spec/suites/map/MapSpec.js @@ -619,4 +619,80 @@ describe("Map", function () { }); + describe('#DOM events', function () { + + var c, map; + + beforeEach(function () { + c = document.createElement('div'); + c.style.width = '400px'; + c.style.height = '400px'; + map = new L.Map(c); + map.setView(new L.LatLng(0, 0), 0); + document.body.appendChild(c); + }); + + afterEach(function () { + document.body.removeChild(c); + }); + + it("DOM events propagate from polygon to map", function () { + var spy = sinon.spy(); + map.on("mousemove", spy); + var layer = new L.Polygon([[1, 2], [3, 4], [5, 6]]).addTo(map); + happen.mousemove(layer._path); + expect(spy.calledOnce).to.be.ok(); + }); + + it("DOM events propagate from marker to map", function () { + var spy = sinon.spy(); + map.on("mousemove", spy); + var layer = new L.Marker([1, 2]).addTo(map); + happen.mousemove(layer._icon); + expect(spy.calledOnce).to.be.ok(); + }); + + it("DOM events fired on marker can be cancelled before being caught by the map", function () { + var mapSpy = sinon.spy(); + var layerSpy = sinon.spy(); + map.on("mousemove", mapSpy); + var layer = new L.Marker([1, 2]).addTo(map); + layer.on("mousemove", L.DomEvent.stopPropagation).on("mousemove", layerSpy); + happen.mousemove(layer._icon); + expect(layerSpy.calledOnce).to.be.ok(); + expect(mapSpy.called).not.to.be.ok(); + }); + + it("mouseout is only forwared if fired on the original target", function () { + var mapSpy = sinon.spy(), + layerSpy = sinon.spy(), + otherSpy = sinon.spy(); + var layer = new L.Polygon([[1, 2], [3, 4], [5, 6]]).addTo(map); + var other = new L.Polygon([[10, 20], [30, 40], [50, 60]]).addTo(map); + map.on("mouseout", mapSpy); + layer.on("mouseout", layerSpy); + other.on("mouseout", otherSpy); + happen.mouseout(layer._path); + expect(mapSpy.called).not.to.be.ok(); + expect(otherSpy.called).not.to.be.ok(); + expect(layerSpy.calledOnce).to.be.ok(); + }); + + it("mouseout is not forwared to layers if fired on the map", function () { + var mapSpy = sinon.spy(), + layerSpy = sinon.spy(), + otherSpy = sinon.spy(); + var layer = new L.Polygon([[1, 2], [3, 4], [5, 6]]).addTo(map); + var other = new L.Polygon([[10, 20], [30, 40], [50, 60]]).addTo(map); + map.on("mouseout", mapSpy); + layer.on("mouseout", layerSpy); + other.on("mouseout", otherSpy); + happen.mouseout(map._container); + expect(otherSpy.called).not.to.be.ok(); + expect(layerSpy.called).not.to.be.ok(); + expect(mapSpy.calledOnce).to.be.ok(); + }); + + }); + }); diff --git a/src/dom/DomEvent.js b/src/dom/DomEvent.js index 9d67761f..0e0d049a 100644 --- a/src/dom/DomEvent.js +++ b/src/dom/DomEvent.js @@ -128,12 +128,14 @@ L.DomEvent = { stopPropagation: function (e) { + L.DomEvent._skipped(e); if (e.stopPropagation) { e.stopPropagation(); } else { e.cancelBubble = true; + // In case of Leaflet event. + L.DomEvent._fakeStop(e); } - L.DomEvent._skipped(e); return this; }, diff --git a/src/map/Map.js b/src/map/Map.js index 21274dc8..1e439b68 100644 --- a/src/map/Map.js +++ b/src/map/Map.js @@ -646,14 +646,20 @@ L.Map = L.Evented.extend({ // special case for map mouseover/mouseout events so that they're actually mouseenter/mouseleave if (!target && (type === 'mouseover' || type === 'mouseout') && - !L.DomEvent._checkMouse(this._container, e)) { return; } + !L.DomEvent._checkMouse(this._container, e)) { return; } // prevents outline when clicking on keyboard-focusable element if (type === 'mousedown') { L.DomUtil.preventOutline(e.target || e.srcElement); } - this._fireDOMEvent(target || this, e, type); + if (target && target !== this) { + this._fireDOMEvent(target, e, type); + if (type === 'mouseover' || type === 'mouseout') { return; } + } + if (!L.DomEvent._skipped(e)) { // In case the Leaflet event has been stopped on some target listener. + this._fireDOMEvent(this, e, type); + } }, _fireDOMEvent: function (target, e, type) { From d1864cd13878fd832a8b9801f56535110702e19c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20S=C3=A1nchez=20Ortega?= Date: Wed, 27 May 2015 11:27:37 +0200 Subject: [PATCH 2/9] Move 'preclick' event handling around so it propagates before 'click'. --- src/map/Map.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/map/Map.js b/src/map/Map.js index 1e439b68..9318e7f7 100644 --- a/src/map/Map.js +++ b/src/map/Map.js @@ -644,12 +644,19 @@ L.Map = L.Evented.extend({ var target = this._findEventTarget(e.target || e.srcElement), type = e.type === 'keypress' && e.keyCode === 13 ? 'click' : e.type; + if (e.type === 'click') { + // Fire a synthetic 'preclick' event which propagates up (mainly for closing popups). + var synth = L.Util.extend({}, e); + synth.type = 'preclick'; + this._handleDOMEvent(synth); + } + // special case for map mouseover/mouseout events so that they're actually mouseenter/mouseleave if (!target && (type === 'mouseover' || type === 'mouseout') && !L.DomEvent._checkMouse(this._container, e)) { return; } - // prevents outline when clicking on keyboard-focusable element if (type === 'mousedown') { + // prevents outline when clicking on keyboard-focusable element L.DomUtil.preventOutline(e.target || e.srcElement); } @@ -663,7 +670,7 @@ L.Map = L.Evented.extend({ }, _fireDOMEvent: function (target, e, type) { - if (!target.listens(type, true) && (type !== 'click' || !target.listens('preclick', true))) { return; } + if (!target.listens(type, true)) { return; } if (type === 'contextmenu') { L.DomEvent.preventDefault(e); @@ -681,9 +688,6 @@ L.Map = L.Evented.extend({ data.layerPoint = this.containerPointToLayerPoint(data.containerPoint); data.latlng = this.layerPointToLatLng(data.layerPoint); } - if (type === 'click') { - target.fire('preclick', data, true); - } target.fire(type, data, true); }, From d67cbb24c13261b3d2570a9348d9be31e6a84e5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20S=C3=A1nchez=20Ortega?= Date: Thu, 28 May 2015 13:16:56 +0200 Subject: [PATCH 3/9] More complete test webpage for #3307 --- debug/tests/mousemove_on_polygons.html | 123 ++++++++++++++++++------- 1 file changed, 91 insertions(+), 32 deletions(-) diff --git a/debug/tests/mousemove_on_polygons.html b/debug/tests/mousemove_on_polygons.html index ea374dae..96c08acb 100644 --- a/debug/tests/mousemove_on_polygons.html +++ b/debug/tests/mousemove_on_polygons.html @@ -1,48 +1,107 @@ - Leaflet debug page + Leaflet debug page - + - + - - - - + + + + + + + + + +
Enter Move Exit Click
Triangle 1:
Triangle 2:
Map:
-
+
- + + var marker = new L.Marker(latlng, {draggable: true}) + .bindPopup('Marker');; + map.addLayer(marker); + + +// map.on('mousemove', function (e) { +// marker.setLatLng(e.latlng); +// }); + map.on('mouseover',update('enter3')) + .on('mousemove',update('move3')) + .on('mouseout',update('exit3')) + .on('click',update('click3')); + + // We should be able to move marker around in a fluid way, + // plus going over the polygon with no issue. + + From 54c89258184fd9341c5a0b1de4785572359acf7f Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Mon, 1 Jun 2015 22:32:50 +0200 Subject: [PATCH 4/9] Add map as layer event parent --- src/core/Events.js | 1 + src/dom/DomEvent.js | 5 ++--- src/layer/Layer.js | 5 +++++ src/map/Map.js | 15 +++++---------- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/core/Events.js b/src/core/Events.js index 6702d2ae..9452124e 100644 --- a/src/core/Events.js +++ b/src/core/Events.js @@ -211,6 +211,7 @@ L.Evented = L.Class.extend({ _propagateEvent: function (e) { for (var id in this._eventParents) { + if (e._stopped) { break; } this._eventParents[id].fire(e.type, L.extend({layer: e.target}, e), true); } } diff --git a/src/dom/DomEvent.js b/src/dom/DomEvent.js index 0e0d049a..4f078437 100644 --- a/src/dom/DomEvent.js +++ b/src/dom/DomEvent.js @@ -128,14 +128,13 @@ L.DomEvent = { stopPropagation: function (e) { - L.DomEvent._skipped(e); if (e.stopPropagation) { e.stopPropagation(); } else { e.cancelBubble = true; - // In case of Leaflet event. - L.DomEvent._fakeStop(e); + e._stopped = true; // In case of Leaflet event. } + L.DomEvent._skipped(e); return this; }, diff --git a/src/layer/Layer.js b/src/layer/Layer.js index b34dcc96..352f6c40 100644 --- a/src/layer/Layer.js +++ b/src/layer/Layer.js @@ -67,6 +67,9 @@ L.Layer = L.Evented.extend({ L.Map.include({ addLayer: function (layer) { var id = L.stamp(layer); + + layer.addEventParent(this); + if (this._layers[id]) { return layer; } this._layers[id] = layer; @@ -84,6 +87,8 @@ L.Map.include({ removeLayer: function (layer) { var id = L.stamp(layer); + layer.removeEventParent(this); + if (!this._layers[id]) { return this; } if (this._loaded) { diff --git a/src/map/Map.js b/src/map/Map.js index 9318e7f7..9b9373a2 100644 --- a/src/map/Map.js +++ b/src/map/Map.js @@ -660,13 +660,7 @@ L.Map = L.Evented.extend({ L.DomUtil.preventOutline(e.target || e.srcElement); } - if (target && target !== this) { - this._fireDOMEvent(target, e, type); - if (type === 'mouseover' || type === 'mouseout') { return; } - } - if (!L.DomEvent._skipped(e)) { // In case the Leaflet event has been stopped on some target listener. - this._fireDOMEvent(this, e, type); - } + this._fireDOMEvent(target || this, e, type); }, _fireDOMEvent: function (target, e, type) { @@ -680,15 +674,16 @@ L.Map = L.Evented.extend({ if (e.type === 'click' && !e._simulated && this._draggableMoved(target)) { return; } var data = { - originalEvent: e - }; + originalEvent: e + }, + propagate = (type !== 'mouseover' && type !== 'mouseout'); if (e.type !== 'keypress') { data.containerPoint = target instanceof L.Marker ? this.latLngToContainerPoint(target.getLatLng()) : this.mouseEventToContainerPoint(e); data.layerPoint = this.containerPointToLayerPoint(data.containerPoint); data.latlng = this.layerPointToLatLng(data.layerPoint); } - target.fire(type, data, true); + target.fire(type, data, propagate); }, _draggableMoved: function (obj) { From 68195aa2bd159180199c21d300fcf070de1a05ce Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Fri, 19 Jun 2015 09:33:57 +0200 Subject: [PATCH 5/9] More natural event bubbling --- src/core/Events.js | 1 - src/dom/DomEvent.js | 3 ++- src/layer/Layer.js | 5 ----- src/map/Map.js | 45 ++++++++++++++++++++++++++++----------------- 4 files changed, 30 insertions(+), 24 deletions(-) diff --git a/src/core/Events.js b/src/core/Events.js index 9452124e..6702d2ae 100644 --- a/src/core/Events.js +++ b/src/core/Events.js @@ -211,7 +211,6 @@ L.Evented = L.Class.extend({ _propagateEvent: function (e) { for (var id in this._eventParents) { - if (e._stopped) { break; } this._eventParents[id].fire(e.type, L.extend({layer: e.target}, e), true); } } diff --git a/src/dom/DomEvent.js b/src/dom/DomEvent.js index 4f078437..2a87a5e6 100644 --- a/src/dom/DomEvent.js +++ b/src/dom/DomEvent.js @@ -130,9 +130,10 @@ L.DomEvent = { if (e.stopPropagation) { e.stopPropagation(); + } else if (e.originalEvent) { // In case of Leaflet event. + e.originalEvent._stopped = true; } else { e.cancelBubble = true; - e._stopped = true; // In case of Leaflet event. } L.DomEvent._skipped(e); diff --git a/src/layer/Layer.js b/src/layer/Layer.js index 352f6c40..b34dcc96 100644 --- a/src/layer/Layer.js +++ b/src/layer/Layer.js @@ -67,9 +67,6 @@ L.Layer = L.Evented.extend({ L.Map.include({ addLayer: function (layer) { var id = L.stamp(layer); - - layer.addEventParent(this); - if (this._layers[id]) { return layer; } this._layers[id] = layer; @@ -87,8 +84,6 @@ L.Map.include({ removeLayer: function (layer) { var id = L.stamp(layer); - layer.removeEventParent(this); - if (!this._layers[id]) { return this; } if (this._loaded) { diff --git a/src/map/Map.js b/src/map/Map.js index 9b9373a2..37b958d8 100644 --- a/src/map/Map.js +++ b/src/map/Map.js @@ -601,6 +601,7 @@ L.Map = L.Evented.extend({ if (!L.DomEvent) { return; } this._targets = {}; + this._targets[L.stamp(this._container)] = this; var onOff = remove ? 'off' : 'on'; @@ -623,26 +624,27 @@ L.Map = L.Evented.extend({ this._container.scrollLeft = 0; }, - _findEventTarget: function (src) { + _findEventTargets: function (src, bubble) { + var targets = [], target; while (src) { - var target = this._targets[L.stamp(src)]; + target = this._targets[L.stamp(src)]; if (target) { - return target; + targets.push(target); + if (!bubble) { break; } } if (src === this._container) { break; } src = src.parentNode; } - return null; + return targets; }, _handleDOMEvent: function (e) { if (!this._loaded || L.DomEvent._skipped(e)) { return; } - // find the layer the event is propagating from - var target = this._findEventTarget(e.target || e.srcElement), - type = e.type === 'keypress' && e.keyCode === 13 ? 'click' : e.type; + // find the layer the event is propagating from and its parents + var type = e.type === 'keypress' && e.keyCode === 13 ? 'click' : e.type; if (e.type === 'click') { // Fire a synthetic 'preclick' event which propagates up (mainly for closing popups). @@ -651,39 +653,48 @@ L.Map = L.Evented.extend({ this._handleDOMEvent(synth); } - // special case for map mouseover/mouseout events so that they're actually mouseenter/mouseleave - if (!target && (type === 'mouseover' || type === 'mouseout') && - !L.DomEvent._checkMouse(this._container, e)) { return; } - if (type === 'mousedown') { // prevents outline when clicking on keyboard-focusable element L.DomUtil.preventOutline(e.target || e.srcElement); } - this._fireDOMEvent(target || this, e, type); + this._fireDOMEvent(e, type); }, - _fireDOMEvent: function (target, e, type) { - if (!target.listens(type, true)) { return; } + _fireDOMEvent: function (e, type) { if (type === 'contextmenu') { L.DomEvent.preventDefault(e); } + var targets = this._findEventTargets(e.target || e.srcElement, !(e.type === 'mouseover' || e.type === 'mouseout')); + + if (!targets.length) { + targets = [this]; + + // special case for map mouseover/mouseout events so that they're actually mouseenter/mouseleave + if ((type === 'mouseover' || type === 'mouseout') && + !L.DomEvent._checkMouse(this._container, e)) { return; } + } + + var target = targets[0]; // prevents firing click after you just dragged an object if (e.type === 'click' && !e._simulated && this._draggableMoved(target)) { return; } var data = { originalEvent: e - }, - propagate = (type !== 'mouseover' && type !== 'mouseout'); + }; if (e.type !== 'keypress') { data.containerPoint = target instanceof L.Marker ? this.latLngToContainerPoint(target.getLatLng()) : this.mouseEventToContainerPoint(e); data.layerPoint = this.containerPointToLayerPoint(data.containerPoint); data.latlng = this.layerPointToLatLng(data.layerPoint); } - target.fire(type, data, propagate); + for (var i = 0; i < targets.length; i++) { + if (data.originalEvent._stopped) { break; } + if (!targets[i].listens(type, true)) { continue; } + targets[i].fire(type, data); + } }, _draggableMoved: function (obj) { From f4cc307e70a8a2b9c5f2d069107aeb47fce90f0a Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Wed, 24 Jun 2015 08:31:59 +0200 Subject: [PATCH 6/9] Add preclick related unitest --- spec/suites/map/MapSpec.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/spec/suites/map/MapSpec.js b/spec/suites/map/MapSpec.js index e1d7ac5b..4ea8d98d 100644 --- a/spec/suites/map/MapSpec.js +++ b/spec/suites/map/MapSpec.js @@ -693,6 +693,28 @@ describe("Map", function () { expect(mapSpy.calledOnce).to.be.ok(); }); + it("preclick is fired before click on marker and map", function () { + var called = 0; + var layer = new L.Marker([1, 2]).addTo(map); + layer.on("preclick", function (e) { + expect(called++).to.eql(0); + expect(e.latlng).to.ok(); + }); + layer.on("click", function (e) { + expect(called++).to.eql(2); + expect(e.latlng).to.ok(); + }); + map.on("preclick", function (e) { + expect(called++).to.eql(1); + expect(e.latlng).to.ok(); + }); + map.on("click", function (e) { + expect(called++).to.eql(3); + expect(e.latlng).to.ok(); + }); + happen.click(layer._icon); + }); + }); }); From 50d7121f72b97a9c34fe96e369509f19f40ae135 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Sat, 4 Jul 2015 17:25:26 +0200 Subject: [PATCH 7/9] Make _fireDOMEvent accept optional targets In the case of canvas path, we can't add the canvas element itself as an interactiveTarget, given that it's big like the path bbox, and thus would make all this bbox target of events (so also clicking outside of the path itself, the layer would fire click event, for example) --- debug/vector/vector-canvas.html | 9 ++++++--- spec/suites/map/MapSpec.js | 30 ++++++++++++++++++++++++++++++ src/layer/vector/Canvas.js | 2 +- src/map/Map.js | 4 ++-- 4 files changed, 39 insertions(+), 6 deletions(-) diff --git a/debug/vector/vector-canvas.html b/debug/vector/vector-canvas.html index 7216a646..430ed130 100644 --- a/debug/vector/vector-canvas.html +++ b/debug/vector/vector-canvas.html @@ -29,7 +29,8 @@ for (var i = 0, latlngs = [], len = route.length; i < len; i++) { latlngs.push(new L.LatLng(route[i][0], route[i][1])); } - var path = new L.Polyline(latlngs); + var canvas = L.canvas(); + var path = new L.Polyline(latlngs, {renderer: canvas}); var map = new L.Map('map', {layers: [osm]}); @@ -41,7 +42,8 @@ circleOptions = { color: 'red', fillColor: 'yellow', - fillOpacity: 0.7 + fillOpacity: 0.7, + renderer: canvas }; var circle = new L.Circle(circleLocation, 500000, circleOptions), @@ -79,7 +81,8 @@ var polygon = new L.Polygon([polygonPoints, holePoints], { fillColor: "#333", - color: 'green' + color: 'green', + renderer: canvas }); group.addLayer(polygon); diff --git a/spec/suites/map/MapSpec.js b/spec/suites/map/MapSpec.js index 4ea8d98d..43f692c7 100644 --- a/spec/suites/map/MapSpec.js +++ b/spec/suites/map/MapSpec.js @@ -644,6 +644,14 @@ describe("Map", function () { expect(spy.calledOnce).to.be.ok(); }); + it("DOM events propagate from canvas polygon to map", function () { + var spy = sinon.spy(); + map.on("mousemove", spy); + var layer = new L.Polygon([[1, 2], [3, 4], [5, 6]], {rendered: L.canvas()}).addTo(map); + happen.mousemove(layer._path); + expect(spy.calledOnce).to.be.ok(); + }); + it("DOM events propagate from marker to map", function () { var spy = sinon.spy(); map.on("mousemove", spy); @@ -663,6 +671,28 @@ describe("Map", function () { expect(mapSpy.called).not.to.be.ok(); }); + it("DOM events fired on polygon can be cancelled before being caught by the map", function () { + var mapSpy = sinon.spy(); + var layerSpy = sinon.spy(); + map.on("mousemove", mapSpy); + var layer = new L.Polygon([[1, 2], [3, 4], [5, 6]]).addTo(map); + layer.on("mousemove", L.DomEvent.stopPropagation).on("mousemove", layerSpy); + happen.mousemove(layer._path); + expect(layerSpy.calledOnce).to.be.ok(); + expect(mapSpy.called).not.to.be.ok(); + }); + + it("DOM events fired on canvas polygon can be cancelled before being caught by the map", function () { + var mapSpy = sinon.spy(); + var layerSpy = sinon.spy(); + map.on("mousemove", mapSpy); + var layer = new L.Polygon([[1, 2], [3, 4], [5, 6]], {rendered: L.canvas()}).addTo(map); + layer.on("mousemove", L.DomEvent.stopPropagation).on("mousemove", layerSpy); + happen.mousemove(layer._path); + expect(layerSpy.calledOnce).to.be.ok(); + expect(mapSpy.called).not.to.be.ok(); + }); + it("mouseout is only forwared if fired on the original target", function () { var mapSpy = sinon.spy(), layerSpy = sinon.spy(), diff --git a/src/layer/vector/Canvas.js b/src/layer/vector/Canvas.js index 67ea31b4..ec2c0042 100644 --- a/src/layer/vector/Canvas.js +++ b/src/layer/vector/Canvas.js @@ -233,7 +233,7 @@ L.Canvas = L.Renderer.extend({ }, _fireEvent: function (layer, e, type) { - this._map._fireDOMEvent(layer, e, type || e.type); + this._map._fireDOMEvent(e, type || e.type, [layer]); }, // TODO _bringToFront & _bringToBack, pretty tricky diff --git a/src/map/Map.js b/src/map/Map.js index 37b958d8..7df04481 100644 --- a/src/map/Map.js +++ b/src/map/Map.js @@ -661,12 +661,12 @@ L.Map = L.Evented.extend({ this._fireDOMEvent(e, type); }, - _fireDOMEvent: function (e, type) { + _fireDOMEvent: function (e, type, targets) { if (type === 'contextmenu') { L.DomEvent.preventDefault(e); } - var targets = this._findEventTargets(e.target || e.srcElement, !(e.type === 'mouseover' || e.type === 'mouseout')); + targets = (targets || []).concat(this._findEventTargets(e.target || e.srcElement, !(e.type === 'mouseover' || e.type === 'mouseout'))); if (!targets.length) { targets = [this]; From d86c6002d7914a3d48c70e1392bba0d2d2189c3c Mon Sep 17 00:00:00 2001 From: Vladimir Agafonkin Date: Fri, 3 Jul 2015 18:10:53 +0300 Subject: [PATCH 8/9] minor cleanup --- src/map/Map.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/map/Map.js b/src/map/Map.js index 7df04481..d04784d3 100644 --- a/src/map/Map.js +++ b/src/map/Map.js @@ -666,14 +666,15 @@ L.Map = L.Evented.extend({ if (type === 'contextmenu') { L.DomEvent.preventDefault(e); } - targets = (targets || []).concat(this._findEventTargets(e.target || e.srcElement, !(e.type === 'mouseover' || e.type === 'mouseout'))); + + var isHover = type === 'mouseover' || type === 'mouseout'; + targets = (targets || []).concat(this._findEventTargets(e.target || e.srcElement, !isHover)); if (!targets.length) { targets = [this]; // special case for map mouseover/mouseout events so that they're actually mouseenter/mouseleave - if ((type === 'mouseover' || type === 'mouseout') && - !L.DomEvent._checkMouse(this._container, e)) { return; } + if (isHover && !L.DomEvent._checkMouse(this._container, e)) { return; } } var target = targets[0]; @@ -682,18 +683,21 @@ L.Map = L.Evented.extend({ if (e.type === 'click' && !e._simulated && this._draggableMoved(target)) { return; } var data = { - originalEvent: e - }; + originalEvent: e + }; + if (e.type !== 'keypress') { data.containerPoint = target instanceof L.Marker ? this.latLngToContainerPoint(target.getLatLng()) : this.mouseEventToContainerPoint(e); data.layerPoint = this.containerPointToLayerPoint(data.containerPoint); data.latlng = this.layerPointToLatLng(data.layerPoint); } + for (var i = 0; i < targets.length; i++) { - if (data.originalEvent._stopped) { break; } - if (!targets[i].listens(type, true)) { continue; } - targets[i].fire(type, data); + if (targets[i].listens(type, true)) { + targets[i].fire(type, data); + if (data.originalEvent._stopped) { return; } + } } }, From fd1b94550c64806b868c439d8b1a0d87f70d6413 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Mon, 6 Jul 2015 11:13:09 +0200 Subject: [PATCH 9/9] Fix popup broken since 9b7f24f5f6efb94be2a96d7d7f4c604783135d10 Popup where binded by the LayerGroup, which was not finring the click event, because not propagated from the layers --- src/map/Map.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/map/Map.js b/src/map/Map.js index d04784d3..663e963b 100644 --- a/src/map/Map.js +++ b/src/map/Map.js @@ -695,7 +695,7 @@ L.Map = L.Evented.extend({ for (var i = 0; i < targets.length; i++) { if (targets[i].listens(type, true)) { - targets[i].fire(type, data); + targets[i].fire(type, data, true); if (data.originalEvent._stopped) { return; } } }