Last active
December 15, 2015 23:50
-
-
Save dux/5343545 to your computer and use it in GitHub Desktop.
labels checkboxes and gives them state, jquery plugin
This file contains hidden or 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
# plugin cheeckbox label state | |
window.checkboxLabel_do = (el, on_, off_) -> | |
if el.is(":checked") then el.next().html(on_).css({color:'#080'}) else el.next().html(off_).css({color:'#800'}) | |
$.fn.checkboxLabel = (on_, off_) -> | |
on_ ||= "ON" | |
off_ ||= "OFF" | |
@each -> | |
el = $(this) | |
el_id = "cbs_" + (parseInt(Math.random() * 100000000000)) | |
el.attr('id', el_id) | |
el.after """ <label for="#{el_id}" style="display:inline; cursor:pointer;"></label>""" | |
el.click -> | |
checkboxLabel_do el, on_, off_ | |
checkboxLabel_do el, on_, off_ | |
$ -> | |
# %input{ :labeled=>'green|red', :type=>:checkbox, :onclick=>'', :checked=>true } | |
$('input[data-labeled]').each -> | |
el = $(this) | |
val = el.attr('data-labeled').split('\|') | |
el.checkboxLabel(val[0], val[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment