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
6.3 KiB

/*!
* # Semantic UI 2.0.0 - Checkbox
* http://github.com/semantic-org/semantic-ui/
*
*
* Copyright 2014 Contributors
* Released under the MIT license
* http://opensource.org/licenses/MIT
*
*/
!function(e,n,t,o){"use strict";e.fn.checkbox=function(t){var c,i=e(this),a=i.selector||"",r=(new Date).getTime(),l=[],s=arguments[0],u="string"==typeof s,d=[].slice.call(arguments,1);return i.each(function(){var i,b,g=e.extend(!0,{},e.fn.checkbox.settings,t),h=g.className,f=g.namespace,p=g.selector,k=g.error,m="."+f,v="module-"+f,y=e(this),x=e(this).find(p.label),C=e(this).find(p.input),D=y.data(v),E=this;b={initialize:function(){b.verbose("Initializing checkbox",g),b.create.label(),b.add.events(),b.setup(),b.observeChanges(),b.instantiate()},instantiate:function(){b.verbose("Storing instance of module",b),D=b,y.data(v,b)},destroy:function(){b.verbose("Destroying module"),b.remove.events(),y.removeData(v)},setup:function(){b.is.checked()?(b.debug("Setting initial value to checked"),b.set.checked(),g.fireOnInit&&g.onChecked.call(C.get())):(b.debug("Setting initial value to unchecked"),b.remove.checked(),g.fireOnInit&&g.onUnchecked.call(C.get()))},refresh:function(){x=y.find(p.label),C=y.find(p.input)},observeChanges:function(){"MutationObserver"in n&&(i=new MutationObserver(function(){b.debug("DOM tree modified, updating selector cache"),b.refresh()}),i.observe(E,{childList:!0,subtree:!0}),b.debug("Setting up mutation observer",i))},attachEvents:function(n,t){var o=e(n);t=e.isFunction(b[t])?b[t]:b.toggle,o.length>0?(b.debug("Attaching checkbox events to element",n,t),o.on("click"+m,t)):b.error(k.notFound)},event:{keydown:function(e){var n=e.which,t={enter:13,space:32,escape:27};n==t.escape&&(b.verbose("Escape key pressed blurring field"),y.blur()),e.ctrlKey||n!=t.enter&&n!=t.space||(b.verbose("Enter key pressed, toggling checkbox"),b.toggle.call(this),e.preventDefault())}},get:{radios:function(){return e('input[name="'+b.get.name()+'"]').closest(p.checkbox)},name:function(){return C.attr("name")}},is:{radio:function(){return C.hasClass(h.radio)||"radio"==C.attr("type")},checked:function(){return C.prop("checked")!==o&&C.prop("checked")},unchecked:function(){return!b.is.checked()}},can:{change:function(){return!(y.hasClass(h.disabled)||y.hasClass(h.readOnly)||C.prop("disabled"))},uncheck:function(){return"boolean"==typeof g.uncheckable?g.uncheckable:!b.is.radio()}},set:{checked:function(){var e;b.is.radio()&&(e=b.get.radios(),b.debug("Unchecking other radios",e),e.removeClass(h.checked)),y.addClass(h.checked)},tab:function(){C.attr("tabindex")===o&&C.attr("tabindex",0)}},create:{label:function(){C.prevAll(p.label).length>0?(C.prev(p.label).detach().insertAfter(C),b.debug("Moving existing label",x)):b.has.label()||(x=e("<label>").insertAfter(C),b.debug("Creating label",x))}},has:{label:function(){return x.length>0}},add:{events:function(){b.verbose("Attaching checkbox events"),y.on("click"+m,b.toggle).on("keydown"+m,p.input,b.event.keydown)}},remove:{checked:function(){y.removeClass(h.checked)},events:function(){b.debug("Removing events"),y.off(m).removeData(v),C.off(m,b.event.keydown),x.off(m)}},enable:function(){b.debug("Enabling checkbox functionality"),y.removeClass(h.disabled),C.prop("disabled",!1),g.onEnabled.call(C[0])},disable:function(){b.debug("Disabling checkbox functionality"),y.addClass(h.disabled),C.prop("disabled","disabled"),g.onDisabled.call(C[0])},check:function(){b.debug("Enabling checkbox",C),C.prop("checked",!0).trigger("change"),b.set.checked(),C.trigger("blur"),g.onChange.call(C[0]),g.onChecked.call(C[0])},uncheck:function(){b.debug("Disabling checkbox"),C.prop("checked",!1).trigger("change"),b.remove.checked(),C.trigger("blur"),g.onChange.call(C[0]),g.onUnchecked.call(C[0])},toggle:function(){return b.can.change()?(b.verbose("Determining new checkbox state"),void(b.is.unchecked()?b.check():b.is.checked()&&b.can.uncheck()&&b.uncheck())):void(b.is.radio()||b.debug("Checkbox is read-only or disabled, ignoring toggle"))},setting:function(n,t){if(b.debug("Changing setting",n,t),e.isPlainObject(n))e.extend(!0,g,n);else{if(t===o)return g[n];g[n]=t}},internal:function(n,t){if(e.isPlainObject(n))e.extend(!0,b,n);else{if(t===o)return b[n];b[n]=t}},debug:function(){g.debug&&(g.performance?b.performance.log(arguments):(b.debug=Function.prototype.bind.call(console.info,console,g.name+":"),b.debug.apply(console,arguments)))},verbose:function(){g.verbose&&g.debug&&(g.performance?b.performance.log(arguments):(b.verbose=Function.prototype.bind.call(console.info,console,g.name+":"),b.verbose.apply(console,arguments)))},error:function(){b.error=Function.prototype.bind.call(console.error,console,g.name+":"),b.error.apply(console,arguments)},performance:{log:function(e){var n,t,o;g.performance&&(n=(new Date).getTime(),o=r||n,t=n-o,r=n,l.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:E,"Execution Time":t})),clearTimeout(b.performance.timer),b.performance.timer=setTimeout(b.performance.display,500)},display:function(){var n=g.name+":",t=0;r=!1,clearTimeout(b.performance.timer),e.each(l,function(e,n){t+=n["Execution Time"]}),n+=" "+t+"ms",a&&(n+=" '"+a+"'"),(console.group!==o||console.table!==o)&&l.length>0&&(console.groupCollapsed(n),console.table?console.table(l):e.each(l,function(e,n){console.log(n.Name+": "+n["Execution Time"]+"ms")}),console.groupEnd()),l=[]}},invoke:function(n,t,i){var a,r,l,s=D;return t=t||d,i=E||i,"string"==typeof n&&s!==o&&(n=n.split(/[\. ]/),a=n.length-1,e.each(n,function(t,c){var i=t!=a?c+n[t+1].charAt(0).toUpperCase()+n[t+1].slice(1):n;if(e.isPlainObject(s[i])&&t!=a)s=s[i];else{if(s[i]!==o)return r=s[i],!1;if(!e.isPlainObject(s[c])||t==a)return s[c]!==o?(r=s[c],!1):(b.error(k.method,n),!1);s=s[c]}})),e.isFunction(r)?l=r.apply(i,t):r!==o&&(l=r),e.isArray(c)?c.push(l):c!==o?c=[c,l]:l!==o&&(c=l),r}},u?(D===o&&b.initialize(),b.invoke(s)):(D!==o&&D.invoke("destroy"),b.initialize())}),c!==o?c: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:{checkbox:".ui.checkbox",input:'> input[type="checkbox"], > input[type="radio"]',label:"> label"}}}(jQuery,window,document);