|
|
!function(a,b,c,d){"use strict";a.fn.checkbox=function(b){var c,e=a(this),f=e.selector||"",g=(new Date).getTime(),h=[],i=arguments[0],j="string"==typeof i,k=[].slice.call(arguments,1);return e.each(function(){var e,l,m=a.extend(!0,{},a.fn.checkbox.settings,b),n=m.className,o=m.namespace,p=m.selector,q=m.error,r="."+o,s="module-"+o,t=a(this),u=a(this).next(p.label).first(),v=a(this).find(p.input),w=t.data(s),x=this;l={initialize:function(){l.verbose("Initializing checkbox",m),t.on("click"+r,l.toggle).on("keydown"+r,p.input,l.event.keydown),l.is.checked()?(l.set.checked(),m.fireOnInit&&a.proxy(m.onChecked,v.get())()):(l.remove.checked(),m.fireOnInit&&a.proxy(m.onUnchecked,v.get())()),l.observeChanges(),l.instantiate()},instantiate:function(){l.verbose("Storing instance of module",l),w=l,t.data(s,l)},destroy:function(){l.verbose("Destroying previous module"),t.off(r).removeData(s),v.off(r,l.event.keydown),u.off(r)},refresh:function(){t=a(this),u=a(this).next(p.label).first(),v=a(this).find(p.input)},observeChanges:function(){MutationObserver!==d&&(e=new MutationObserver(function(){l.debug("DOM tree modified, updating selector cache"),l.refresh()}),e.observe(x,{childList:!0,subtree:!0}),l.debug("Setting up mutation observer",e))},attachEvents:function(b,c){var d=a(b);c=a.isFunction(l[c])?l[c]:l.toggle,d.size()>0?(l.debug("Attaching checkbox events to element",b,c),d.on("click"+r,c)):l.error(q.notFound)},event:{keydown:function(b){var c=b.which,d={enter:13,escape:27};c==d.escape&&(l.verbose("Escape key pressed blurring field"),t.blur()),b.ctrlKey||c!=d.enter||(l.verbose("Enter key pressed, toggling checkbox"),a.proxy(l.toggle,this)(),b.preventDefault())}},is:{radio:function(){return t.hasClass(n.radio)},checked:function(){return v.prop("checked")!==d&&v.prop("checked")},unchecked:function(){return!l.is.checked()}},can:{change:function(){return!(t.hasClass(n.disabled)||t.hasClass(n.readOnly)||v.prop("disabled"))},uncheck:function(){return"boolean"==typeof m.uncheckable?m.uncheckable:!l.is.radio()}},set:{checked:function(){t.addClass(n.checked)}},remove:{checked:function(){t.removeClass(n.checked)}},disable:function(){l.debug("Enabling checkbox functionality"),t.addClass(n.disabled),v.removeProp("disabled"),a.proxy(m.onDisabled,v.get())()},enable:function(){l.debug("Disabling checkbox functionality"),t.removeClass(n.disabled),v.prop("disabled","disabled"),a.proxy(m.onEnabled,v.get())()},check:function(){l.debug("Enabling checkbox",v),v.prop("checked",!0).trigger("change"),l.set.checked(),a.proxy(m.onChange,v.get())(),a.proxy(m.onChecked,v.get())()},uncheck:function(){l.debug("Disabling checkbox"),v.prop("checked",!1).trigger("change"),l.remove.checked(),a.proxy(m.onChange,v.get())(),a.proxy(m.onUnchecked,v.get())()},toggle:function(){return l.can.change()?(l.verbose("Determining new checkbox state"),void(l.is.unchecked()?l.check():l.is.checked()&&l.can.uncheck()&&l.uncheck())):(console.log(l.can.change()),void l.debug("Checkbox is read-only or disabled, ignoring toggle"))},setting:function(b,c){if(l.debug("Changing setting",b,c),a.isPlainObject(b))a.extend(!0,m,b);else{if(c===d)return m[b];m[b]=c}},internal:function(b,c){if(a.isPlainObject(b))a.extend(!0,l,b);else{if(c===d)return l[b];l[b]=c}},debug:function(){m.debug&&(m.performance?l.performance.log(arguments):(l.debug=Function.prototype.bind.call(console.info,console,m.name+":"),l.debug.apply(console,arguments)))},verbose:function(){m.verbose&&m.debug&&(m.performance?l.performance.log(arguments):(l.verbose=Function.prototype.bind.call(console.info,console,m.name+":"),l.verbose.apply(console,arguments)))},error:function(){l.error=Function.prototype.bind.call(console.error,console,m.name+":"),l.error.apply(console,arguments)},performance:{log:function(a){var b,c,d;m.performance&&(b=(new Date).getTime(),d=g||b,c=b-d,g=b,h.push({Name:a[0],Arguments:[].slice.call(a,1)||"",Element:x,"Execution Time":c})),clearTimeout(l.performance.timer),l.performance.timer=setTimeout(l.performance.display,100)},display:function(){var b=m.name+":",c=0;g=!1,clearTimeout(l.performance.timer),a.each
|