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 = new L.Draggable(icon, icon);
} }
this._draggable this._draggable.on({
.on('dragstart', this._onDragStart, this) dragstart: this._onDragStart,
.on('drag', this._onDrag, this) drag: this._onDrag,
.on('dragend', this._onDragEnd, this) dragend: this._onDragEnd
.enable(); }).enable();
L.DomUtil.addClass(icon, 'leaflet-marker-draggable'); L.DomUtil.addClass(icon, 'leaflet-marker-draggable');
}, },
removeHooks: function () { removeHooks: function () {
this._draggable this._draggable.off({
.off('dragstart', this._onDragStart, this) dragstart: this._onDragStart,
.off('drag', this._onDrag, this) drag: this._onDrag,
.off('dragend', this._onDragEnd, this) dragend: this._onDragEnd
.disable(); }).disable();
L.DomUtil.removeClass(this._marker._icon, 'leaflet-marker-draggable'); L.DomUtil.removeClass(this._marker._icon, 'leaflet-marker-draggable');
}, },

View File

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

View File

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

View File

@ -127,14 +127,14 @@ L.Map = L.Evented.extend({
this.options.maxBounds = bounds; this.options.maxBounds = bounds;
if (!bounds) { if (!bounds) {
return this.off('moveend', this._panInsideMaxBounds, this); return this.off('moveend', this._panInsideMaxBounds);
} }
if (this._loaded) { if (this._loaded) {
this._panInsideMaxBounds(); this._panInsideMaxBounds();
} }
return this.on('moveend', this._panInsideMaxBounds, this); return this.on('moveend', this._panInsideMaxBounds);
}, },
panInsideBounds: function (bounds, options) { 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 = new L.Draggable(map._mapPane, map._container);
this._draggable.on({ this._draggable.on({
'dragstart': this._onDragStart, dragstart: this._onDragStart,
'drag': this._onDrag, drag: this._onDrag,
'dragend': this._onDragEnd dragend: this._onDragEnd
}, this); }, this);
if (map.options.worldCopyJump) { if (map.options.worldCopyJump) {