]> git.openstreetmap.org Git - rails.git/commitdiff
Ignore hashchange-triggered popstate events here too
authorJohn Firebaugh <john.firebaugh@gmail.com>
Fri, 8 Nov 2013 20:19:47 +0000 (12:19 -0800)
committerJohn Firebaugh <john.firebaugh@gmail.com>
Fri, 8 Nov 2013 21:42:24 +0000 (13:42 -0800)
app/assets/javascripts/router.js

index 654ec860b549b2483d2a8fea51a46edc9bc5eec7..7a61af106df9696b36ebc4bb68a8cda13be12da7 100644 (file)
@@ -50,7 +50,12 @@ OSM.Router = function(rts) {
   currentRoute.run('load', currentPath);
 
   if (window.history && window.history.pushState) {
-    $(window).on('popstate', function() {
+    // Set a non-null initial state, so that the e.originalEvent.state
+    // check below works correctly when going back to the initial page.
+    window.history.replaceState({}, document.title, window.location);
+
+    $(window).on('popstate', function(e) {
+      if (!e.originalEvent.state) return; // Is it a real popstate event or just a hash change?
       var path = window.location.pathname + window.location.search;
       if (path === currentPath) return;
       currentRoute.run('unload');