switch markers to event delegation API
This commit is contained in:
parent
22c97d1b33
commit
34bc7fa4ea
@ -123,11 +123,11 @@ L.Marker = L.Layer.extend({
|
||||
this._icon = icon;
|
||||
this._initInteraction();
|
||||
|
||||
if (L.DomEvent && options.riseOnHover) {
|
||||
L.DomEvent.on(icon, {
|
||||
if (options.riseOnHover) {
|
||||
this.on({
|
||||
mouseover: this._bringToFront,
|
||||
mouseout: this._resetZIndex
|
||||
}, this);
|
||||
});
|
||||
}
|
||||
|
||||
var newShadow = options.icon.createShadow(this._shadow),
|
||||
@ -158,14 +158,15 @@ L.Marker = L.Layer.extend({
|
||||
},
|
||||
|
||||
_removeIcon: function () {
|
||||
if (L.DomEvent && this.options.riseOnHover) {
|
||||
L.DomEvent.off(this._icon, {
|
||||
if (this.options.riseOnHover) {
|
||||
this.off({
|
||||
mouseover: this._bringToFront,
|
||||
mouseout: this._resetZIndex
|
||||
}, this);
|
||||
});
|
||||
}
|
||||
|
||||
L.DomUtil.remove(this._icon);
|
||||
this.removeInteractiveTarget(this._icon);
|
||||
|
||||
this._icon = null;
|
||||
},
|
||||
@ -205,11 +206,7 @@ L.Marker = L.Layer.extend({
|
||||
|
||||
L.DomUtil.addClass(this._icon, 'leaflet-interactive');
|
||||
|
||||
if (L.DomEvent) {
|
||||
L.DomEvent.on(this._icon,
|
||||
'click dblclick mousedown mouseup mouseover mousemove mouseout contextmenu keypress',
|
||||
this._fireMouseEvent, this);
|
||||
}
|
||||
this.addInteractiveTarget(this._icon);
|
||||
|
||||
if (L.Handler.MarkerDrag) {
|
||||
var draggable = this.options.draggable;
|
||||
@ -226,21 +223,6 @@ L.Marker = L.Layer.extend({
|
||||
}
|
||||
},
|
||||
|
||||
_fireMouseEvent: function (e, type) {
|
||||
// to prevent outline when clicking on keyboard-focusable marker
|
||||
if (e.type === 'mousedown') {
|
||||
L.DomEvent.preventDefault(e);
|
||||
}
|
||||
|
||||
if (e.type === 'keypress' && e.keyCode === 13) {
|
||||
type = 'click';
|
||||
}
|
||||
|
||||
if (this._map) {
|
||||
this._map._fireMouseEvent(this, e, type, true, this._latlng);
|
||||
}
|
||||
},
|
||||
|
||||
setOpacity: function (opacity) {
|
||||
this.options.opacity = opacity;
|
||||
if (this._map) {
|
||||
|
@ -554,7 +554,7 @@ L.Map = L.Evented.extend({
|
||||
onOff = onOff || 'on';
|
||||
|
||||
L.DomEvent[onOff](this._container,
|
||||
'click dblclick mousedown mouseup mouseenter mouseleave mousemove contextmenu',
|
||||
'click dblclick mousedown mouseup mouseover mouseout mousemove contextmenu keypress',
|
||||
this._handleMouseEvent, this);
|
||||
|
||||
this._targets = {};
|
||||
@ -575,9 +575,24 @@ L.Map = L.Evented.extend({
|
||||
|
||||
var target = this._targets[L.stamp(e.target || e.srcElement)];
|
||||
|
||||
this._fireMouseEvent(target || this, e,
|
||||
e.type === 'mouseenter' ? 'mouseover' :
|
||||
e.type === 'mouseleave' ? 'mouseout' : e.type, true);
|
||||
var type =
|
||||
e.type === 'mouseenter' ? 'mouseover' :
|
||||
e.type === 'mouseleave' ? 'mouseout' : e.type;
|
||||
|
||||
if (e.type === 'keypress' && e.keyCode === 13) {
|
||||
type = 'click';
|
||||
}
|
||||
|
||||
// to prevent outline when clicking on keyboard-focusable element
|
||||
if (type === 'mousedown') {
|
||||
L.DomEvent.preventDefault(e);
|
||||
}
|
||||
|
||||
// special case for map mouseover/mouseout events so that they're actually mouseenter/mouseleave
|
||||
if (!target && (e.type === 'mouseover' || e.type === 'mouseout') &&
|
||||
!L.DomEvent._checkMouse(this._container, e)) { return; }
|
||||
|
||||
this._fireMouseEvent(target || this, e, type, true);
|
||||
},
|
||||
|
||||
_fireMouseEvent: function (obj, e, type, propagate, latlng) {
|
||||
@ -604,12 +619,15 @@ L.Map = L.Evented.extend({
|
||||
}
|
||||
|
||||
var data = {
|
||||
originalEvent: e,
|
||||
containerPoint: this.mouseEventToContainerPoint(e)
|
||||
originalEvent: e
|
||||
};
|
||||
|
||||
data.layerPoint = this.containerPointToLayerPoint(data.containerPoint);
|
||||
data.latlng = latlng || this.layerPointToLatLng(data.layerPoint);
|
||||
if (e.type !== 'keypress') {
|
||||
// TODO latlng isn't used, wrong latlng for markers
|
||||
data.containerPoint = this.mouseEventToContainerPoint(e);
|
||||
data.layerPoint = this.containerPointToLayerPoint(data.containerPoint);
|
||||
data.latlng = latlng || this.layerPointToLatLng(data.layerPoint);
|
||||
}
|
||||
|
||||
obj.fire(type, data, propagate);
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user