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 lines
3.6 KiB
1 lines
3.6 KiB
!function(a,b,c,d){a.fn.checkbox=function(b){var c,e=a(this),f=a.extend(!0,{},a.fn.checkbox.settings,b),g=f.className,h=f.namespace,i=f.error,j="."+h,k="module-"+h,l=e.selector||"",m=(new Date).getTime(),n=[],o=arguments[0],p="string"==typeof o,q=[].slice.call(arguments,1);return e.each(function(){var b,h=a(this),r=a(this).next(f.selector.label).first(),s=a(this).find(f.selector.input),t=h.selector||"",u=h.data(k),v=this;b={initialize:function(){b.verbose("Initializing checkbox",f),f.context&&""!==t?(b.verbose("Adding delegated events"),a(v,f.context).on(t,"click"+j,b.toggle).on(t+" + "+f.selector.label,"click"+j,b.toggle)):(h.on("click"+j,b.toggle).data(k,b),r.on("click"+j,b.toggle)),b.instantiate()},instantiate:function(){b.verbose("Storing instance of module",b),u=b,h.data(k,b)},destroy:function(){b.verbose("Destroying previous module"),h.off(j).removeData(k)},is:{radio:function(){return h.hasClass(g.radio)}},can:{disable:function(){return"boolean"==typeof f.required?f.required:!b.is.radio()}},enable:function(){b.debug("Enabling checkbox"),s.prop("checked",!0),a.proxy(f.onChange,s.get())(),a.proxy(f.onEnable,s.get())()},disable:function(){b.debug("Disabling checkbox"),s.prop("checked",!1),a.proxy(f.onChange,s.get())(),a.proxy(f.onDisable,s.get())()},toggle:function(){b.verbose("Determining new checkbox state"),s.prop("checked")!==d&&s.prop("checked")?b.can.disable()&&b.disable():b.enable()},setting:function(b,c){return c===d?f[b]:(a.isPlainObject(b)?a.extend(!0,f,b):f[b]=c,void 0)},internal:function(c,e){return e===d?b[c]:(a.isPlainObject(c)?a.extend(!0,b,c):b[c]=e,void 0)},debug:function(){f.debug&&(f.performance?b.performance.log(arguments):(b.debug=Function.prototype.bind.call(console.info,console,f.name+":"),b.debug.apply(console,arguments)))},verbose:function(){f.verbose&&f.debug&&(f.performance?b.performance.log(arguments):(b.verbose=Function.prototype.bind.call(console.info,console,f.name+":"),b.verbose.apply(console,arguments)))},error:function(){b.error=Function.prototype.bind.call(console.error,console,f.name+":"),b.error.apply(console,arguments)},performance:{log:function(a){var c,d,e;f.performance&&(c=(new Date).getTime(),e=m||c,d=c-e,m=c,n.push({Element:v,Name:a[0],Arguments:[].slice.call(a,1)||"","Execution Time":d})),clearTimeout(b.performance.timer),b.performance.timer=setTimeout(b.performance.display,100)},display:function(){var c=f.name+":",g=0;m=!1,clearTimeout(b.performance.timer),a.each(n,function(a,b){g+=b["Execution Time"]}),c+=" "+g+"ms",l&&(c+=" '"+l+"'"),e.size()>1&&(c+=" ("+e.size()+")"),(console.group!==d||console.table!==d)&&n.length>0&&(console.groupCollapsed(c),console.table?console.table(n):a.each(n,function(a,b){console.log(b.Name+": "+b["Execution Time"]+"ms")}),console.groupEnd()),n=[]}},invoke:function(e,f,g){var h,j,k;return f=f||q,g=v||g,"string"==typeof e&&u!==d&&(e=e.split(/[\. ]/),h=e.length-1,a.each(e,function(c,f){var g=c!=h?f+e[c+1].charAt(0).toUpperCase()+e[c+1].slice(1):e;if(a.isPlainObject(u[f])&&c!=h)u=u[f];else{if(!a.isPlainObject(u[g])||c==h)return u[f]!==d?(j=u[f],!1):u[g]!==d?(j=u[g],!1):(b.error(i.method),!1);u=u[g]}})),a.isFunction(j)?k=j.apply(g,f):j!==d&&(k=j),a.isArray(c)?c.push(k):"string"==typeof c?c=[c,k]:k!==d&&(c=k),j}},p?(u===d&&b.initialize(),b.invoke(o)):(u!==d&&b.destroy(),b.initialize())}),c!==d?c:this},a.fn.checkbox.settings={name:"Checkbox",namespace:"checkbox",verbose:!0,debug:!0,performance:!0,context:!1,required:"auto",onChange:function(){},onEnable:function(){},onDisable:function(){},error:{method:"The method you called is not defined."},selector:{input:"input",label:"label"},className:{radio:"radio"}}}(jQuery,window,document);
|