From a2859ba7d6900dda910e519046026745a5f962ad Mon Sep 17 00:00:00 2001 From: Mikel Maron Date: Wed, 9 Apr 2014 11:21:11 -0400 Subject: [PATCH 1/4] event handling, to extend to manage other hash arguments and map behaviors (ie add/remove layers) --- leaflet-hash.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/leaflet-hash.js b/leaflet-hash.js index 70a1007..f8442bd 100644 --- a/leaflet-hash.js +++ b/leaflet-hash.js @@ -11,6 +11,8 @@ if (map) { this.init(map); } + + this.events = new Object(); }; L.Hash.parseHash = function(hash) { @@ -86,6 +88,12 @@ } var hash = this.formatHash(this.map); + if (this.events['change']) { + for (var i=0; i Date: Wed, 9 Apr 2014 15:13:19 -0400 Subject: [PATCH 2/4] fixed indent --- leaflet-hash.js | 86 ++++++++++++++++++++++++------------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/leaflet-hash.js b/leaflet-hash.js index f8442bd..2693024 100644 --- a/leaflet-hash.js +++ b/leaflet-hash.js @@ -12,7 +12,7 @@ this.init(map); } - this.events = new Object(); + this.events = new Object(); }; L.Hash.parseHash = function(hash) { @@ -88,11 +88,11 @@ } var hash = this.formatHash(this.map); - if (this.events['change']) { - for (var i=0; i Date: Wed, 9 Apr 2014 17:04:29 -0400 Subject: [PATCH 3/4] added tests for event callbacks --- test/spec/hash.js | 84 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/test/spec/hash.js b/test/spec/hash.js index 4360fd9..c282714 100644 --- a/test/spec/hash.js +++ b/test/spec/hash.js @@ -65,4 +65,88 @@ describe("L.Hash", function() { map.setView([51, 2], 13); expect(L.Hash.formatHash(map)).to.be('#13/51.0000/2.0000'); }); + + function setQueryVariable(hash, key, value) { + var vars = hash.split("&"); + var found = false; + for (var i=0;i Date: Thu, 10 Apr 2014 11:30:15 -0400 Subject: [PATCH 4/4] "hash" event fires when location.hash has changed useful for updating embed links and such --- leaflet-hash.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/leaflet-hash.js b/leaflet-hash.js index 2693024..a93dad4 100644 --- a/leaflet-hash.js +++ b/leaflet-hash.js @@ -97,6 +97,11 @@ if (this.lastHash != hash) { location.replace(hash); this.lastHash = hash; + if (this.events['hash']) { + for (var i=0; i