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.5 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.namespace,h="module-"+f.namespace,i=e.selector||"",j=(new Date).getTime(),k=[],l=arguments[0],m="string"==typeof l,n=[].slice.call(arguments,1);return e.each(function(){var b,e=a(this),o=a(this).next(f.selector.label).first(),p=a(this).find(f.selector.input),q=e.selector||"",r=this,s=e.data("module-"+f.namespace),t=f.className,u=f.namespace,v=f.errors;b={initialize:function(){f.context&&""!==q?(b.verbose("Initializing checkbox with delegated events",e),a(r,f.context).on(q,"click"+g,b.toggle).on(q+" + "+f.selector.label,"click"+g,b.toggle).data(h,b)):(b.verbose("Initializing checkbox with bound events",e),e.on("click"+g,b.toggle).data(h,b),o.on("click"+g,b.toggle))},destroy:function(){b.verbose("Destroying previous module for",e),e.off(u)},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"),e.addClass(t.active),p.prop("checked",!0),a.proxy(f.onChange,p.get())(),a.proxy(f.onEnable,p.get())()},disable:function(){b.debug("Disabling checkbox"),e.removeClass(t.active),p.prop("checked",!1),a.proxy(f.onChange,p.get())(),a.proxy(f.onDisable,p.get())()},toggle:function(){b.verbose("Toggling checkbox state"),p.prop("checked")!==d&&p.prop("checked")?b.can.disable()&&b.disable():b.enable()},setting:function(c,e){return e===d?f[c]:(a.isPlainObject(c)?(b.verbose("Modifying settings object",c,e),a.extend(!0,f,c)):(b.verbose("Modifying setting",c,e),f[c]=e),void 0)},internal:function(c,e){return e===d?b[c]:(a.isPlainObject(c)?(b.verbose("Modifying internal property",c,e),a.extend(!0,b,c)):(b.verbose("Changing internal method to",e),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+":"))},verbose:function(){f.verbose&&f.debug&&(f.performance?b.performance.log(arguments):b.verbose=Function.prototype.bind.call(console.info,console,f.moduleName+":"))},error:function(){b.error=Function.prototype.bind.call(console.log,console,f.moduleName+":")},performance:{log:function(a){var c,d,e;f.performance&&(c=(new Date).getTime(),e=j||c,d=c-e,j=c,k.push({Element:r,Name:a[0],Arguments:a[1]||"","Execution Time":d})),clearTimeout(b.performance.timer),b.performance.timer=setTimeout(b.performance.display,100)},display:function(){var b=f.moduleName+":",c=0;j=!1,a.each(k,function(a,b){c+=b["Execution Time"]}),b+=" "+c+"ms",i&&(b+=" '"+i+"'"),(console.group!==d||console.table!==d)&&k.length>0&&(console.groupCollapsed(b),console.table?console.table(k):a.each(k,function(a,b){console.log(b.Name+": "+b["Execution Time"]+"ms")}),console.groupEnd()),k=[]}},invoke:function(c,e,f){var g,h;return e=e||n,f=r||f,"string"==typeof c&&s!==d&&(c=c.split("."),g=c.length-1,a.each(c,function(c,e){return a.isPlainObject(s[e])&&c!=g?(s=s[e],!0):s[e]!==d?(h=s[e],!0):(b.error(v.method),!1)})),a.isFunction(h)?(s.verbose("Executing invoked function",h),h.apply(f,e)):h||!1}},m?(s===d&&b.initialize(),c=b.invoke(l)):(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:{active:"active",radio:"radio"}}}(jQuery,window,document);