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:
Jessica McKellar
2013-08-02 17:56:28 -04:00
parent 5b38b763d9
commit ccd2433345
2 changed files with 44 additions and 4 deletions

View File

@@ -1401,10 +1401,12 @@ function scroll_finish() {
scroll_timer = setTimeout(scroll_finished, 100); scroll_timer = setTimeout(scroll_finished, 100);
} }
$(window).scroll($.throttle(50, function (e) { exports.register_scroll_handler = function () {
process_visible_unread_messages(); $(window).scroll($.throttle(50, function (e) {
scroll_finish(); process_visible_unread_messages();
})); scroll_finish();
}));
};
var presence_descriptions = { var presence_descriptions = {
active: 'is active', active: 'is active',

View File

@@ -39,6 +39,8 @@ var pointer_update_in_flight = false;
var events_stored_during_tutorial = []; var events_stored_during_tutorial = [];
var waiting_on_browser_scroll = true;
function add_person(person) { function add_person(person) {
page_params.people_list.push(person); page_params.people_list.push(person);
people_dict[person.email] = person; people_dict[person.email] = person;
@@ -1051,6 +1053,13 @@ function process_result(messages, opts) {
} }
function get_old_messages_success(data, 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) { if (opts.msg_list.narrowed && opts.msg_list !== current_msg_list) {
// We unnarrowed before receiving new messages so // We unnarrowed before receiving new messages so
// don't bother processing the newly arrived messages. // 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 () { $(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(); main();
}); });