mirror of https://github.com/zulip/zulip.git
Make within_viewport take the row offset and row height
The .height() and .width() functions are actually pretty expensive for the number of times we call them. The callers of within_viewport already know the offset and height of the row, so we just pass them in so the values don't have to be recalculated. (imported from commit d1c077bd87463d695f0bbe337b6a8b04ac2d17ce)
This commit is contained in:
parent
02dc15f426
commit
4de79cf723
|
@ -419,7 +419,10 @@ MessageList.prototype = {
|
|||
}
|
||||
|
||||
var selected_row = current_msg_list.selected_row();
|
||||
if (within_viewport(rows.last_visible()) && selected_row && (selected_row.length > 0)) {
|
||||
var last_visible = rows.last_visible();
|
||||
if (within_viewport(last_visible.offset(), last_visible.height())
|
||||
&& selected_row && (selected_row.length > 0))
|
||||
{
|
||||
var viewport_offset = viewport.scrollTop();
|
||||
var new_messages_height = 0;
|
||||
|
||||
|
|
|
@ -67,10 +67,10 @@ $(function () {
|
|||
|
||||
});
|
||||
|
||||
function within_viewport(message_row) {
|
||||
function within_viewport(row_offset, row_height) {
|
||||
// Returns true if a message is fully within the viewport.
|
||||
var message_top = message_row.offset().top;
|
||||
var message_bottom = message_top + message_row.height();
|
||||
var message_top = row_offset.top;
|
||||
var message_bottom = message_top + row_height;
|
||||
var viewport_top = viewport.scrollTop();
|
||||
var viewport_bottom = viewport_top + viewport.height();
|
||||
return (message_top > viewport_top) && (message_bottom < viewport_bottom);
|
||||
|
@ -408,8 +408,10 @@ function process_visible_unread_messages() {
|
|||
|
||||
var visible_messages = candidates.filter(function (idx, message) {
|
||||
var row = $(message);
|
||||
var row_offset = row.offset();
|
||||
var row_height = row.height();
|
||||
// Mark very tall messages as read once we've gotten past them
|
||||
return (row.height() > height && row.offset().top > top) || within_viewport(row);
|
||||
return (row_height > height && row_offset.top > top) || within_viewport(row_offset, row_height);
|
||||
});
|
||||
|
||||
var mark_as_read = $.map(visible_messages, function(msg) {
|
||||
|
|
Loading…
Reference in New Issue