From ea3f177de21eda173d0a1ac96522de0f9750d65b Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Wed, 11 Nov 2015 20:37:38 +0100 Subject: [PATCH] Prevent from registering events twice if calling startListening twice --- leaflet-hash.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/leaflet-hash.js b/leaflet-hash.js index 70a1007..a7b2940 100644 --- a/leaflet-hash.js +++ b/leaflet-hash.js @@ -60,9 +60,7 @@ this.lastHash = null; this.onHashChange(); - if (!this.isListening) { - this.startListening(); - } + this.startListening(); }, removeFrom: function(map) { @@ -70,9 +68,7 @@ clearTimeout(this.changeTimeout); } - if (this.isListening) { - this.stopListening(); - } + this.stopListening(); this.map = null; }, @@ -128,6 +124,7 @@ isListening: false, hashChangeInterval: null, startListening: function() { + if (this.isListening) { return; } this.map.on("moveend", this.onMapMove, this); if (HAS_HASHCHANGE) { @@ -140,6 +137,7 @@ }, stopListening: function() { + if (!this.isListening) { return; } this.map.off("moveend", this.onMapMove, this); if (HAS_HASHCHANGE) {