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