mirror of
https://github.com/zulip/zulip.git
synced 2025-11-10 17:07:07 +00:00
Let the browser scroll happen before our scrolling on a (re)load.
On a page load or reload, the browser will, at an idle time, scroll to the top of the page. We can't intercept this browser-induced scroll, so to make sure it doesn't in interfere with our scrolling to the correct place in your message feed, we let the browser scroll happen before the work we do on page load. (imported from commit f5f441ab90bcdb8404e05caea3c6da81a3a6fc1e)
This commit is contained in:
@@ -39,6 +39,8 @@ var pointer_update_in_flight = false;
|
||||
|
||||
var events_stored_during_tutorial = [];
|
||||
|
||||
var waiting_on_browser_scroll = true;
|
||||
|
||||
function add_person(person) {
|
||||
page_params.people_list.push(person);
|
||||
people_dict[person.email] = person;
|
||||
@@ -1051,6 +1053,13 @@ function process_result(messages, opts) {
|
||||
}
|
||||
|
||||
function get_old_messages_success(data, opts) {
|
||||
if (waiting_on_browser_scroll) {
|
||||
setTimeout(function () {
|
||||
get_old_messages_success(data, opts);
|
||||
}, 25);
|
||||
return;
|
||||
}
|
||||
|
||||
if (opts.msg_list.narrowed && opts.msg_list !== current_msg_list) {
|
||||
// We unnarrowed before receiving new messages so
|
||||
// don't bother processing the newly arrived messages.
|
||||
@@ -1315,6 +1324,35 @@ function main() {
|
||||
}
|
||||
}
|
||||
|
||||
function install_main_scroll_handler() {
|
||||
waiting_on_browser_scroll = false;
|
||||
// Unregister this special un-throttled scroll handler.
|
||||
$(window).unbind("scroll");
|
||||
// Register the normal throttled scroll handler.
|
||||
ui.register_scroll_handler();
|
||||
}
|
||||
|
||||
$(function () {
|
||||
// On a page load or reload, the browser will, at an idle time, scroll to
|
||||
// the top of the page. We can't intercept this browser-induced scroll, so
|
||||
// to make sure it doesn't in interfere with our scrolling to the correct
|
||||
// place in your message feed, we let the browser scroll happen first.
|
||||
|
||||
// After some time, if we haven't seen the browser scroll, give up
|
||||
// and call main.
|
||||
var browser_scroll_timer = setTimeout(function () {
|
||||
install_main_scroll_handler();
|
||||
}, 500);
|
||||
|
||||
(window).scroll(function () {
|
||||
if (viewport.scrollTop() < viewport.height()) {
|
||||
// This is the browser-induced scroll to the top of the
|
||||
// page that we were waiting for. It only happens once,
|
||||
// so stop waiting and call main.
|
||||
install_main_scroll_handler();
|
||||
clearTimeout(browser_scroll_timer);
|
||||
}
|
||||
});
|
||||
|
||||
main();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user