forked from starikovs/alt-checkbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.alt-checkbox.min.js
1 lines (1 loc) · 1.64 KB
/
jquery.alt-checkbox.min.js
1
(function(b){var a={init:function(c){var d=b.extend({iconClass:"fontawesome-ok",sizeClass:"medium",customClass:"",labelSameSize:true,outlineUnchecked:true},c);return this.hide().each(function(){var e=b(this),h=e.data("alt-checkbox");if(h){return}var i=b('<a href="#" class="alt-checkbox">').addClass(d.iconClass).addClass(d.sizeClass).addClass(d.customClass).addClass(d.outlineUnchecked?"outline-unchecked":"").insertBefore(e),f=e.attr("id"),g=b("[for='"+f+"']");if(d.labelSameSize){g.addClass("alt-checkbox-label").addClass(d.sizeClass)}e.data("alt-checkbox",{alt:i,label:g,labelSameSize:d.labelSameSize,sizeClass:d.sizeClass});i.bind("click.alt-checkbox",function(j){var k=b(this);if(k.hasClass("checked")){k.removeClass("checked");e.prop("checked",false)}else{k.addClass("checked");e.prop("checked",true)}j.preventDefault()}).bind("keyup.alt-checkbox",function(j){if(j.keyCode===32){b(this).click();j.preventDefault();j.stopPropagation()}}).bind("keydown.alt-checkbox",function(j){if(j.keyCode===32){j.preventDefault();j.stopPropagation()}});e.bind("change.alt-checkbox",function(){i.click()});i.addClass(e.is(":checked")?"checked":"")})},clear:function(){return this.each(function(){var c=b(this),d=c.data("alt-checkbox");if(!d){return}d.alt.unbind(".alt-checkbox").remove();c.unbind(".alt-checkbox");if(d.labelSameSize){d.label.removeClass(d.sizeClass).removeClass("alt-checkbox-label")}c.removeData("alt-checkbox")}).show()}};b.fn.altCheckbox=function(c){if(a[c]){return a[c].apply(this,Array.prototype.slice.call(arguments,1))}else{if(typeof c==="object"||!c){return a.init.apply(this,arguments)}else{b.error("Method "+c+" does not exist on jQuery.altCheckbox.")}}}})(jQuery);