From c798962cda8ede6425ce56c59533bc476180a830 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Wed, 6 Nov 2013 12:25:55 -0800 Subject: [PATCH] Fix feedback loop between L.hash and popstate --- app/assets/javascripts/index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/index.js b/app/assets/javascripts/index.js index c6295cb10..3db9d7ba0 100644 --- a/app/assets/javascripts/index.js +++ b/app/assets/javascripts/index.js @@ -24,8 +24,12 @@ $(document).ready(function () { map.hash = L.hash(map); - $(window).on('popstate', function() { - map.hash.update(); + $(window).on('popstate', function(e) { + // popstate is triggered when the hash changes as well as on actual navigation + // events. We want to update the hash on the latter and not the former. + if (e.originalEvent.state) { + map.hash.update(); + } }); var copyright = I18n.t('javascripts.map.copyright', {copyright_url: '/copyright'}); -- 2.39.5