You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

11 lines
5.5 KiB

/*
* # 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(a,function(e,n){o+=n["Execution Time"]}),n+=" "+o+"ms",i&&(n+=" '"+i+"'"),(console.group!==c||console.table!==c)&&a.length>0&&(console.groupCollapsed(n),console.table?console.table(a):e.each(a,function(e,n){console.log(n.Name+": "+n["Execution Time"]+"ms")}),console.groupEnd()),a=[]}},invoke:function(n,t,i){var r,a,s,l=C;return t=t||u,i=E||i,"string"==typeof n&&l!==c&&(n=n.split(/[\. ]/),r=n.length-1,e.each(n,function(o,t){var i=o!=r?t+n[o+1].charAt(0).toUpperCase()+n[o+1].slice(1):n;if(e.isPlainObject(l[i])&&o!=r)l=l[i];else{if(l[i]!==c)return a=l[i],!1;if(!e.isPlainObject(l[t])||o==r)return l[t]!==c?(a=l[t],!1):!1;l=l[t]}})),e.isFunction(a)?s=a.apply(i,t):a!==c&&(s=a),e.isArray(o)?o.push(s):o!==c?o=[o,s]:s!==c&&(o=s),a}},l?(C===c&&d.initialize(),d.invoke(s)):(C!==c&&d.destroy(),d.initialize())}),o!==c?o:this},e.fn.checkbox.settings={name:"Checkbox",namespace:"checkbox",debug:!1,verbose:!0,performance:!0,uncheckable:"auto",fireOnInit:!0,onChange:function(){},onChecked:function(){},onUnchecked:function(){},onEnabled:function(){},onDisabled:function(){},className:{checked:"checked",disabled:"disabled",radio:"radio",readOnly:"read-only"},error:{method:"The method you called is not defined."},selector:{input:"input[type=checkbox], input[type=radio]",label:"label"}}}(jQuery,window,document);