source: extensions/GrumPluginClasses/js/ui.inputCheckbox.min.js @ 10155

Last change on this file since 10155 was 8961, checked in by grum, 13 years ago

release 3.4.0
fix bug:1984, bug:2109
js file are minified, remove packed files

  • Property svn:executable set to *
File size: 6.4 KB
Line 
1/* file: ui.inputCheckbox.js - v1.0.0 | minified on 2011/01/27 with http://jscompress.com/ */
2(function($)
3{var publicMethods={init:function(opt)
4{return this.each(function()
5{var $this=$(this),data=$this.data('options'),objects=$this.data('objects'),properties=$this.data('properties'),options={values:{forced:false,checked:'yes',unchecked:'no'},returnMode:'selected',change:null};$this.data('options',options).addClass('ui-inputCheckbox');if(!properties)
6{$this.data('properties',{initialized:false,isValid:true,checkboxList:null,isCB:true});properties=$this.data('properties');}
7if($this.get(0).tagName=='INPUT'&&$this.get(0).type=='checkbox')
8{properties.checkboxList=$this;}
9else
10{properties.checkboxList=$this.find('input[type=checkbox]');properties.isCB=false;}
11properties.checkboxList.bind('click.inputCheckbox',function(event)
12{privateMethods.setValue($this,$(this).attr('id'),$(this).attr('checked')?options.values.checked:options.values.unchecked,false);});privateMethods.setOptions($this,opt);});},destroy:function()
13{return this.each(function()
14{var properties=this.data('properties');properties.checkboxList.unbind('.inputCheckbox');this.removeClass('ui-inputCheckbox');});},options:function(value)
15{return(this.each(function()
16{privateMethods.setOptions($(this),value);}));},disabled:function(value)
17{if(value!=null)
18{return(this.each(function()
19{privateMethods.setDisabled($(this),value);}));}
20else
21{return(privateMethods.getDisabled($(this)));}},values:function(value)
22{if(value!=null)
23{return(this.each(function()
24{privateMethods.setValues($(this),value);}));}
25else
26{var options=this.data('options');return(options.values);}},value:function(id,value)
27{var properties=this.data('properties');if(properties.isCB)
28{value=id;id=$(this).get(0).id;}
29if(value!=null||id==':all'||id==':invert'||id==':none')
30{return(this.each(function()
31{privateMethods.setValue($(this),id,value,true);}));}
32else if(id!=null&&id!='')
33{var options=this.data('options');return($(this).find('#'+id).attr('checked')?options.values.checked:options.values.unchecked);}
34else
35{var options=this.data('options'),returned=[];if(options.values.forced)
36{$(this).find('input').each(function()
37{returned.push({id:$(this).attr('id'),value:$(this).attr('checked')?options.values.checked:options.values.unchecked});});}
38else
39{var filter=(options.returnMode=='selected'?':checked':':not(:checked)');$(this).find('input'+filter).each(function()
40{returned.push($(this).attr('value'));});}
41return(returned);}},returnMode:function(value)
42{if(value!=null)
43{return this.each(function()
44{privateMethods.setReturnMode($(this),value);});}
45else
46{var options=this.data('options');if(options)
47{return(options.returnMode);}
48else
49{return('selected');}}},isValid:function(value)
50{if(value!=null)
51{return(this.each(function()
52{privateMethods.setIsValid($(this),value);}));}
53else
54{var properties=this.data('properties');return(properties.isValid);}},change:function(value)
55{if(value!=null&&$.isFunction(value))
56{return(this.each(function()
57{privateMethods.setEventChange($(this),value);}));}
58else
59{var options=this.data('options');if(options)
60{return(options.change);}
61else
62{return(null);}}}};var privateMethods={setOptions:function(object,value)
63{var properties=object.data('properties'),options=object.data('options');if(!$.isPlainObject(value))return(false);properties.initialized=false;privateMethods.setReturnMode(object,(value.returnMode!=null)?value.returnMode:options.returnMode);privateMethods.setValues(object,(value.values!=null)?value.values:options.values);privateMethods.setEventChange(object,(value.change!=null)?value.change:options.change);properties.initialized=true;},setIsValid:function(object,value)
64{var properties=object.data('properties');if(properties.isValid!=value&&properties.initialized)
65{properties.isValid=value;if(properties.isValid)
66{if(properties.isCB)
67{object.parent().removeClass('ui-inputCheckbox ui-error');}
68else
69{object.removeClass('ui-error');}}
70else
71{if(properties.isCB)
72{object.parent().addClass('ui-inputCheckbox ui-error');}
73else
74{object.addClass('ui-error');}}}
75return(properties.isValid);},setReturnMode:function(object,value)
76{var options=object.data('options'),properties=object.data('properties');if((!properties.initialized||options.returnMode!=value)&&(value=='selected'||value=='notSelected'))
77{options.returnMode=value;}
78return(options.returnMode);},setValues:function(object,value)
79{var options=object.data('options');if(value.forced!=null)options.values.forced=value.forced;if(value.checked!=null)options.values.checked=value.checked;if(value.unchecked!=null)options.values.unchecked=value.unchecked;return(options.values);},setValue:function(object,id,value,apply)
80{var options=object.data('options'),properties=object.data('properties');if(apply)
81{if(id==':all'||id==':none'||id==':invert')
82{switch(id)
83{case':all':properties.checkboxList.attr('checked',true);break;case':none':properties.checkboxList.attr('checked',false);break;case':invert':properties.checkboxList.each(function()
84{$(this).attr('checked',!$(this).attr('checked'));});break;}}
85else if($.isArray(value)&&!properties.isCB)
86{properties.checkboxList.attr('checked',false);for(var i=0;i<value.length;i++)
87{if(value[i].id!=null&&value[i].value!=null)
88{if($('#'+value[i].id).attr('value')==value[i].value)$('#'+value[i].id).attr('checked',true);}
89else
90{properties.checkboxList.filter('[value='+value[i]+']').attr('checked',true);}}}
91else
92{if(options.values.checked==value)
93{if(properties.isCB)
94{properties.checkboxList.attr('checked',true);}
95else
96{if(id=='')
97{properties.checkboxList.attr('checked',true);}
98else
99{properties.checkboxList.filter('#'+id).attr('checked',true);}}}
100else
101{if(properties.isCB)
102{properties.checkboxList.attr('checked',false);}
103else
104{if(id=='')
105{properties.checkboxList.attr('checked',false);}
106else
107{properties.checkboxList.filter('#'+id).attr('checked',false);}}}}}
108if(options.change)object.trigger('inputCheckboxChange',{id:id,state:value});return(true);},setEventChange:function(object,value)
109{var options=object.data('options');options.change=value;object.unbind('inputCheckboxChange');if(value)object.bind('inputCheckboxChange',options.change);return(options.change);}};$.fn.inputCheckbox=function(method)
110{if(publicMethods[method])
111{return publicMethods[method].apply(this,Array.prototype.slice.call(arguments,1));}
112else if(typeof method==='object'||!method)
113{return publicMethods.init.apply(this,arguments);}
114else
115{$.error('Method '+method+' does not exist on jQuery.inputCheckbox');}}})(jQuery);
Note: See TracBrowser for help on using the repository browser.