mirror of https://github.com/zulip/zulip.git
Move message_viewport_info() from ui.js to viewport.js
The message_viewport_info() function encapsulates our logic around the compose box and other elements blocking the viewport, so viewport.js seems like a more logical home for it. It also makes ui.js, one of our largest modules, a little bit smaller. (imported from commit 7838668b28175e161b87a6d7a8124b73012f0ff3)
This commit is contained in:
parent
29d0b923d1
commit
1cd113db10
|
@ -442,7 +442,7 @@ MessageList.prototype = {
|
|||
}
|
||||
|
||||
var selected_row_offset = selected_row.offset().top;
|
||||
var info = ui.message_viewport_info();
|
||||
var info = viewport.message_viewport_info();
|
||||
var available_space_for_scroll = selected_row_offset - info.visible_top;
|
||||
|
||||
// Don't scroll if we can't move the pointer up.
|
||||
|
|
|
@ -32,38 +32,11 @@ exports.focus_on = function (field_id) {
|
|||
$("#" + field_id).focus();
|
||||
};
|
||||
|
||||
exports.message_viewport_info = function () {
|
||||
// Return a structure that tells us details of the viewport
|
||||
// accounting for fixed elements like the top navbar.
|
||||
//
|
||||
// The message_header is NOT considered to be part of the visible
|
||||
// message pane, which should make sense for callers, who will
|
||||
// generally be concerned about whether actual message content is
|
||||
// visible.
|
||||
|
||||
var res = {};
|
||||
|
||||
var element_just_above_us = $("#tab_bar_underpadding");
|
||||
|
||||
res.visible_top =
|
||||
element_just_above_us.offset().top
|
||||
+ element_just_above_us.height()
|
||||
+ $(".message_header").height();
|
||||
|
||||
var element_just_below_us = $("#compose");
|
||||
|
||||
res.visible_height =
|
||||
element_just_below_us.offset().top
|
||||
- res.visible_top;
|
||||
|
||||
return res;
|
||||
};
|
||||
|
||||
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 = exports.message_viewport_info();
|
||||
var info = viewport.message_viewport_info();
|
||||
var page_size = info.visible_height;
|
||||
|
||||
// We don't want to page up a full page, because Humbug users
|
||||
|
|
|
@ -10,6 +10,33 @@ exports.at_top = function () {
|
|||
return (jwindow.scrollTop() <= 0);
|
||||
};
|
||||
|
||||
exports.message_viewport_info = function () {
|
||||
// Return a structure that tells us details of the viewport
|
||||
// accounting for fixed elements like the top navbar.
|
||||
//
|
||||
// The message_header is NOT considered to be part of the visible
|
||||
// message pane, which should make sense for callers, who will
|
||||
// generally be concerned about whether actual message content is
|
||||
// visible.
|
||||
|
||||
var res = {};
|
||||
|
||||
var element_just_above_us = $("#tab_bar_underpadding");
|
||||
|
||||
res.visible_top =
|
||||
element_just_above_us.offset().top
|
||||
+ element_just_above_us.height()
|
||||
+ $(".message_header").height();
|
||||
|
||||
var element_just_below_us = $("#compose");
|
||||
|
||||
res.visible_height =
|
||||
element_just_below_us.offset().top
|
||||
- res.visible_top;
|
||||
|
||||
return res;
|
||||
};
|
||||
|
||||
exports.at_bottom = function () {
|
||||
// outerHeight(true): Include margin
|
||||
var bottom = jwindow.scrollTop() + jwindow.height();
|
||||
|
@ -25,7 +52,7 @@ exports.at_bottom = function () {
|
|||
exports.set_message_position = function (message_top, message_height, viewport_info, ratio) {
|
||||
// message_top = offset of the top of a message that you are positioning
|
||||
// message_height = height of the message that you are positioning
|
||||
// viewport_info = result of calling ui.message_viewport_info
|
||||
// viewport_info = result of calling viewport.message_viewport_info
|
||||
// ratio = fraction indicating how far down the screen the msg should be
|
||||
|
||||
var how_far_down_in_visible_page = viewport_info.visible_height * ratio;
|
||||
|
|
|
@ -75,7 +75,7 @@ function within_viewport(row_offset, row_height) {
|
|||
// part of the viewport.
|
||||
var message_top = row_offset.top;
|
||||
var message_bottom = message_top + row_height;
|
||||
var info = ui.message_viewport_info();
|
||||
var info = viewport.message_viewport_info();
|
||||
var viewport_top = info.visible_top;
|
||||
var viewport_bottom = viewport_top + info.visible_height;
|
||||
return (message_top > viewport_top) && (message_bottom < viewport_bottom);
|
||||
|
@ -94,7 +94,7 @@ function keep_pointer_in_view() {
|
|||
if (next_row.length === 0)
|
||||
return;
|
||||
|
||||
var info = ui.message_viewport_info();
|
||||
var info = viewport.message_viewport_info();
|
||||
var top_threshold = info.visible_top + (1/10 * info.visible_height);
|
||||
var bottom_threshold = info.visible_top + (9/10 * info.visible_height);
|
||||
|
||||
|
@ -130,7 +130,7 @@ function recenter_view(message, from_scroll) {
|
|||
// the 1/2 marks. If the pointer is too low, move it to the 1/7 mark.
|
||||
// See keep_pointer_in_view() for related logic to keep the pointer onscreen.
|
||||
|
||||
var viewport_info = ui.message_viewport_info();
|
||||
var viewport_info = viewport.message_viewport_info();
|
||||
var top_threshold = viewport_info.visible_top;
|
||||
|
||||
var bottom_threshold = viewport_info.visible_top + viewport_info.visible_height;
|
||||
|
@ -342,7 +342,7 @@ function process_visible_unread_messages(update_cursor) {
|
|||
}
|
||||
|
||||
var selected = current_msg_list.selected_message();
|
||||
var vp = ui.message_viewport_info();
|
||||
var vp = viewport.message_viewport_info();
|
||||
var top = vp.visible_top;
|
||||
var height = vp.visible_height;
|
||||
|
||||
|
|
Loading…
Reference in New Issue