From: John Firebaugh Date: Wed, 6 Nov 2013 20:25:55 +0000 (-0800) Subject: Fix feedback loop between L.hash and popstate X-Git-Tag: live~4653^2~176 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/c798962cda8ede6425ce56c59533bc476180a830?hp=8756feab8a902bd1111adf3b1d9514988dde9bf3 Fix feedback loop between L.hash and popstate --- 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'});