Skip to content

Commit

Permalink
added thread highlighting based on last update vs last view
Browse files Browse the repository at this point in the history
  • Loading branch information
silverweed committed Mar 19, 2015
1 parent f1fd458 commit 88131a1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
27 changes: 27 additions & 0 deletions static/src/coffee/threads.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
return unless window.localStorage?

if window.location.pathname[1...7] == 'thread'
# When a thread is visited, save the latest post date is localStorage.
# First, ensure this is the last page of the thread. If not, don't
# mark this thread as 'visited', since latest replies are not being
# actually seen.
pages = document.querySelector 'div.pages'
return unless pages.dataset.current == pages.dataset.max
# grab latest post
posts = document.getElementById('replies').querySelectorAll 'article.post'
latest = posts[posts.length-1]
date = latest.querySelector('a.date').dataset.udate
if date?
surl = window.location.pathname.split('/')[2]
window.localStorage.setItem "lview_#{surl}", date
else
# In home: for each thread, check if already viewed or not
window.fromList(document.querySelectorAll 'article.thread').map (thread) ->
# get last-modified date
date = thread.querySelector('span.date').dataset.udate
# compare with locally saved date, if any
surl = thread.querySelector('a').pathname.split('/')[2]
lview = window.localStorage.getItem("lview_#{surl}")
if lview? and lview == date
# no updates since latest visit
thread.querySelector('.thread-name').style.opacity = 0.7
1 change: 1 addition & 0 deletions template/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@
<script src="/static/js/posts.js"></script>
<script src="/static/js/complete.js"></script>
<script src="/static/js/hiding.js"></script>
<script src="/static/js/threads.js"></script>
</body>
</html>

0 comments on commit 88131a1

Please sign in to comment.