More thoughtful unread-scroll code.

This commit is contained in:
Mayhem 2013-07-08 23:40:48 +02:00
parent e16fefb31f
commit 7d38f0502c

View File

@ -37,13 +37,11 @@ Unread =
# Let the header's onload callback handle it. # Let the header's onload callback handle it.
return if (hash = location.hash.match /\d+/) and hash[0] of Unread.thread.posts return if (hash = location.hash.match /\d+/) and hash[0] of Unread.thread.posts
if Unread.posts.length if Unread.posts.length
# Scroll to before the first unread post. # Scroll to a non-hidden, non-OP post that's before the first unread post.
{root} = Unread.posts[0].nodes post = Unread.posts[0]
while root = $.x 'preceding-sibling::div[contains(@class,"postContainer")][1]', root while root = $.x 'preceding-sibling::div[contains(@class,"replyContainer")][1]', post.nodes.root
post = Get.postFromRoot root break unless (post = Get.postFromRoot root).isHidden
# Don't scroll if we have 0 posts read in this thread. return unless root
return unless post.isReply
break unless post.isHidden
onload = -> root.scrollIntoView false if checkPosition root onload = -> root.scrollIntoView false if checkPosition root
else else
# Scroll to the last read post. # Scroll to the last read post.