minor events-related cleanup

This commit is contained in:
Vladimir Agafonkin 2013-12-21 09:53:26 +01:00
parent deec9d54be
commit 9e6a747f6f
5 changed files with 33 additions and 29 deletions

View File

@ -14,21 +14,21 @@ L.Handler.MarkerDrag = L.Handler.extend({
this._draggable = new L.Draggable(icon, icon);
}
this._draggable
.on('dragstart', this._onDragStart, this)
.on('drag', this._onDrag, this)
.on('dragend', this._onDragEnd, this)
.enable();
this._draggable.on({
dragstart: this._onDragStart,
drag: this._onDrag,
dragend: this._onDragEnd
}).enable();
L.DomUtil.addClass(icon, 'leaflet-marker-draggable');
},
removeHooks: function () {
this._draggable
.off('dragstart', this._onDragStart, this)
.off('drag', this._onDrag, this)
.off('dragend', this._onDragEnd, this)
.disable();
this._draggable.off({
dragstart: this._onDragStart,
drag: this._onDrag,
dragend: this._onDragEnd
}).disable();
L.DomUtil.removeClass(this._marker._icon, 'leaflet-marker-draggable');
},

View File

@ -42,10 +42,11 @@ L.Marker.include({
options = L.extend({offset: anchor}, options);
if (!this._popupHandlersAdded) {
this
.on('click', this.togglePopup, this)
.on('remove', this.closePopup, this)
.on('move', this._movePopup, this);
this.on({
click: this.togglePopup,
remove: this.closePopup,
move: this._movePopup
});
this._popupHandlersAdded = true;
}
@ -70,10 +71,11 @@ L.Marker.include({
unbindPopup: function () {
if (this._popup) {
this._popup = null;
this
.off('click', this.togglePopup, this)
.off('remove', this.closePopup, this)
.off('move', this._movePopup, this);
this.on({
click: this.togglePopup,
remove: this.closePopup,
move: this._movePopup
});
this._popupHandlersAdded = false;
}
return this;

View File

@ -16,9 +16,10 @@ L.Path.include({
}
if (!this._popupHandlersAdded) {
this
.on('click', this._openPopup, this)
.on('remove', this.closePopup, this);
this.on({
click: this._openPopup,
remove: this.closePopup
});
this._popupHandlersAdded = true;
}
@ -29,9 +30,10 @@ L.Path.include({
unbindPopup: function () {
if (this._popup) {
this._popup = null;
this
.off('click', this._openPopup)
.off('remove', this.closePopup);
this.off({
click: this._openPopup,
remove: this.closePopup
});
this._popupHandlersAdded = false;
}

View File

@ -127,14 +127,14 @@ L.Map = L.Evented.extend({
this.options.maxBounds = bounds;
if (!bounds) {
return this.off('moveend', this._panInsideMaxBounds, this);
return this.off('moveend', this._panInsideMaxBounds);
}
if (this._loaded) {
this._panInsideMaxBounds();
}
return this.on('moveend', this._panInsideMaxBounds, this);
return this.on('moveend', this._panInsideMaxBounds);
},
panInsideBounds: function (bounds, options) {

View File

@ -23,9 +23,9 @@ L.Map.Drag = L.Handler.extend({
this._draggable = new L.Draggable(map._mapPane, map._container);
this._draggable.on({
'dragstart': this._onDragStart,
'drag': this._onDrag,
'dragend': this._onDragEnd
dragstart: this._onDragStart,
drag: this._onDrag,
dragend: this._onDragEnd
}, this);
if (map.options.worldCopyJump) {