mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 23:13:25 +00:00
We suspect that these seem to be causing a regression where scrolling in narrowed views gets really sluggish, but we haven't totally been able to figure out why since it's challenging to reproduce locally. (It currently manifests itself on staging but not prod.) So for now we'll back them out. Here's the full set of things: Revert "Cause update_floating_recipient_bar to get called less frequently." This reverts commit a6c1518c4001a2dde44d7b512236795da3ccd351. Revert "Remove double-scroll in un-narrowing code." This reverts commit 3dde6c27ffa1e8afa1a084b1b2baee3bc0512962. Revert "Reset our scroll position if we change our hash to "#"." This reverts commit 925b44d770c96dafaabebc9e0114f9a3b8f53c4d. Revert "Properly update floating subject bar when you are at top of page." This reverts commit 6633cc8a81aedcbb31b30d7c1f27816f8808c700. (imported from commit a273730581cef30c33bedf701659ee084434f8ad)
91 lines
2.5 KiB
JavaScript
91 lines
2.5 KiB
JavaScript
var hashchange = (function () {
|
|
|
|
var exports = {};
|
|
|
|
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);
|
|
}
|
|
};
|
|
|
|
exports.save_narrow = function (operators) {
|
|
if (operators === undefined) {
|
|
exports.changehash('#');
|
|
} else {
|
|
var new_hash = '#narrow';
|
|
$.each(operators, function (idx, elem) {
|
|
new_hash += '/' + encodeURIComponent(elem[0])
|
|
+ '/' + encodeURIComponent(elem[1]);
|
|
});
|
|
exports.changehash(new_hash);
|
|
}
|
|
};
|
|
|
|
function parse_narrow(hash) {
|
|
var i, operators = [];
|
|
for (i=1; i<hash.length; i+=2) {
|
|
// We don't construct URLs with an odd number of components,
|
|
// but the user might write one.
|
|
var operator = decodeURIComponent(hash[i]);
|
|
var operand = decodeURIComponent(hash[i+1] || '');
|
|
operators.push([operator, operand]);
|
|
}
|
|
narrow.activate(operators);
|
|
}
|
|
|
|
// Returns true if this function performed a narrow
|
|
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 false;
|
|
}
|
|
|
|
var hash = window.location.hash.split("/");
|
|
switch (hash[0]) {
|
|
case "#narrow":
|
|
ui.change_tab_to("#home");
|
|
parse_narrow(hash);
|
|
ui.update_floating_recipient_bar();
|
|
return true;
|
|
case "":
|
|
case "#":
|
|
ui.change_tab_to("#home");
|
|
narrow.deactivate();
|
|
ui.update_floating_recipient_bar();
|
|
break;
|
|
case "#subscriptions":
|
|
ui.change_tab_to("#subscriptions");
|
|
break;
|
|
case "#settings":
|
|
ui.change_tab_to("#settings");
|
|
break;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
exports.initialize = function () {
|
|
window.onhashchange = hashchanged;
|
|
if (hashchanged()) {
|
|
load_more_messages();
|
|
}
|
|
};
|
|
|
|
return exports;
|
|
|
|
}());
|