From fa239ea2705b97571adb68e26f710e89d877b686 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Wed, 3 Apr 2013 14:44:26 -0400 Subject: [PATCH] hashchange: Don't change the hash when called from hashchange code. I generally don't like this sort of state variable, but I don't see a better solution. The codepath is that when you start out on the subscriptions page and then click one of the left sidebar links to narrow to something: (1) hashchanged() would call ui.change_tab (2) ui.change_tab triggers a gear change event (3) The ui.js gear-changed event handler updates the hash Resulting in the hash ending up at "#". Since there's no easy way to pass arguments through to the event handler, we just use a global variable inside hash_change.js to track whether we're currently handling a hashchange event. (imported from commit 7bb905a223b5539240fc36de7896ee8074ebc62e) --- zephyr/static/js/hashchange.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/zephyr/static/js/hashchange.js b/zephyr/static/js/hashchange.js index 7e4bf29640..3319207d32 100644 --- a/zephyr/static/js/hashchange.js +++ b/zephyr/static/js/hashchange.js @@ -3,6 +3,7 @@ var hashchange = (function () { var exports = {}; var expected_hash = false; +var changing_hash = false; // Some browsers zealously URI-decode the contents of // window.location.hash. So we hide our URI-encoding @@ -19,6 +20,9 @@ function decodeHashComponent(str) { } exports.changehash = function (newhash) { + if (changing_hash) { + return; + } expected_hash = newhash; // Some browsers reset scrollTop when changing the hash to "", // so we save and restore it. @@ -32,6 +36,9 @@ exports.changehash = function (newhash) { }; exports.save_narrow = function (operators) { + if (changing_hash) { + return; + } if (operators === undefined) { exports.changehash('#'); } else { @@ -60,7 +67,7 @@ function parse_narrow(hash) { } // Returns true if this function performed a narrow -function hashchanged() { +function do_hashchange() { // If window.location.hash changed because our app explicitly // changed it, then we don't need to do anything. // (This function only neds to jump into action if it changed @@ -95,6 +102,13 @@ function hashchanged() { return false; } +function hashchanged() { + changing_hash = true; + var ret = do_hashchange(); + changing_hash = false; + return ret; +} + exports.initialize = function () { window.onhashchange = hashchanged; if (hashchanged()) {