Skip to content

Instantly share code, notes, and snippets.

@thejh
Created August 4, 2011 00:14
Show Gist options
  • Save thejh/1124214 to your computer and use it in GitHub Desktop.
Save thejh/1124214 to your computer and use it in GitHub Desktop.
Creating UI Element handlers
buttons =
dismissBtnClass: ".dismiss.btn"
selectBtnClass: ".select.btn"
normalBtnClass: ".normal.btn"
toggleBtnClass: ".toggle.btn"
buttons.bind = ->
bindDismissButtons()
bindSelectButtons()
bindNormalButtons()
bindToggleButtons()
bindDismissButtons = ->
$(this.dismissBtnClass).live 'click', ->
$(this).remove()
bindSelectButtons = ->
$(this.selectBtnClass).live 'click', ->
$(this).siblings().removeClass("selected")
$(this).addClass("selected")
bindNormalButtons = ->
$(this.normalBtnClass).live 'mousedown', ->
$(this).addClass("selected")
$(this.normalBtnClass).live 'mouseup', ->
$(this).removeClass("selected")
$(this.normalBtnClass).live 'mouseleave', ->
$(this).removeClass("selected")
bindToggleButtons = ->
$(this.toggleBtnClass).live 'click', ->
$(this).toggleClass("selected")
window.buttons = buttons
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment