From 975b984aee7c20cdd4b93bd7d748f3ad1f99c74d Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Tue, 28 May 2013 16:36:48 -0400 Subject: [PATCH] Slow down pointer adjustments at the bottom of the messages. The main point of this fix is to move some more scroll-related code into viewport.js, but it also fixes a bug where the size of #main_div was not accurately representing the full height of the message list. Making the calculation more accurate narrows the window where we do pointer adjustements on mousewheel moves. (imported from commit 5d821f459284c4dbd5ff8056001e54caf4355f1d) --- zephyr/static/js/hotkey.js | 4 ++-- zephyr/static/js/viewport.js | 12 ++++++++++++ zephyr/static/js/zephyr.js | 15 +++------------ 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/zephyr/static/js/hotkey.js b/zephyr/static/js/hotkey.js index 8fac78db69..1621aaff93 100644 --- a/zephyr/static/js/hotkey.js +++ b/zephyr/static/js/hotkey.js @@ -151,7 +151,7 @@ function process_hotkey(e) { switch (code) { case 33: // Page Up - if (at_top_of_viewport() && !current_msg_list.empty()) { + if (viewport.at_top() && !current_msg_list.empty()) { current_msg_list.select_id(current_msg_list.first().id, {then_scroll: false}); } else { @@ -160,7 +160,7 @@ function process_hotkey(e) { return true; case 32: // Spacebar case 34: // Page Down - if (at_bottom_of_viewport() && !current_msg_list.empty()) { + if (viewport.at_bottom() && !current_msg_list.empty()) { current_msg_list.select_id(current_msg_list.last().id, {then_scroll: false}); } else { diff --git a/zephyr/static/js/viewport.js b/zephyr/static/js/viewport.js index c04d821f3c..c1e66b37fa 100644 --- a/zephyr/static/js/viewport.js +++ b/zephyr/static/js/viewport.js @@ -6,6 +6,18 @@ var height; var width; var in_stoppable_autoscroll = false; +exports.at_top = function () { + return (jwindow.scrollTop() <= 0); +}; + +exports.at_bottom = function () { + // outerHeight(true): Include margin + var bottom = jwindow.scrollTop() + jwindow.height(); + var window_size = $(document).height(); + + return bottom >= window_size; +}; + exports.scrollTop = function viewport_scrollTop () { return jwindow.scrollTop.apply(jwindow, arguments); }; diff --git a/zephyr/static/js/zephyr.js b/zephyr/static/js/zephyr.js index d219c3825f..1bd9f1d9d5 100644 --- a/zephyr/static/js/zephyr.js +++ b/zephyr/static/js/zephyr.js @@ -1120,15 +1120,6 @@ setInterval(function () { watchdog_time = new_time; }, 5000); -function at_top_of_viewport() { - return (viewport.scrollTop() === 0); -} - -function at_bottom_of_viewport() { - // outerHeight(true): Include margin - return (viewport.scrollTop() + viewport.height() >= $("#main_div").outerHeight(true)); -} - function keep_pointer_in_view() { var candidate; var next_row = current_msg_list.selected_row(); @@ -1152,8 +1143,8 @@ function keep_pointer_in_view() { return true; } - if (! adjust(above_view_threshold, at_top_of_viewport, rows.next_visible)) - adjust(below_view_threshold, at_bottom_of_viewport, rows.prev_visible); + if (! adjust(above_view_threshold, viewport.at_top, rows.next_visible)) + adjust(below_view_threshold, viewport.at_bottom, rows.prev_visible); current_msg_list.select_id(rows.id(next_row), {from_scroll: true}); } @@ -1164,7 +1155,7 @@ function keep_pointer_in_view() { // the scrollwheel, the selection should advance until // I'm at the very top or the very bottom of the page. function move_pointer_at_page_top_and_bottom(delta) { - if (delta !== 0 && (at_top_of_viewport() || at_bottom_of_viewport())) { + if (delta !== 0 && (viewport.at_top() || viewport.at_bottom())) { var next_row = current_msg_list.selected_row(); if (delta > 0) { // Scrolling up (want older messages)