Add hidden threads count on the index.

This commit is contained in:
Mayhem 2014-02-01 19:48:37 +01:00
parent c5490f6aec
commit 0092c53783

View File

@ -24,7 +24,29 @@ ThreadHiding =
else unless root.contains thread.stub
# When we come back to a page, the stub is already there.
ThreadHiding.makeStub thread, root
return
ThreadHiding.updateToggle()
updateToggle: ->
hiddenCount = 0
for threadID, thread of g.BOARD.threads when thread.isHidden
hiddenCount++ if thread.ID in Index.liveThreadIDs
unless hiddenCount
ThreadHiding.removeToggle()
return
unless ThreadHiding.toggler
ThreadHiding.addToggle()
$('#hidden-count', Index.navLinks).textContent = if hiddenCount is 1
'1 hidden thread'
else
"#{hiddenCount} hidden threads"
addToggle: ->
ThreadHiding.toggler = $.el 'span',
id: 'hidden-label'
innerHTML: ' &mdash; <span id="hidden-count"></span>'
$.add Index.navLinks, ThreadHiding.toggler
removeToggle: ->
return unless ThreadHiding.toggler
$.rm ThreadHiding.toggler
delete ThreadHiding.toggler
syncCatalog: ->
# Sync hidden threads from the catalog into the index.
@ -157,6 +179,7 @@ ThreadHiding =
return if thread.isHidden
threadRoot = thread.OP.nodes.root.parentNode
thread.isHidden = true
ThreadHiding.updateToggle()
unless makeStub
threadRoot.hidden = threadRoot.nextElementSibling.hidden = true # <hr>
@ -171,3 +194,4 @@ ThreadHiding =
threadRoot = thread.OP.nodes.root.parentNode
threadRoot.nextElementSibling.hidden =
threadRoot.hidden = thread.isHidden = false
ThreadHiding.updateToggle()