From 90e40e11e750223941540a3435ad9cde4f5b92fe Mon Sep 17 00:00:00 2001 From: Mayhem Date: Fri, 31 May 2013 21:20:16 +0200 Subject: [PATCH] Fix #1131. --- src/Monitoring/Unread.coffee | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Monitoring/Unread.coffee b/src/Monitoring/Unread.coffee index a951be09a..b381a4441 100644 --- a/src/Monitoring/Unread.coffee +++ b/src/Monitoring/Unread.coffee @@ -44,12 +44,18 @@ Unread = break if prevID is post.ID prevID = post.ID break unless post.isHidden - onload = -> root.scrollIntoView false + onload = -> root.scrollIntoView false if checkPosition root else # Scroll to the last read post. - posts = Object.keys Unread.thread.posts - post = Unread.thread.posts[posts[posts.length - 1]] - onload = -> Header.scrollToPost post.nodes.root + posts = Object.keys Unread.thread.posts + {root} = Unread.thread.posts[posts[posts.length - 1]].nodes + 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 # the previous scroll location on page load. $.on window, 'load', onload @@ -66,8 +72,8 @@ Unread = Unread.setLine() Unread.update() - addPosts: (newPosts) -> - for post in newPosts + addPosts: (posts) -> + for post in posts {ID} = post if ID <= Unread.lastReadPost or post.isHidden continue @@ -81,7 +87,7 @@ Unread = Unread.addPostQuotingYou post if Conf['Unread Line'] # 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.update()