2012-12-07 20:52:39 +01:00
|
|
|
var hashchange = (function () {
|
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
|
|
|
var expected_hash = false;
|
|
|
|
|
|
|
|
exports.changehash = function (newhash) {
|
|
|
|
expected_hash = newhash;
|
2012-12-19 21:19:29 +01:00
|
|
|
// 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();
|
|
|
|
}
|
2012-12-07 20:52:39 +01:00
|
|
|
window.location.hash = newhash;
|
2012-12-19 21:19:29 +01:00
|
|
|
util.reset_favicon();
|
|
|
|
if (newhash === "") {
|
|
|
|
viewport.scrollTop(scrolltop);
|
|
|
|
}
|
2012-12-07 20:52:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
function hashchanged() {
|
|
|
|
// 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
|
|
|
|
// because e.g. the back button was pressed by the user)
|
|
|
|
if (window.location.hash === expected_hash) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var hash = window.location.hash.split("/");
|
2012-12-19 21:19:29 +01:00
|
|
|
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;
|
2012-12-07 20:52:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.initialize = function () {
|
|
|
|
window.onhashchange = hashchanged;
|
2012-12-18 00:31:21 +01:00
|
|
|
hashchanged();
|
2012-12-07 20:52:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
return exports;
|
|
|
|
|
|
|
|
}());
|