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.2 KiB

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