From 9e6a747f6f19e8db6d70dc255a5cf1f94284cce8 Mon Sep 17 00:00:00 2001 From: Vladimir Agafonkin Date: Sat, 21 Dec 2013 09:53:26 +0100 Subject: [PATCH] minor events-related cleanup --- src/layer/marker/Marker.Drag.js | 20 ++++++++++---------- src/layer/marker/Marker.Popup.js | 18 ++++++++++-------- src/layer/vector/Path.Popup.js | 14 ++++++++------ src/map/Map.js | 4 ++-- src/map/handler/Map.Drag.js | 6 +++--- 5 files changed, 33 insertions(+), 29 deletions(-) diff --git a/src/layer/marker/Marker.Drag.js b/src/layer/marker/Marker.Drag.js index e03fa716..dd013541 100644 --- a/src/layer/marker/Marker.Drag.js +++ b/src/layer/marker/Marker.Drag.js @@ -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'); }, diff --git a/src/layer/marker/Marker.Popup.js b/src/layer/marker/Marker.Popup.js index 4acbd142..cfca0a6f 100644 --- a/src/layer/marker/Marker.Popup.js +++ b/src/layer/marker/Marker.Popup.js @@ -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; diff --git a/src/layer/vector/Path.Popup.js b/src/layer/vector/Path.Popup.js index ffb167d7..e70e9586 100644 --- a/src/layer/vector/Path.Popup.js +++ b/src/layer/vector/Path.Popup.js @@ -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; } diff --git a/src/map/Map.js b/src/map/Map.js index 8e44fa54..c4ee7528 100644 --- a/src/map/Map.js +++ b/src/map/Map.js @@ -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) { diff --git a/src/map/handler/Map.Drag.js b/src/map/handler/Map.Drag.js index 23d89c8b..f66912a5 100644 --- a/src/map/handler/Map.Drag.js +++ b/src/map/handler/Map.Drag.js @@ -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) {