2013-07-24 22:51:13 +02:00
|
|
|
var navigate = (function () {
|
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
2013-07-24 23:41:49 +02:00
|
|
|
|
|
|
|
function go_to_row(row) {
|
|
|
|
current_msg_list.select_id(rows.id(row),
|
|
|
|
{then_scroll: true,
|
|
|
|
from_scroll: true});
|
|
|
|
}
|
|
|
|
|
2013-07-24 22:51:13 +02:00
|
|
|
exports.up = function () {
|
2017-03-10 23:48:51 +01:00
|
|
|
message_viewport.last_movement_direction = -1;
|
2013-07-24 22:51:13 +02:00
|
|
|
var next_row = rows.prev_visible(current_msg_list.selected_row());
|
|
|
|
if (next_row.length !== 0) {
|
2013-07-24 23:41:49 +02:00
|
|
|
go_to_row(next_row);
|
2013-07-24 22:51:13 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-08-05 21:52:38 +02:00
|
|
|
exports.down = function (with_centering) {
|
2017-03-10 23:48:51 +01:00
|
|
|
message_viewport.last_movement_direction = 1;
|
2013-07-24 22:51:13 +02:00
|
|
|
var next_row = rows.next_visible(current_msg_list.selected_row());
|
|
|
|
if (next_row.length !== 0) {
|
2013-07-24 23:41:49 +02:00
|
|
|
go_to_row(next_row);
|
2013-07-24 22:51:13 +02:00
|
|
|
}
|
2013-08-05 21:52:38 +02:00
|
|
|
if (with_centering && (next_row.length === 0)) {
|
|
|
|
// At the last message, scroll to the bottom so we have
|
|
|
|
// lots of nice whitespace for new messages coming in.
|
|
|
|
//
|
|
|
|
// FIXME: this doesn't work for End because rows.last_visible()
|
|
|
|
// always returns a message.
|
|
|
|
var current_msg_table = rows.get_table(current_msg_list.table_name);
|
2017-03-10 23:48:51 +01:00
|
|
|
message_viewport.scrollTop(current_msg_table.outerHeight(true) -
|
|
|
|
message_viewport.height() * 0.1);
|
2017-02-11 09:55:18 +01:00
|
|
|
unread_ui.mark_current_list_as_read();
|
2013-08-05 21:52:38 +02:00
|
|
|
}
|
2013-07-24 22:51:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.to_home = function () {
|
2017-03-10 23:48:51 +01:00
|
|
|
message_viewport.last_movement_direction = -1;
|
2013-07-24 22:51:13 +02:00
|
|
|
var next_row = rows.first_visible(current_msg_list.selected_row());
|
|
|
|
if (next_row.length !== 0) {
|
2013-07-24 23:41:49 +02:00
|
|
|
go_to_row(next_row);
|
2013-07-24 22:51:13 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.to_end = function () {
|
|
|
|
var next_id = current_msg_list.last().id;
|
2017-03-10 23:48:51 +01:00
|
|
|
message_viewport.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});
|
2017-02-11 09:55:18 +01:00
|
|
|
unread_ui.mark_current_list_as_read();
|
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 {
|
2013-07-24 22:51:13 +02:00
|
|
|
ui.page_up_the_right_amount();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
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});
|
2017-02-11 09:55:18 +01:00
|
|
|
unread_ui.mark_current_list_as_read();
|
2016-06-09 23:02:49 +02:00
|
|
|
} else {
|
2013-07-24 22:51:13 +02:00
|
|
|
ui.page_down_the_right_amount();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-02-14 19:32:40 +01:00
|
|
|
exports.cycle_stream = function (direction) {
|
2016-12-02 17:09:31 +01:00
|
|
|
var currentStream;
|
|
|
|
var nextStream;
|
2014-02-14 19:32:40 +01:00
|
|
|
if (narrow.stream() !== undefined) {
|
|
|
|
currentStream = stream_list.get_stream_li(narrow.stream());
|
|
|
|
}
|
|
|
|
switch (direction) {
|
|
|
|
case 'forward':
|
|
|
|
if (narrow.stream() === undefined) {
|
2014-02-28 22:48:45 +01:00
|
|
|
nextStream = $("#stream_filters").children('.narrow-filter').first();
|
2014-02-14 19:32:40 +01:00
|
|
|
} else {
|
2014-02-28 22:48:45 +01:00
|
|
|
nextStream = currentStream.next('.narrow-filter');
|
2014-02-14 19:32:40 +01:00
|
|
|
if (nextStream.length === 0) {
|
2014-02-28 22:48:45 +01:00
|
|
|
nextStream = $("#stream_filters").children('.narrow-filter').first();
|
2014-02-14 19:32:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'backward':
|
|
|
|
if (narrow.stream() === undefined) {
|
2014-02-28 22:48:45 +01:00
|
|
|
nextStream = $("#stream_filters").children('.narrow-filter').last();
|
2014-02-14 19:32:40 +01:00
|
|
|
} else {
|
2014-02-28 22:48:45 +01:00
|
|
|
nextStream = currentStream.prev('.narrow-filter');
|
2014-02-14 19:32:40 +01:00
|
|
|
if (nextStream.length === 0) {
|
2014-02-28 22:48:45 +01:00
|
|
|
nextStream = $("#stream_filters").children('.narrow-filter').last();
|
2014-02-14 19:32:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
blueslip.error("Invalid parameter to cycle_stream", {value: direction});
|
|
|
|
}
|
|
|
|
narrow.by('stream', nextStream.data('name'));
|
|
|
|
};
|
|
|
|
|
2016-05-25 13:26:57 +02:00
|
|
|
exports.scroll_to_selected = function () {
|
|
|
|
var selected_row = current_msg_list.selected_row();
|
|
|
|
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();
|
2016-05-25 13:24:33 +02:00
|
|
|
pointer.recenter_pointer_on_display = false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|