|
|
/*! * # Semantic UI 2.0.3 - Checkbox * http://github.com/semantic-org/semantic-ui/
* * * Copyright 2015 Contributors * Released under the MIT license * http://opensource.org/licenses/MIT
* */ !function(e,n,t,i){"use strict";e.fn.checkbox=function(t){var o,r=e(this),a=r.selector||"",c=(new Date).getTime(),d=[],s=arguments[0],l="string"==typeof s,u=[].slice.call(arguments,1);return r.each(function(){var r,b,g=e.extend(!0,{},e.fn.checkbox.settings,t),h=g.className,p=g.namespace,m=g.selector,f=g.error,k="."+p,v="module-"+p,y=e(this),x=e(this).children(m.label),C=e(this).children(m.input),I=y.data(v),O=this;b={initialize:function(){b.verbose("Initializing checkbox",g),b.create.label(),b.bind.events(),b.set.tabbable(),b.hide.input(),b.observeChanges(),b.instantiate(),b.setup()},instantiate:function(){b.verbose("Storing instance of module",b),I=b,y.data(v,b)},destroy:function(){b.verbose("Destroying module"),b.unbind.events(),b.show.input(),y.removeData(v)},fix:{reference:function(){y.is(m.input)&&(b.debug("Behavior called on <input> adjusting invoked element"),y=y.closest(m.checkbox),b.refresh())}},setup:function(){b.is.indeterminate()?(b.debug("Initial value is indeterminate"),b.set.indeterminate(),g.fireOnInit&&(g.onIndeterminate.call(C[0]),g.onChange.call(C[0]))):b.is.checked()?(b.debug("Initial value is checked"),b.set.checked(),g.fireOnInit&&(g.onChecked.call(C[0]),g.onChange.call(C[0]))):(b.debug("Initial value is unchecked"),b.set.unchecked(),g.fireOnInit&&(g.onUnchecked.call(C[0]),g.onChange.call(C[0])))},refresh:function(){x=y.children(m.label),C=y.children(m.input)},hide:{input:function(){b.verbose("Modfying <input> z-index to be unselectable"),C.addClass(h.hidden)}},show:{input:function(){b.verbose("Modfying <input> z-index to be selectable"),C.removeClass(h.hidden)}},observeChanges:function(){"MutationObserver"in n&&(r=new MutationObserver(function(e){b.debug("DOM tree modified, updating selector cache"),b.refresh()}),r.observe(O,{childList:!0,subtree:!0}),b.debug("Setting up mutation observer",r))},attachEvents:function(n,t){var i=e(n);t=e.isFunction(b[t])?b[t]:b.toggle,i.length>0?(b.debug("Attaching checkbox events to element",n,t),i.on("click"+k,t)):b.error(f.notFound)},event:{click:function(n){return e(n.target).is(m.input)?void b.verbose("Using default check action on initialized checkbox"):(b.toggle(),void n.preventDefault())},keydown:function(e){var n=e.which,t={enter:13,space:32,escape:27};n==t.escape&&(b.verbose("Escape key pressed blurring field"),C.blur(),e.preventDefault()),e.ctrlKey||n!=t.enter&&n!=t.space||(b.verbose("Enter key pressed, toggling checkbox"),b.toggle(),e.preventDefault())}},check:function(){return!b.is.indeterminate()&&b.is.checked()?void b.debug("Checkbox is already checked"):(b.debug("Checking checkbox",C),b.set.checked(),g.onChecked.call(C[0]),void g.onChange.call(C[0]))},uncheck:function(){return!b.is.indeterminate()&&b.is.unchecked()?void b.debug("Checkbox is already unchecked"):(b.debug("Unchecking checkbox"),b.set.unchecked(),g.onUnchecked.call(C[0]),void g.onChange.call(C[0]))},indeterminate:function(){return b.is.indeterminate()?void b.debug("Checkbox is already indeterminate"):(b.debug("Making checkbox indeterminate"),b.set.indeterminate(),g.onIndeterminate.call(C[0]),void g.onChange.call(C[0]))},determinate:function(){return b.is.determinate()?void b.debug("Checkbox is already determinate"):(b.debug("Making checkbox determinate"),b.set.determinate(),g.onDeterminate.call(C[0]),void g.onChange.call(C[0]))},enable:function(){return b.is.enabled()?void b.debug("Checkbox is already enabled"):(b.debug("Enabling checkbox"),b.set.enabled(),void g.onEnable.call(C[0]))},disable:function(){return b.is.disabled()?void b.debug("Checkbox is already disabled"):(b.debug("Disabling checkbox"),b.set.disabled(),void g.onDisable.call(C[0]))},get:{radios:function(){var n=b.get.name();return e('input[name="'+n+'"]').closest(m.checkbox)},otherRadios:function(){return b.get.radios().not(y)},name:function(){return C.attr("name")}},is:{radio:function(){return C.hasClass(h.radio)||"radio"==C.attr("type")},indeterminate:function(){return C.prop("indeterminate")!==i&&C.prop("indeterminate")},checked:function(){return C.prop("checked")!==i&&C.prop("checked")},disabled:function(){return C.prop
|