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.
1 line
11 KiB
1 line
11 KiB
7 years ago
|
!function(e,n,i,t){"use strict";n=void 0!==n&&n.Math==Math?n:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")(),e.fn.checkbox=function(t){var o,a=e(this),c=a.selector||"",r=(new Date).getTime(),d=[],l=arguments[0],s="string"==typeof l,u=[].slice.call(arguments,1);return a.each(function(){var a,b,h=e.extend(!0,{},e.fn.checkbox.settings,t),g=h.className,f=h.namespace,p=h.selector,k=h.error,m="."+f,v="module-"+f,y=e(this),C=e(this).children(p.label),x=e(this).children(p.input),w=x[0],I=!1,D=!1,S=y.data(v),E=this;b={initialize:function(){b.verbose("Initializing checkbox",h),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),S=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(p.input)&&(b.debug("Behavior called on <input> adjusting invoked element"),y=y.closest(p.checkbox),b.refresh())}},setup:function(){b.set.initialLoad(),b.is.indeterminate()?(b.debug("Initial value is indeterminate"),b.indeterminate()):b.is.checked()?(b.debug("Initial value is checked"),b.check()):(b.debug("Initial value is unchecked"),b.uncheck()),b.remove.initialLoad()},refresh:function(){C=y.children(p.label),x=y.children(p.input),w=x[0]},hide:{input:function(){b.verbose("Modifying <input> z-index to be unselectable"),x.addClass(g.hidden)}},show:{input:function(){b.verbose("Modifying <input> z-index to be selectable"),x.removeClass(g.hidden)}},observeChanges:function(){"MutationObserver"in n&&(a=new MutationObserver(function(e){b.debug("DOM tree modified, updating selector cache"),b.refresh()}),a.observe(E,{childList:!0,subtree:!0}),b.debug("Setting up mutation observer",a))},attachEvents:function(n,i){var t=e(n);i=e.isFunction(b[i])?b[i]:b.toggle,t.length>0?(b.debug("Attaching checkbox events to element",n,i),t.on("click"+m,i)):b.error(k.notFound)},event:{click:function(n){var i=e(n.target);return i.is(p.input)?void b.verbose("Using default check action on initialized checkbox"):i.is(p.link)?void b.debug("Clicking link inside checkbox, skipping toggle"):(b.toggle(),x.focus(),void n.preventDefault())},keydown:function(e){var n=e.which,i={enter:13,space:32,escape:27};n==i.escape?(b.verbose("Escape key pressed blurring field"),x.blur(),D=!0):e.ctrlKey||n!=i.space&&n!=i.enter?D=!1:(b.verbose("Enter/space key pressed, toggling checkbox"),b.toggle(),D=!0)},keyup:function(e){D&&e.preventDefault()}},check:function(){b.should.allowCheck()&&(b.debug("Checking checkbox",x),b.set.checked(),b.should.ignoreCallbacks()||(h.onChecked.call(w),h.onChange.call(w)))},uncheck:function(){b.should.allowUncheck()&&(b.debug("Unchecking checkbox"),b.set.unchecked(),b.should.ignoreCallbacks()||(h.onUnchecked.call(w),h.onChange.call(w)))},indeterminate:function(){if(b.should.allowIndeterminate())return void b.debug("Checkbox is already indeterminate");b.debug("Making checkbox indeterminate"),b.set.indeterminate(),b.should.ignoreCallbacks()||(h.onIndeterminate.call(w),h.onChange.call(w))},determinate:function(){if(b.should.allowDeterminate())return void b.debug("Checkbox is already determinate");b.debug("Making checkbox determinate"),b.set.determinate(),b.should.ignoreCallbacks()||(h.onDeterminate.call(w),h.onChange.call(w))},enable:function(){if(b.is.enabled())return void b.debug("Checkbox is already enabled");b.debug("Enabling checkbox"),b.set.enabled(),h.onEnable.call(w),h.onEnabled.call(w)},disable:function(){if(b.is.disabled())return void b.debug("Checkbox is already disabled");b.debug("Disabling checkbox"),b.set.disabled(),h.onDisable.call(w),h.onDisabled.call(w)},get:{radios:function(){var n=b.get.name();return e('input[name="'+n+'"]').closest(p.checkbox)},otherRadios:function(){return b.get.radios().not(y)},name:function(){return x.attr("name")}},is:{initialLoad:function(){return I},radio:function(){return x.hasClass(g.radio)||"radio"==x.attr("type")},indeterminate:function(){return void 0!==x.prop("indeterminate")&&x.prop("indetermi
|