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
3.4 KiB

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