Make the back button work for the settings and subscriptions pages

(imported from commit 650c884abc9514cdfc934ae01e0a490f5f681292)
This commit is contained in:
Jeff Arnold
2012-12-19 15:19:29 -05:00
parent f4ddf4412b
commit 4feae6b202
3 changed files with 36 additions and 10 deletions

View File

@@ -6,7 +6,18 @@ var expected_hash = false;
exports.changehash = function (newhash) {
expected_hash = newhash;
// Some browsers reset scrollTop when changing the hash to "",
// so we save and restore it.
// http://stackoverflow.com/questions/4715073/window-location-hash-prevent-scrolling-to-the-top
var scrolltop;
if (newhash === "") {
scrolltop = viewport.scrollTop();
}
window.location.hash = newhash;
util.reset_favicon();
if (newhash === "") {
viewport.scrollTop(scrolltop);
}
};
function hashchanged() {
@@ -19,13 +30,24 @@ function hashchanged() {
}
var hash = window.location.hash.split("/");
if (hash[0] === "#narrow") {
narrow.hashchanged(hash);
ui.update_floating_recipient_bar();
}
else if (narrow.active()) {
narrow.show_all_messages();
ui.update_floating_recipient_bar();
switch (hash[0]) {
case "#narrow":
ui.change_tab_to("#home");
narrow.hashchanged(hash);
ui.update_floating_recipient_bar();
break;
case "":
case "#":
ui.change_tab_to("#home");
narrow.show_all_messages();
ui.update_floating_recipient_bar();
break;
case "#subscriptions":
ui.change_tab_to("#subscriptions");
break;
case "#settings":
ui.change_tab_to("#settings");
break;
}
}