Created
July 18, 2012 00:16
-
-
Save togakangaroo/3133127 to your computer and use it in GitHub Desktop.
A very simple pretty checkbox plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.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