diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2016-08-16 15:27:31 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2016-08-17 00:14:03 +0100 |
commit | 7ac628dad473020534fd4fc831c9c65c6193e916 (patch) | |
tree | d5c506a3c621da1c71211e208994d4b24f9c9c65 | |
parent | ce61bff5a9c9133f4ea522830c136095068ef8d9 (diff) |
Simplify blank popState case.
Prevent possible infinite loops during internal hashref change.
-rw-r--r-- | web/cobrands/fixmystreet/fixmystreet.js | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/web/cobrands/fixmystreet/fixmystreet.js b/web/cobrands/fixmystreet/fixmystreet.js index bafe88635..d98730b62 100644 --- a/web/cobrands/fixmystreet/fixmystreet.js +++ b/web/cobrands/fixmystreet/fixmystreet.js @@ -759,7 +759,7 @@ $.extend(fixmystreet.set_up, { // we want to record the navigation as a state, so the user // can return to it later using their Back button. if ('pushState' in history) { - history.pushState(null, null, reportListUrl); + history.pushState({ initial: true }, null, reportListUrl); } }); }); @@ -1050,6 +1050,11 @@ $(function() { setup_func(); }); + // Have a fake history entry so we can cover all eventualities. + if ('replaceState' in history) { + history.replaceState({ initial: true }, null); + } + $(window).on('load', function () { setTimeout(function () { window.addEventListener('popstate', function(e) { @@ -1060,9 +1065,16 @@ $(function() { // because we're already inside a popstate: We want to roll // back to a previous state, not create a new one! + if (!fixmystreet.page) { + // Only care about map pages, which set this variable + return; + } + var location = window.history.location || window.location; if (e.state === null) { + // Hashchange or whatever, we don't care. + } else if ('initial' in e.state) { // User has navigated Back from a pushStated state, presumably to // see the list of all reports (which was shown on pageload). By // this point, the browser has *already* updated the URL bar so |