Get rid of ThreadWatcher.menu.refreshers hook and set menu content when menu is opened.
This commit is contained in:
parent
86909be300
commit
296457a79f
@ -445,9 +445,6 @@ ThreadWatcher =
|
|||||||
$.add list, nodes
|
$.add list, nodes
|
||||||
|
|
||||||
ThreadWatcher.refreshIcon()
|
ThreadWatcher.refreshIcon()
|
||||||
for refresher in ThreadWatcher.menu.refreshers
|
|
||||||
refresher()
|
|
||||||
return
|
|
||||||
|
|
||||||
refresh: ->
|
refresh: ->
|
||||||
ThreadWatcher.build()
|
ThreadWatcher.build()
|
||||||
@ -526,7 +523,6 @@ ThreadWatcher =
|
|||||||
ThreadWatcher.refresh()
|
ThreadWatcher.refresh()
|
||||||
|
|
||||||
menu:
|
menu:
|
||||||
refreshers: []
|
|
||||||
init: ->
|
init: ->
|
||||||
return if !Conf['Thread Watcher']
|
return if !Conf['Thread Watcher']
|
||||||
menu = @menu = new UI.Menu 'thread watcher'
|
menu = @menu = new UI.Menu 'thread watcher'
|
||||||
@ -541,15 +537,16 @@ ThreadWatcher =
|
|||||||
Header.menu.addEntry
|
Header.menu.addEntry
|
||||||
el: entryEl
|
el: entryEl
|
||||||
order: 60
|
order: 60
|
||||||
|
open: ->
|
||||||
|
[addClass, rmClass, text] = if !!ThreadWatcher.db.get {boardID: g.BOARD.ID, threadID: g.THREADID}
|
||||||
|
['unwatch-thread', 'watch-thread', 'Unwatch thread']
|
||||||
|
else
|
||||||
|
['watch-thread', 'unwatch-thread', 'Watch thread']
|
||||||
|
$.addClass entryEl, addClass
|
||||||
|
$.rmClass entryEl, rmClass
|
||||||
|
entryEl.textContent = text
|
||||||
|
true
|
||||||
$.on entryEl, 'click', -> ThreadWatcher.toggle g.threads["#{g.BOARD}.#{g.THREADID}"]
|
$.on entryEl, 'click', -> ThreadWatcher.toggle g.threads["#{g.BOARD}.#{g.THREADID}"]
|
||||||
@refreshers.push ->
|
|
||||||
[addClass, rmClass, text] = if $ '.current', ThreadWatcher.list
|
|
||||||
['unwatch-thread', 'watch-thread', 'Unwatch thread']
|
|
||||||
else
|
|
||||||
['watch-thread', 'unwatch-thread', 'Watch thread']
|
|
||||||
$.addClass entryEl, addClass
|
|
||||||
$.rmClass entryEl, rmClass
|
|
||||||
entryEl.textContent = text
|
|
||||||
|
|
||||||
addMenuEntries: ->
|
addMenuEntries: ->
|
||||||
entries = []
|
entries = []
|
||||||
@ -560,7 +557,9 @@ ThreadWatcher =
|
|||||||
entry:
|
entry:
|
||||||
el: $.el 'a',
|
el: $.el 'a',
|
||||||
textContent: 'Open all threads'
|
textContent: 'Open all threads'
|
||||||
refresh: -> (if ThreadWatcher.list.firstElementChild then $.rmClass else $.addClass) @el, 'disabled'
|
open: ->
|
||||||
|
@el.classList.toggle 'disabled', !ThreadWatcher.list.firstElementChild
|
||||||
|
true
|
||||||
|
|
||||||
# `Prune dead threads` entry
|
# `Prune dead threads` entry
|
||||||
entries.push
|
entries.push
|
||||||
@ -568,7 +567,9 @@ ThreadWatcher =
|
|||||||
entry:
|
entry:
|
||||||
el: $.el 'a',
|
el: $.el 'a',
|
||||||
textContent: 'Prune dead threads'
|
textContent: 'Prune dead threads'
|
||||||
refresh: -> (if $('.dead-thread', ThreadWatcher.list) then $.rmClass else $.addClass) @el, 'disabled'
|
open: ->
|
||||||
|
@el.classList.toggle 'disabled', !$('.dead-thread', ThreadWatcher.list)
|
||||||
|
true
|
||||||
|
|
||||||
# `Settings` entries:
|
# `Settings` entries:
|
||||||
subEntries = []
|
subEntries = []
|
||||||
@ -580,10 +581,10 @@ ThreadWatcher =
|
|||||||
textContent: 'Settings'
|
textContent: 'Settings'
|
||||||
subEntries: subEntries
|
subEntries: subEntries
|
||||||
|
|
||||||
for {entry, cb, refresh} in entries
|
for {entry, cb, open} in entries
|
||||||
entry.el.href = 'javascript:;' if entry.el.nodeName is 'A'
|
entry.el.href = 'javascript:;' if entry.el.nodeName is 'A'
|
||||||
$.on entry.el, 'click', cb if cb
|
$.on entry.el, 'click', cb if cb
|
||||||
@refreshers.push refresh.bind entry if refresh
|
entry.open = open.bind(entry) if open
|
||||||
@menu.addEntry entry
|
@menu.addEntry entry
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user