From a710bdf8b4b6d7b234456546867f882905d1710e Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sat, 22 Nov 2014 17:12:57 -0800 Subject: [PATCH] Better Unread.scroll code. --- src/Monitoring/Unread.coffee | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/Monitoring/Unread.coffee b/src/Monitoring/Unread.coffee index ee8bc1d7f..7f32df8d1 100755 --- a/src/Monitoring/Unread.coffee +++ b/src/Monitoring/Unread.coffee @@ -44,20 +44,15 @@ Unread = scroll: -> # Let the header's onload callback handle it. return if (hash = location.hash.match /\d+/) and hash[0] of Unread.thread.posts - if post = Unread.posts.first - # Scroll to a non-hidden, non-OP post that's before the first unread post. - while root = $.x 'preceding-sibling::div[contains(@class,"replyContainer")][1]', post.data.nodes.root - break unless (post = Get.postFromRoot root).isHidden - return unless root - down = true - else - # Scroll to the last read post. - {posts} = Unread.thread - {keys} = posts - {root} = posts[keys[keys.length - 1]].nodes - # Scroll to the target unless we scrolled past it. - Header.scrollTo root, down if Header.getBottomOf(root) < 0 + # Scroll to the last non-hidden non-deleted read post. + post = null + {posts} = Unread.thread + for ID in posts.keys + break if +ID > Unread.lastReadPost + post = posts[ID] unless posts[ID].isHidden + if post + Header.scrollToIfNeeded post.nodes.root, true sync: -> return unless Unread.lastReadPost?