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