Skip to content

Instantly share code, notes, and snippets.

@togakangaroo
Created July 18, 2012 00:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save togakangaroo/3133127 to your computer and use it in GitHub Desktop.
Save togakangaroo/3133127 to your computer and use it in GitHub Desktop.
A very simple pretty checkbox plugin
$.widget 'someApp.prettyCheckbox',
_create: ->
if not @element.is ':checkbox'
return console.error "Expect widget to be called on a checkbox element", this, this.element
@wrapper = $('<div class=prettyCheckbox-wrapper>')
.css(position: 'relative', display: 'inline-block')
@element
.css(padding: 0, border: 0, opacity: 0, position: 'absolute', left: 0, top: 0)
@prettyBox = $('<div class=prettyCheckbox>')
.css('z-index': -10, display: 'inline-block')
@element.wrap @wrapper
@element.after @prettyBox
@element.width(@prettyBox.width()).height @prettyBox.height()
@element.change => @prettyBox.toggleClass 'prettyCheckbox-checked', @element.prop 'checked'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment