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.9 KiB
11 lines
5.9 KiB
/*
|
|
* # Semantic UI
|
|
* https://github.com/Semantic-Org/Semantic-UI
|
|
* http://www.semantic-ui.com/
|
|
*
|
|
* Copyright 2014 Contributors
|
|
* Released under the MIT license
|
|
* http://opensource.org/licenses/MIT
|
|
*
|
|
*/
|
|
!function(e,n,o,t){"use strict";e.fn.checkbox=function(o){var c,i=e(this),r=i.selector||"",a=(new Date).getTime(),s=[],l=arguments[0],u="string"==typeof l,d=[].slice.call(arguments,1);return i.each(function(){var i,b,g=e.extend(!0,{},e.fn.checkbox.settings,o),h=g.className,f=g.namespace,p=g.selector,m=g.error,k="."+f,v="module-"+f,y=e(this),x=e(this).find(p.label).first(),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.is.checked()?(b.set.checked(),g.fireOnInit&&e.proxy(g.onChecked,C.get())()):(b.remove.checked(),g.fireOnInit&&e.proxy(g.onUnchecked,C.get())()),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)},refresh:function(){y=e(this),x=e(this).find(p.label).first(),C=e(this).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,o){var t=e(n);o=e.isFunction(b[o])?b[o]:b.toggle,t.size()>0?(b.debug("Attaching checkbox events to element",n,o),t.on("click"+k,o)):b.error(m.notFound)},event:{keydown:function(n){var o=n.which,t={enter:13,escape:27};o==t.escape&&(b.verbose("Escape key pressed blurring field"),y.blur()),n.ctrlKey||o!=t.enter||(b.verbose("Enter key pressed, toggling checkbox"),e.proxy(b.toggle,this)(),n.preventDefault())}},is:{radio:function(){return y.hasClass(h.radio)},checked:function(){return C.prop("checked")!==t&&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(){y.addClass(h.checked)},tab:function(){C.attr("tabindex")===t&&C.attr("tabindex",0)}},create:{label:function(){C.prevAll(p.label).size()>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.size()>0}},add:{events:function(){b.verbose("Attaching checkbox events"),y.on("click"+k,b.toggle).on("keydown"+k,p.input,b.event.keydown)}},remove:{checked:function(){y.removeClass(h.checked)},events:function(){b.debug("Removing events"),y.off(k).removeData(v),C.off(k,b.event.keydown),x.off(k)}},enable:function(){b.debug("Enabling checkbox functionality"),y.removeClass(h.disabled),C.prop("disabled",!1),e.proxy(g.onEnabled,C.get())()},disable:function(){b.debug("Disabling checkbox functionality"),y.addClass(h.disabled),C.prop("disabled","disabled"),e.proxy(g.onDisabled,C.get())()},check:function(){b.debug("Enabling checkbox",C),C.prop("checked",!0).trigger("change"),b.set.checked(),e.proxy(g.onChange,C.get())(),e.proxy(g.onChecked,C.get())()},uncheck:function(){b.debug("Disabling checkbox"),C.prop("checked",!1).trigger("change"),b.remove.checked(),e.proxy(g.onChange,C.get())(),e.proxy(g.onUnchecked,C.get())()},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())):(console.log(b.can.change()),void b.debug("Checkbox is read-only or disabled, ignoring toggle"))},setting:function(n,o){if(b.debug("Changing setting",n,o),e.isPlainObject(n))e.extend(!0,g,n);else{if(o===t)return g[n];g[n]=o}},internal:function(n,o){if(e.isPlainObject(n))e.extend(!0,b,n);else{if(o===t)return b[n];b[n]=o}},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,o,t;g.performance&&(n=(new Date).getTime(),t=a||n,o=n-t,a=n,s.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:E,"Execution Time":o})),clearTimeout(b.performance.timer),b.performance.timer=setTimeout(b.performance.display,100)},display:function(){var n=g.name+":",o=0;a=!1,clearTimeout(b.performance.timer),e.each(s,function(e,n){o+=n["Execution Time"]}),n+=" "+o+"ms",r&&(n+=" '"+r+"'"),(console.group!==t||console.table!==t)&&s.length>0&&(console.groupCollapsed(n),console.table?console.table(s):e.each(s,function(e,n){console.log(n.Name+": "+n["Execution Time"]+"ms")}),console.groupEnd()),s=[]}},invoke:function(n,o,i){var r,a,s,l=D;return o=o||d,i=E||i,"string"==typeof n&&l!==t&&(n=n.split(/[\. ]/),r=n.length-1,e.each(n,function(o,c){var i=o!=r?c+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]!==t)return a=l[i],!1;if(!e.isPlainObject(l[c])||o==r)return l[c]!==t?(a=l[c],!1):!1;l=l[c]}})),e.isFunction(a)?s=a.apply(i,o):a!==t&&(s=a),e.isArray(c)?c.push(s):c!==t?c=[c,s]:s!==t&&(c=s),a}},u?(D===t&&b.initialize(),b.invoke(l)):(D!==t&&b.destroy(),b.initialize())}),c!==t?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:{input:"input[type=checkbox], input[type=radio]",label:"label"}}}(jQuery,window,document);
|