Let CoffeeScript handle binding methods for us.
This commit is contained in:
parent
5924dbb4bb
commit
772e82aa60
@ -3,7 +3,7 @@ DataBoards = ['hiddenThreads', 'hiddenPosts', 'lastReadPosts', 'yourPosts', 'wat
|
|||||||
class DataBoard
|
class DataBoard
|
||||||
constructor: (@key, sync, dontClean) ->
|
constructor: (@key, sync, dontClean) ->
|
||||||
@data = Conf[key]
|
@data = Conf[key]
|
||||||
$.sync key, @onSync.bind @
|
$.sync key, @onSync
|
||||||
@clean() unless dontClean
|
@clean() unless dontClean
|
||||||
return unless sync
|
return unless sync
|
||||||
# Chrome also fires the onChanged callback on the current tab,
|
# Chrome also fires the onChanged callback on the current tab,
|
||||||
@ -84,6 +84,6 @@ class DataBoard
|
|||||||
@deleteIfEmpty {boardID}
|
@deleteIfEmpty {boardID}
|
||||||
@save()
|
@save()
|
||||||
|
|
||||||
onSync: (data) ->
|
onSync: (data) =>
|
||||||
@data = data or boards: {}
|
@data = data or boards: {}
|
||||||
@sync?()
|
@sync?()
|
||||||
|
|||||||
@ -1,8 +1,5 @@
|
|||||||
class Notification
|
class Notification
|
||||||
constructor: (type, content, @timeout) ->
|
constructor: (type, content, @timeout) ->
|
||||||
@add = add.bind @
|
|
||||||
@close = close.bind @
|
|
||||||
|
|
||||||
@el = $.el 'div',
|
@el = $.el 'div',
|
||||||
innerHTML: '<a href=javascript:; class=close title=Close>×</a><div class=message></div>'
|
innerHTML: '<a href=javascript:; class=close title=Close>×</a><div class=message></div>'
|
||||||
@el.style.opacity = 0
|
@el.style.opacity = 0
|
||||||
@ -17,7 +14,7 @@ class Notification
|
|||||||
setType: (type) ->
|
setType: (type) ->
|
||||||
@el.className = "notification #{type}"
|
@el.className = "notification #{type}"
|
||||||
|
|
||||||
add = ->
|
add: =>
|
||||||
if d.hidden
|
if d.hidden
|
||||||
$.on d, 'visibilitychange', @add
|
$.on d, 'visibilitychange', @add
|
||||||
return
|
return
|
||||||
@ -27,5 +24,5 @@ class Notification
|
|||||||
@el.style.opacity = 1
|
@el.style.opacity = 1
|
||||||
setTimeout @close, @timeout * $.SECOND if @timeout
|
setTimeout @close, @timeout * $.SECOND if @timeout
|
||||||
|
|
||||||
close = ->
|
close: =>
|
||||||
$.rm @el
|
$.rm @el
|
||||||
|
|||||||
@ -17,8 +17,7 @@ UI = do ->
|
|||||||
|
|
||||||
constructor: (@type) ->
|
constructor: (@type) ->
|
||||||
# Doc here: https://github.com/MayhemYDG/4chan-x/wiki/Menu-API
|
# Doc here: https://github.com/MayhemYDG/4chan-x/wiki/Menu-API
|
||||||
$.on d, 'AddMenuEntry', @addEntry.bind @
|
$.on d, 'AddMenuEntry', @addEntry
|
||||||
@close = close.bind @
|
|
||||||
@entries = []
|
@entries = []
|
||||||
|
|
||||||
makeMenu: ->
|
makeMenu: ->
|
||||||
@ -27,7 +26,7 @@ UI = do ->
|
|||||||
id: 'menu'
|
id: 'menu'
|
||||||
tabIndex: 0
|
tabIndex: 0
|
||||||
$.on menu, 'click', (e) -> e.stopPropagation()
|
$.on menu, 'click', (e) -> e.stopPropagation()
|
||||||
$.on menu, 'keydown', @keybinds.bind @
|
$.on menu, 'keydown', @keybinds
|
||||||
menu
|
menu
|
||||||
|
|
||||||
toggle: (e, button, data) ->
|
toggle: (e, button, data) ->
|
||||||
@ -98,7 +97,7 @@ UI = do ->
|
|||||||
$.add entry.el, submenu
|
$.add entry.el, submenu
|
||||||
return
|
return
|
||||||
|
|
||||||
close = ->
|
close: =>
|
||||||
$.rm currentMenu
|
$.rm currentMenu
|
||||||
currentMenu = null
|
currentMenu = null
|
||||||
lastToggledButton = null
|
lastToggledButton = null
|
||||||
@ -110,7 +109,7 @@ UI = do ->
|
|||||||
+(first.style.order or first.style.webkitOrder) - +(second.style.order or second.style.webkitOrder)
|
+(first.style.order or first.style.webkitOrder) - +(second.style.order or second.style.webkitOrder)
|
||||||
entries[entries.indexOf(entry) + direction]
|
entries[entries.indexOf(entry) + direction]
|
||||||
|
|
||||||
keybinds: (e) ->
|
keybinds: (e) =>
|
||||||
entry = $ '.focused', currentMenu
|
entry = $ '.focused', currentMenu
|
||||||
while subEntry = $ '.focused', entry
|
while subEntry = $ '.focused', entry
|
||||||
entry = subEntry
|
entry = subEntry
|
||||||
@ -167,7 +166,7 @@ UI = do ->
|
|||||||
$.addClass submenu, 'right'
|
$.addClass submenu, 'right'
|
||||||
$.rmClass submenu, 'left'
|
$.rmClass submenu, 'left'
|
||||||
|
|
||||||
addEntry: (e) ->
|
addEntry: (e) =>
|
||||||
entry = e.detail
|
entry = e.detail
|
||||||
return if entry.type isnt @type
|
return if entry.type isnt @type
|
||||||
@parseEntry entry
|
@parseEntry entry
|
||||||
|
|||||||
@ -446,7 +446,7 @@ QR =
|
|||||||
$.on elm, 'blur', QR.focusout
|
$.on elm, 'blur', QR.focusout
|
||||||
$.on elm, 'focus', QR.focusin
|
$.on elm, 'focus', QR.focusin
|
||||||
<% } %>
|
<% } %>
|
||||||
$.on el, 'click', @select.bind @
|
$.on el, 'click', @select
|
||||||
$.on @nodes.rm, 'click', (e) => e.stopPropagation(); @rm()
|
$.on @nodes.rm, 'click', (e) => e.stopPropagation(); @rm()
|
||||||
$.on @nodes.label, 'click', (e) => e.stopPropagation()
|
$.on @nodes.label, 'click', (e) => e.stopPropagation()
|
||||||
$.on @nodes.spoiler, 'change', (e) =>
|
$.on @nodes.spoiler, 'change', (e) =>
|
||||||
@ -516,7 +516,7 @@ QR =
|
|||||||
@nodes.el.draggable = !lock
|
@nodes.el.draggable = !lock
|
||||||
unlock: ->
|
unlock: ->
|
||||||
@lock false
|
@lock false
|
||||||
select: ->
|
select: =>
|
||||||
if QR.selected
|
if QR.selected
|
||||||
QR.selected.nodes.el.id = null
|
QR.selected.nodes.el.id = null
|
||||||
QR.selected.forceSave()
|
QR.selected.forceSave()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user