2013-07-24 22:51:13 +02:00
|
|
|
var navigate = (function () {
|
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
2013-07-24 23:41:49 +02:00
|
|
|
|
2018-05-26 12:36:24 +02:00
|
|
|
function go_to_row(msg_id) {
|
|
|
|
current_msg_list.select_id(msg_id,
|
2013-07-24 23:41:49 +02:00
|
|
|
{then_scroll: true,
|
|
|
|
from_scroll: true});
|
|
|
|
}
|
|
|
|
|
2013-07-24 22:51:13 +02:00
|
|
|
exports.up = function () {
|
2018-08-04 08:33:00 +02:00
|
|
|
message_viewport.set_last_movement_direction(-1);
|
2018-05-26 12:36:24 +02:00
|
|
|
var msg_id = current_msg_list.prev();
|
|
|
|
if (msg_id === undefined) {
|
|
|
|
return;
|
2013-07-24 22:51:13 +02:00
|
|
|
}
|
2018-05-26 12:36:24 +02:00
|
|
|
go_to_row(msg_id);
|
2013-07-24 22:51:13 +02:00
|
|
|
};
|
|
|
|
|
2013-08-05 21:52:38 +02:00
|
|
|
exports.down = function (with_centering) {
|
2018-08-04 08:33:00 +02:00
|
|
|
message_viewport.set_last_movement_direction(1);
|
2018-05-29 00:21:13 +02:00
|
|
|
|
|
|
|
if (current_msg_list.is_at_end()) {
|
|
|
|
if (with_centering) {
|
|
|
|
// At the last message, scroll to the bottom so we have
|
|
|
|
// lots of nice whitespace for new messages coming in.
|
|
|
|
var current_msg_table = rows.get_table(current_msg_list.table_name);
|
|
|
|
message_viewport.scrollTop(current_msg_table.safeOuterHeight(true) -
|
|
|
|
message_viewport.height() * 0.1);
|
2019-07-10 02:03:41 +02:00
|
|
|
if (current_msg_list.can_mark_messages_read()) {
|
|
|
|
unread_ops.mark_current_list_as_read();
|
|
|
|
}
|
2018-05-29 00:21:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Normal path starts here.
|
2018-05-26 12:36:24 +02:00
|
|
|
var msg_id = current_msg_list.next();
|
|
|
|
if (msg_id === undefined) {
|
|
|
|
return;
|
2013-07-24 22:51:13 +02:00
|
|
|
}
|
2018-05-26 12:36:24 +02:00
|
|
|
go_to_row(msg_id);
|
2013-07-24 22:51:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.to_home = function () {
|
2018-08-04 08:33:00 +02:00
|
|
|
message_viewport.set_last_movement_direction(-1);
|
2017-09-30 18:17:34 +02:00
|
|
|
var first_id = current_msg_list.first().id;
|
|
|
|
current_msg_list.select_id(first_id, {then_scroll: true,
|
|
|
|
from_scroll: true});
|
2013-07-24 22:51:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.to_end = function () {
|
|
|
|
var next_id = current_msg_list.last().id;
|
2018-08-04 08:33:00 +02:00
|
|
|
message_viewport.set_last_movement_direction(1);
|
2013-07-24 22:51:13 +02:00
|
|
|
current_msg_list.select_id(next_id, {then_scroll: true,
|
|
|
|
from_scroll: true});
|
2019-07-10 02:03:41 +02:00
|
|
|
if (current_msg_list.can_mark_messages_read()) {
|
|
|
|
unread_ops.mark_current_list_as_read();
|
|
|
|
}
|
2013-07-24 22:51:13 +02:00
|
|
|
};
|
|
|
|
|
2017-03-18 23:23:39 +01:00
|
|
|
function amount_to_paginate() {
|
|
|
|
// Some day we might have separate versions of this function
|
|
|
|
// for Page Up vs. Page Down, but for now it's the same
|
|
|
|
// strategy in either direction.
|
|
|
|
var info = message_viewport.message_viewport_info();
|
|
|
|
var page_size = info.visible_height;
|
|
|
|
|
|
|
|
// We don't want to page up a full page, because Zulip users
|
|
|
|
// are especially worried about missing messages, so we want
|
|
|
|
// a little bit of the old page to stay on the screen. The
|
|
|
|
// value chosen here is roughly 2 or 3 lines of text, but there
|
|
|
|
// is nothing sacred about it, and somebody more anal than me
|
|
|
|
// might wish to tie this to the size of some particular DOM
|
|
|
|
// element.
|
|
|
|
var overlap_amount = 55;
|
|
|
|
|
|
|
|
var delta = page_size - overlap_amount;
|
|
|
|
|
|
|
|
// If the user has shrunk their browser a whole lot, pagination
|
|
|
|
// is not going to be very pleasant, but we can at least
|
|
|
|
// ensure they go in the right direction.
|
|
|
|
if (delta < 1) {
|
|
|
|
delta = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return delta;
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.page_up_the_right_amount = function () {
|
|
|
|
// This function's job is to scroll up the right amount,
|
|
|
|
// after the user hits Page Up. We do this ourselves
|
|
|
|
// because we can't rely on the browser to account for certain
|
|
|
|
// page elements, like the compose box, that sit in fixed
|
|
|
|
// positions above the message pane. For other scrolling
|
|
|
|
// related adjustements, try to make those happen in the
|
|
|
|
// scroll handlers, not here.
|
|
|
|
var delta = amount_to_paginate();
|
|
|
|
message_viewport.scrollTop(message_viewport.scrollTop() - delta);
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.page_down_the_right_amount = function () {
|
|
|
|
// see also: page_up_the_right_amount
|
|
|
|
var delta = amount_to_paginate();
|
|
|
|
message_viewport.scrollTop(message_viewport.scrollTop() + delta);
|
|
|
|
};
|
|
|
|
|
2013-07-24 22:51:13 +02:00
|
|
|
exports.page_up = function () {
|
2017-03-10 23:48:51 +01:00
|
|
|
if (message_viewport.at_top() && !current_msg_list.empty()) {
|
2013-07-24 22:51:13 +02:00
|
|
|
current_msg_list.select_id(current_msg_list.first().id, {then_scroll: false});
|
2016-06-09 23:02:49 +02:00
|
|
|
} else {
|
2017-03-18 23:23:39 +01:00
|
|
|
exports.page_up_the_right_amount();
|
2013-07-24 22:51:13 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.page_down = function () {
|
2017-03-10 23:48:51 +01:00
|
|
|
if (message_viewport.at_bottom() && !current_msg_list.empty()) {
|
2013-07-24 22:51:13 +02:00
|
|
|
current_msg_list.select_id(current_msg_list.last().id, {then_scroll: false});
|
2019-07-10 02:03:41 +02:00
|
|
|
if (current_msg_list.can_mark_messages_read()) {
|
|
|
|
unread_ops.mark_current_list_as_read();
|
|
|
|
}
|
2016-06-09 23:02:49 +02:00
|
|
|
} else {
|
2017-03-18 23:23:39 +01:00
|
|
|
exports.page_down_the_right_amount();
|
2013-07-24 22:51:13 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-05-25 13:26:57 +02:00
|
|
|
exports.scroll_to_selected = function () {
|
|
|
|
var selected_row = current_msg_list.selected_row();
|
2018-06-06 18:50:09 +02:00
|
|
|
if (selected_row && selected_row.length !== 0) {
|
2017-03-10 23:48:51 +01:00
|
|
|
message_viewport.recenter_view(selected_row);
|
2016-05-25 13:26:57 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-05-25 13:24:33 +02:00
|
|
|
|
|
|
|
exports.maybe_scroll_to_selected = function () {
|
|
|
|
// If we have been previously instructed to re-center to the
|
|
|
|
// selected message, then do so
|
|
|
|
if (pointer.recenter_pointer_on_display) {
|
2016-05-25 13:26:57 +02:00
|
|
|
exports.scroll_to_selected();
|
2018-08-04 08:38:54 +02:00
|
|
|
pointer.set_recenter_pointer_on_display(false);
|
2016-05-25 13:24:33 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-24 22:51:13 +02:00
|
|
|
return exports;
|
2013-08-02 19:33:20 +02:00
|
|
|
}());
|
2016-12-04 08:59:56 +01:00
|
|
|
|
|
|
|
if (typeof module !== 'undefined') {
|
|
|
|
module.exports = navigate;
|
|
|
|
}
|
2018-05-28 08:04:36 +02:00
|
|
|
window.navigate = navigate;
|