Restore the browser's scroll position on server-initiated reload.

(imported from commit 934659c0f1a2c014cfd2811fe49ea31abad262b2)
This commit is contained in:
Tim Abbott
2014-02-04 16:02:26 -05:00
parent e8834c2a9b
commit 1bd9e5809c
4 changed files with 20 additions and 7 deletions

View File

@@ -143,6 +143,7 @@ MessageList.prototype = {
select_id: function MessageList_select_id(id, opts) {
opts = _.extend({
then_scroll: false,
target_scroll_offset: undefined,
use_closest: false,
empty_ok: false,
mark_read: true,

View File

@@ -490,7 +490,8 @@ $(function () {
// a stream from the home before already
if (home_msg_list.selected_id() === -1 && !home_msg_list.empty()) {
home_msg_list.select_id(page_params.initial_pointer,
{then_scroll: true, use_closest: true});
{then_scroll: true, use_closest: true,
target_scroll_offset: page_params.initial_offset});
}
// catch the user up

View File

@@ -37,6 +37,10 @@ function preserve_state(send_after_reload) {
if (pointer !== -1) {
url += "+pointer=" + pointer;
}
var row = current_msg_list.selected_row();
if (row.length > 0) {
url += "+offset=" + row.offset().top;
}
var oldhash = window.location.hash;
if (oldhash.length !== 0 && oldhash[0] === '#') {
@@ -88,6 +92,10 @@ $(function () {
page_params.orig_initial_pointer = page_params.initial_pointer;
page_params.initial_pointer = pointer;
}
var offset = parseInt(vars.offset, 10);
if (offset) {
page_params.initial_offset = offset;
}
activity.new_user_input = false;
hashchange.changehash(vars.oldhash);

View File

@@ -1469,12 +1469,15 @@ $(function () {
found_in_dom: row_from_dom.length
});
}
// Scroll to place the message within the current view;
// but if this is the initial placement of the pointer,
// just place it in the very center
recenter_view(row, {from_scroll: event.from_scroll,
force_center: event.previously_selected === -1});
if (event.target_scroll_offset !== undefined) {
viewport.set_message_offset(event.target_scroll_offset);
} else {
// Scroll to place the message within the current view;
// but if this is the initial placement of the pointer,
// just place it in the very center
recenter_view(row, {from_scroll: event.from_scroll,
force_center: event.previously_selected === -1});
}
}
});