From 1cd113db10295d52fa2851c5c8cba2c3f1094c31 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Thu, 6 Jun 2013 10:10:12 -0400 Subject: [PATCH] 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) --- zephyr/static/js/message_list.js | 2 +- zephyr/static/js/ui.js | 29 +---------------------------- zephyr/static/js/viewport.js | 29 ++++++++++++++++++++++++++++- zephyr/static/js/zephyr.js | 8 ++++---- 4 files changed, 34 insertions(+), 34 deletions(-) diff --git a/zephyr/static/js/message_list.js b/zephyr/static/js/message_list.js index 80a27da788..89e5a5c2de 100644 --- a/zephyr/static/js/message_list.js +++ b/zephyr/static/js/message_list.js @@ -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. diff --git a/zephyr/static/js/ui.js b/zephyr/static/js/ui.js index 6220c1b961..a3168b8ddb 100644 --- a/zephyr/static/js/ui.js +++ b/zephyr/static/js/ui.js @@ -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 diff --git a/zephyr/static/js/viewport.js b/zephyr/static/js/viewport.js index 41e9ade5f8..f7a4353a06 100644 --- a/zephyr/static/js/viewport.js +++ b/zephyr/static/js/viewport.js @@ -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; diff --git a/zephyr/static/js/zephyr.js b/zephyr/static/js/zephyr.js index 6283aadb8a..ac27bd6521 100644 --- a/zephyr/static/js/zephyr.js +++ b/zephyr/static/js/zephyr.js @@ -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;