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
4.4 KiB
1 lines
4.4 KiB
!function(a,b,c,d){"use strict";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,"."+n),p="module-"+n,q=a(this),r=a(this).next(l.selector.label).first(),s=a(this).find(l.selector.input),t=q.selector||"",u=q.data(p),v=this;e={initialize:function(){e.verbose("Initializing checkbox",l),l.context&&""!==t?(e.verbose("Adding delegated events"),a(v,l.context).on(t,"click"+o,e.toggle).on(t+" + "+l.selector.label,"click"+o,e.toggle)):(q.on("click"+o,e.toggle).data(p,e),s.on("keydown"+o,e.event.keydown),r.on("click"+o,e.toggle)),e.is.checked()?(e.set.checked(),l.fireOnInit&&a.proxy(l.onChecked,s.get())()):(e.remove.checked(),l.fireOnInit&&a.proxy(l.onUnchecked,s.get())()),e.instantiate()},instantiate:function(){e.verbose("Storing instance of module",e),u=e,q.data(p,e)},destroy:function(){e.verbose("Destroying previous module"),q.off(o).removeData(p),s.off(o,e.event.keydown),r.off(o)},event:{keydown:function(b){var c=b.which,d={enter:13,escape:27};c==d.escape&&(e.verbose("Escape key pressed blurring field"),q.blur()),b.ctrlKey||c!=d.enter||(e.verbose("Enter key pressed, toggling checkbox"),a.proxy(e.toggle,this)(),b.preventDefault())}},is:{radio:function(){return q.hasClass(m.radio)},checked:function(){return s.prop("checked")!==d&&s.prop("checked")},unchecked:function(){return!e.is.checked()}},can:{uncheck:function(){return"boolean"==typeof l.required?l.required:!e.is.radio()}},set:{checked:function(){q.addClass(m.checked)}},remove:{checked:function(){q.removeClass(m.checked)}},check:function(){e.debug("Enabling checkbox",s),s.prop("checked",!0).trigger("change"),e.set.checked(),a.proxy(l.onChange,s.get())(),a.proxy(l.onChecked,s.get())()},uncheck:function(){e.debug("Disabling checkbox"),s.prop("checked",!1).trigger("change"),e.remove.checked(),a.proxy(l.onChange,s.get())(),a.proxy(l.onUnchecked,s.get())()},toggle:function(){e.verbose("Determining new checkbox state"),e.is.unchecked()?e.check():e.is.checked()&&e.can.uncheck()&&e.uncheck()},setting:function(b,c){if(e.debug("Changing setting",b,c),a.isPlainObject(b))a.extend(!0,l,b);else{if(c===d)return l[b];l[b]=c}},internal:function(b,c){if(a.isPlainObject(b))a.extend(!0,e,b);else{if(c===d)return e[b];e[b]=c}},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:v,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,e,f){var g,h,i,j=u;return e=e||k,f=v||f,"string"==typeof b&&j!==d&&(b=b.split(/[\. ]/),g=b.length-1,a.each(b,function(c,e){var f=c!=g?e+b[c+1].charAt(0).toUpperCase()+b[c+1].slice(1):b;if(a.isPlainObject(j[f])&&c!=g)j=j[f];else{if(j[f]!==d)return h=j[f],!1;if(!a.isPlainObject(j[e])||c==g)return j[e]!==d?(h=j[e],!1):!1;j=j[e]}})),a.isFunction(h)?i=h.apply(f,e):h!==d&&(i=h),a.isArray(c)?c.push(i):c!==d?c=[c,i]:i!==d&&(c=i),h}},j?(u===d&&e.initialize(),e.invoke(i)):(u!==d&&e.destroy(),e.initialize())}),c!==d?c:this},a.fn.checkbox.settings={name:"Checkbox",namespace:"checkbox",debug:!1,verbose:!0,performance:!0,context:!1,required:"auto",fireOnInit:!0,className:{checked:"checked",radio:"radio"},onChange:function(){},onChecked:function(){},onUnchecked:function(){},error:{method:"The method you called is not defined."},selector:{input:"input[type=checkbox], input[type=radio]",label:"label"}}}(jQuery,window,document);
|