Add nonBubblingEvents option (fix #3604)
This commit is contained in:
parent
d2513b2d53
commit
74018f284e
@ -207,5 +207,35 @@ describe("Marker", function () {
|
|||||||
expect(spy.calledTwice).to.be.ok();
|
expect(spy.calledTwice).to.be.ok();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("do not propagate click event", function () {
|
||||||
|
var spy = sinon.spy();
|
||||||
|
var spy2 = sinon.spy();
|
||||||
|
var mapSpy = sinon.spy();
|
||||||
|
var marker = new L.Marker(new L.LatLng(55.8, 37.6));
|
||||||
|
map.addLayer(marker);
|
||||||
|
marker.on('click', spy);
|
||||||
|
marker.on('click', spy2);
|
||||||
|
map.on('click', mapSpy);
|
||||||
|
happen.click(marker._icon);
|
||||||
|
expect(spy.called).to.be.ok();
|
||||||
|
expect(spy2.called).to.be.ok();
|
||||||
|
expect(mapSpy.called).not.to.be.ok();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("do not propagate dblclick event", function () {
|
||||||
|
var spy = sinon.spy();
|
||||||
|
var spy2 = sinon.spy();
|
||||||
|
var mapSpy = sinon.spy();
|
||||||
|
var marker = new L.Marker(new L.LatLng(55.8, 37.6));
|
||||||
|
map.addLayer(marker);
|
||||||
|
marker.on('dblclick', spy);
|
||||||
|
marker.on('dblclick', spy2);
|
||||||
|
map.on('dblclick', mapSpy);
|
||||||
|
happen.dblclick(marker._icon);
|
||||||
|
expect(spy.called).to.be.ok();
|
||||||
|
expect(spy2.called).to.be.ok();
|
||||||
|
expect(mapSpy.called).not.to.be.ok();
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -147,6 +147,13 @@ L.Util = {
|
|||||||
return (Object.prototype.toString.call(obj) === '[object Array]');
|
return (Object.prototype.toString.call(obj) === '[object Array]');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
indexOf: function (array, el) {
|
||||||
|
for (var i = 0; i < array.length; i++) {
|
||||||
|
if (array[i] === el) { return i; }
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
},
|
||||||
|
|
||||||
// minimal image URI, set to an image when disposing to flush memory
|
// minimal image URI, set to an image when disposing to flush memory
|
||||||
emptyImageUrl: 'data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs='
|
emptyImageUrl: 'data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs='
|
||||||
};
|
};
|
||||||
|
@ -2,7 +2,8 @@
|
|||||||
L.Layer = L.Evented.extend({
|
L.Layer = L.Evented.extend({
|
||||||
|
|
||||||
options: {
|
options: {
|
||||||
pane: 'overlayPane'
|
pane: 'overlayPane',
|
||||||
|
nonBubblingEvents: [] // Array of events that should not be bubbled to DOM parents (like the map)
|
||||||
},
|
},
|
||||||
|
|
||||||
addTo: function (map) {
|
addTo: function (map) {
|
||||||
|
@ -6,6 +6,7 @@ L.Marker = L.Layer.extend({
|
|||||||
|
|
||||||
options: {
|
options: {
|
||||||
pane: 'markerPane',
|
pane: 'markerPane',
|
||||||
|
nonBubblingEvents: ['click', 'dblclick', 'mouseover', 'mouseout', 'contextmenu'],
|
||||||
|
|
||||||
icon: new L.Icon.Default(),
|
icon: new L.Icon.Default(),
|
||||||
// title: '',
|
// title: '',
|
||||||
|
@ -696,7 +696,8 @@ L.Map = L.Evented.extend({
|
|||||||
for (var i = 0; i < targets.length; i++) {
|
for (var i = 0; i < targets.length; i++) {
|
||||||
if (targets[i].listens(type, true)) {
|
if (targets[i].listens(type, true)) {
|
||||||
targets[i].fire(type, data, true);
|
targets[i].fire(type, data, true);
|
||||||
if (data.originalEvent._stopped) { return; }
|
if (data.originalEvent._stopped
|
||||||
|
|| (targets[i].options.nonBubblingEvents && L.Util.indexOf(targets[i].options.nonBubblingEvents, type) !== -1)) { return; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user