Let CoffeeScript handle binding methods for us.

This commit is contained in:
Mayhem 2013-08-14 17:10:24 +02:00
parent 5924dbb4bb
commit 772e82aa60
4 changed files with 11 additions and 15 deletions

View File

@ -3,7 +3,7 @@ DataBoards = ['hiddenThreads', 'hiddenPosts', 'lastReadPosts', 'yourPosts', 'wat
class DataBoard
constructor: (@key, sync, dontClean) ->
@data = Conf[key]
$.sync key, @onSync.bind @
$.sync key, @onSync
@clean() unless dontClean
return unless sync
# Chrome also fires the onChanged callback on the current tab,
@ -84,6 +84,6 @@ class DataBoard
@deleteIfEmpty {boardID}
@save()
onSync: (data) ->
onSync: (data) =>
@data = data or boards: {}
@sync?()

View File

@ -1,8 +1,5 @@
class Notification
constructor: (type, content, @timeout) ->
@add = add.bind @
@close = close.bind @
@el = $.el 'div',
innerHTML: '<a href=javascript:; class=close title=Close>×</a><div class=message></div>'
@el.style.opacity = 0
@ -17,7 +14,7 @@ class Notification
setType: (type) ->
@el.className = "notification #{type}"
add = ->
add: =>
if d.hidden
$.on d, 'visibilitychange', @add
return
@ -27,5 +24,5 @@ class Notification
@el.style.opacity = 1
setTimeout @close, @timeout * $.SECOND if @timeout
close = ->
close: =>
$.rm @el

View File

@ -17,8 +17,7 @@ UI = do ->
constructor: (@type) ->
# Doc here: https://github.com/MayhemYDG/4chan-x/wiki/Menu-API
$.on d, 'AddMenuEntry', @addEntry.bind @
@close = close.bind @
$.on d, 'AddMenuEntry', @addEntry
@entries = []
makeMenu: ->
@ -27,7 +26,7 @@ UI = do ->
id: 'menu'
tabIndex: 0
$.on menu, 'click', (e) -> e.stopPropagation()
$.on menu, 'keydown', @keybinds.bind @
$.on menu, 'keydown', @keybinds
menu
toggle: (e, button, data) ->
@ -98,7 +97,7 @@ UI = do ->
$.add entry.el, submenu
return
close = ->
close: =>
$.rm currentMenu
currentMenu = null
lastToggledButton = null
@ -110,7 +109,7 @@ UI = do ->
+(first.style.order or first.style.webkitOrder) - +(second.style.order or second.style.webkitOrder)
entries[entries.indexOf(entry) + direction]
keybinds: (e) ->
keybinds: (e) =>
entry = $ '.focused', currentMenu
while subEntry = $ '.focused', entry
entry = subEntry
@ -167,7 +166,7 @@ UI = do ->
$.addClass submenu, 'right'
$.rmClass submenu, 'left'
addEntry: (e) ->
addEntry: (e) =>
entry = e.detail
return if entry.type isnt @type
@parseEntry entry

View File

@ -446,7 +446,7 @@ QR =
$.on elm, 'blur', QR.focusout
$.on elm, 'focus', QR.focusin
<% } %>
$.on el, 'click', @select.bind @
$.on el, 'click', @select
$.on @nodes.rm, 'click', (e) => e.stopPropagation(); @rm()
$.on @nodes.label, 'click', (e) => e.stopPropagation()
$.on @nodes.spoiler, 'change', (e) =>
@ -516,7 +516,7 @@ QR =
@nodes.el.draggable = !lock
unlock: ->
@lock false
select: ->
select: =>
if QR.selected
QR.selected.nodes.el.id = null
QR.selected.forceSave()