mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
Move paging methods into navigate.js.
This commit is contained in:
@@ -52,11 +52,57 @@ exports.to_end = function () {
|
|||||||
unread_ops.mark_current_list_as_read();
|
unread_ops.mark_current_list_as_read();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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);
|
||||||
|
};
|
||||||
|
|
||||||
exports.page_up = function () {
|
exports.page_up = function () {
|
||||||
if (message_viewport.at_top() && !current_msg_list.empty()) {
|
if (message_viewport.at_top() && !current_msg_list.empty()) {
|
||||||
current_msg_list.select_id(current_msg_list.first().id, {then_scroll: false});
|
current_msg_list.select_id(current_msg_list.first().id, {then_scroll: false});
|
||||||
} else {
|
} else {
|
||||||
ui.page_up_the_right_amount();
|
exports.page_up_the_right_amount();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -65,7 +111,7 @@ exports.page_down = function () {
|
|||||||
current_msg_list.select_id(current_msg_list.last().id, {then_scroll: false});
|
current_msg_list.select_id(current_msg_list.last().id, {then_scroll: false});
|
||||||
unread_ops.mark_current_list_as_read();
|
unread_ops.mark_current_list_as_read();
|
||||||
} else {
|
} else {
|
||||||
ui.page_down_the_right_amount();
|
exports.page_down_the_right_amount();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -19,52 +19,6 @@ exports.home_tab_obscured = function () {
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
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);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.replace_emoji_with_text = function (element) {
|
exports.replace_emoji_with_text = function (element) {
|
||||||
element.find(".emoji").replaceWith(function () {
|
element.find(".emoji").replaceWith(function () {
|
||||||
return $(this).attr("alt");
|
return $(this).attr("alt");
|
||||||
|
|||||||
Reference in New Issue
Block a user