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.

0 lines
11 KiB

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