This commit is contained in:
Mayhem 2013-05-31 21:20:16 +02:00
parent cbd00356d8
commit 90e40e11e7

View File

@ -44,12 +44,18 @@ Unread =
break if prevID is post.ID break if prevID is post.ID
prevID = post.ID prevID = post.ID
break unless post.isHidden break unless post.isHidden
onload = -> root.scrollIntoView false onload = -> root.scrollIntoView false if checkPosition root
else else
# Scroll to the last read post. # Scroll to the last read post.
posts = Object.keys Unread.thread.posts posts = Object.keys Unread.thread.posts
post = Unread.thread.posts[posts[posts.length - 1]] {root} = Unread.thread.posts[posts[posts.length - 1]].nodes
onload = -> Header.scrollToPost post.nodes.root onload = -> Header.scrollToPost root if checkPosition root
checkPosition = (target) ->
# Don't scroll to the target if
# - it's visible.
# - we've scrolled past it.
{top, height} = target.getBoundingClientRect()
top + height - doc.clientHeight > 0
# Prevent the browser to scroll back to # Prevent the browser to scroll back to
# the previous scroll location on page load. # the previous scroll location on page load.
$.on window, 'load', onload $.on window, 'load', onload
@ -66,8 +72,8 @@ Unread =
Unread.setLine() Unread.setLine()
Unread.update() Unread.update()
addPosts: (newPosts) -> addPosts: (posts) ->
for post in newPosts for post in posts
{ID} = post {ID} = post
if ID <= Unread.lastReadPost or post.isHidden if ID <= Unread.lastReadPost or post.isHidden
continue continue
@ -81,7 +87,7 @@ Unread =
Unread.addPostQuotingYou post Unread.addPostQuotingYou post
if Conf['Unread Line'] if Conf['Unread Line']
# Force line on visible threads if there were no unread posts previously. # Force line on visible threads if there were no unread posts previously.
Unread.setLine Unread.posts[0] in newPosts Unread.setLine Unread.posts[0] in posts
Unread.read() Unread.read()
Unread.update() Unread.update()