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