mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 15:03:34 +00:00
Cache the window selector as 'viewport' in an attempt to improve performance.
(imported from commit 3e01382260938737fbee663f6a9e94ad495ef21e)
This commit is contained in:
@@ -45,7 +45,7 @@ var globals =
|
|||||||
+ ' scroll_to_selected select_and_show_by_id'
|
+ ' scroll_to_selected select_and_show_by_id'
|
||||||
+ ' selected_message selected_message_id'
|
+ ' selected_message selected_message_id'
|
||||||
+ ' at_top_of_viewport at_bottom_of_viewport'
|
+ ' at_top_of_viewport at_bottom_of_viewport'
|
||||||
|
+ ' viewport'
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ function process_hotkey(code) {
|
|||||||
//
|
//
|
||||||
// FIXME: this doesn't work for End because get_last_visible()
|
// FIXME: this doesn't work for End because get_last_visible()
|
||||||
// always returns a message.
|
// always returns a message.
|
||||||
var viewport = $(window);
|
|
||||||
viewport.scrollTop($("#main_div").outerHeight(true));
|
viewport.scrollTop($("#main_div").outerHeight(true));
|
||||||
}
|
}
|
||||||
return process_hotkey;
|
return process_hotkey;
|
||||||
|
|||||||
@@ -72,7 +72,6 @@ function mousemove() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function resizehandler(e) {
|
function resizehandler(e) {
|
||||||
var viewport = $(window);
|
|
||||||
var sidebar = $("#sidebar");
|
var sidebar = $("#sidebar");
|
||||||
var sidebar_nav = $(".sidebar-nav");
|
var sidebar_nav = $(".sidebar-nav");
|
||||||
var composebox = $("#compose");
|
var composebox = $("#compose");
|
||||||
@@ -274,13 +273,11 @@ $(function () {
|
|||||||
|
|
||||||
$('#sidebar a[data-toggle="pill"]').on('show', function (e) {
|
$('#sidebar a[data-toggle="pill"]').on('show', function (e) {
|
||||||
// Save the position of our old tab away, before we switch
|
// Save the position of our old tab away, before we switch
|
||||||
var viewport = $(window);
|
|
||||||
var old_tab = $(e.relatedTarget).attr('href');
|
var old_tab = $(e.relatedTarget).attr('href');
|
||||||
scroll_positions[old_tab] = viewport.scrollTop();
|
scroll_positions[old_tab] = viewport.scrollTop();
|
||||||
});
|
});
|
||||||
$('#sidebar a[data-toggle="pill"]').on('shown', function (e) {
|
$('#sidebar a[data-toggle="pill"]').on('shown', function (e) {
|
||||||
// Right after we show the new tab, restore its old scroll position
|
// Right after we show the new tab, restore its old scroll position
|
||||||
var viewport = $(window);
|
|
||||||
var target_tab = $(e.target).attr('href');
|
var target_tab = $(e.target).attr('href');
|
||||||
if (scroll_positions.hasOwnProperty(target_tab)) {
|
if (scroll_positions.hasOwnProperty(target_tab)) {
|
||||||
viewport.scrollTop(scroll_positions[target_tab]);
|
viewport.scrollTop(scroll_positions[target_tab]);
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ var subject_dict = {};
|
|||||||
var people_hash = {};
|
var people_hash = {};
|
||||||
|
|
||||||
var selected_message_class = 'selected_message';
|
var selected_message_class = 'selected_message';
|
||||||
|
var viewport = $(window);
|
||||||
|
|
||||||
$(function () {
|
$(function () {
|
||||||
var i;
|
var i;
|
||||||
@@ -69,14 +70,12 @@ var message_groups = {
|
|||||||
function above_view_threshold(message) {
|
function above_view_threshold(message) {
|
||||||
// Barnowl-style thresholds: the pointer is never above the
|
// Barnowl-style thresholds: the pointer is never above the
|
||||||
// 1/5-mark.
|
// 1/5-mark.
|
||||||
var viewport = $(window);
|
|
||||||
return message.offset().top < viewport.scrollTop() + viewport.height() / 5;
|
return message.offset().top < viewport.scrollTop() + viewport.height() / 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
function below_view_threshold(message) {
|
function below_view_threshold(message) {
|
||||||
// Barnowl-style thresholds: the pointer is never below the
|
// Barnowl-style thresholds: the pointer is never below the
|
||||||
// 4/5-mark.
|
// 4/5-mark.
|
||||||
var viewport = $(window);
|
|
||||||
return message.offset().top + message.outerHeight(true) >
|
return message.offset().top + message.outerHeight(true) >
|
||||||
viewport.scrollTop() + viewport.height() * 4 / 5;
|
viewport.scrollTop() + viewport.height() * 4 / 5;
|
||||||
}
|
}
|
||||||
@@ -88,7 +87,6 @@ function recenter_view(message) {
|
|||||||
|
|
||||||
// If this logic changes, above_view_threshold andd
|
// If this logic changes, above_view_threshold andd
|
||||||
// below_view_threshold must also change.
|
// below_view_threshold must also change.
|
||||||
var viewport = $(window);
|
|
||||||
if (above_view_threshold(message)) {
|
if (above_view_threshold(message)) {
|
||||||
viewport.scrollTop(selected_message.offset().top - viewport.height() / 2);
|
viewport.scrollTop(selected_message.offset().top - viewport.height() / 2);
|
||||||
} else if (below_view_threshold(message)) {
|
} else if (below_view_threshold(message)) {
|
||||||
@@ -189,7 +187,6 @@ function update_selected_message(message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function select_message(next_message, scroll_to) {
|
function select_message(next_message, scroll_to) {
|
||||||
var viewport = $(window);
|
|
||||||
|
|
||||||
/* If the message exists but is hidden, try to find the next visible one. */
|
/* If the message exists but is hidden, try to find the next visible one. */
|
||||||
if (next_message.length !== 0 && next_message.is(':hidden')) {
|
if (next_message.length !== 0 && next_message.is(':hidden')) {
|
||||||
@@ -539,17 +536,15 @@ setInterval(function() {
|
|||||||
}, 5000);
|
}, 5000);
|
||||||
|
|
||||||
function at_top_of_viewport() {
|
function at_top_of_viewport() {
|
||||||
return ($(window).scrollTop() === 0);
|
return (viewport.scrollTop() === 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
function at_bottom_of_viewport() {
|
function at_bottom_of_viewport() {
|
||||||
var viewport = $(window);
|
|
||||||
return (viewport.scrollTop() + viewport.height() >= $("#main_div").outerHeight(true));
|
return (viewport.scrollTop() + viewport.height() >= $("#main_div").outerHeight(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
function keep_pointer_in_view() {
|
function keep_pointer_in_view() {
|
||||||
var candidate;
|
var candidate;
|
||||||
var viewport = $(window);
|
|
||||||
var next_message = get_message_row(selected_message_id);
|
var next_message = get_message_row(selected_message_id);
|
||||||
|
|
||||||
if (above_view_threshold(next_message) && (!at_top_of_viewport())) {
|
if (above_view_threshold(next_message) && (!at_top_of_viewport())) {
|
||||||
|
|||||||
Reference in New Issue
Block a user