1 | /* file: ui.inputList.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={serverUrl:'',autoLoad:true,listMaxWidth:0,listMaxHeight:0,multiple:false,downArrow:'⇓',popupMode:'click',colsWidth:[],colsDisplayed:[],colsCss:[],disabled:false,popup:null,change:null,load:null,returnMode:'selected'};$this.data('options',options);if(!properties) |
---|
6 | {$this.data('properties',{index:-1,initialized:false,selectorVisible:false,items:[],mouseOver:false,isValid:true,firstPopup:true});properties=$this.data('properties');} |
---|
7 | if(!objects) |
---|
8 | {objects={container:$('<div/>',{'class':'ui-inputList',tabindex:0,css:{width:'100%'}}).bind('click.inputList',function() |
---|
9 | {privateMethods.displaySelector($this,!$this.data('properties').selectorVisible);$(this).focus();}),containerValue:$('<div/>',{html:' ','class':'ui-inputList-value',css:{overflow:'hidden'}}),containerList:null,containerArrow:$('<div/>',{html:'⇓','class':'ui-inputList-arrow',css:{'float':'right',cursor:'pointer'}}).bind('mousedown',function() |
---|
10 | {$(this).addClass('ui-inputList-arrow-active');}).bind('mouseup',function() |
---|
11 | {$(this).removeClass('ui-inputList-arrow-active');}),listContainer:$('<div/>',{html:"",'class':'ui-inputList-list',css:{overflow:"auto",display:'none',position:'absolute'}}),list:$('<ul/>',{css:{listStyle:'none',padding:'0px',margin:'0px'}})};} |
---|
12 | $this.data('objects',objects);privateMethods.setOptions($this,opt);if($this.text()!='') |
---|
13 | {var tmp=$.parseJSON($.trim($this.text())),selectedValues=[],values=[];if($.isArray(tmp)) |
---|
14 | {values=tmp;} |
---|
15 | else if(tmp.values!=null) |
---|
16 | {values=tmp.values;} |
---|
17 | if(tmp.selected!=null)selectedValues=tmp.selected;privateMethods.setItems($this,values);privateMethods.setValue($this,selectedValues);} |
---|
18 | $this.html('').append(objects.container.append(objects.containerArrow).append(objects.containerValue)).append(objects.listContainer.append(objects.list));});},destroy:function() |
---|
19 | {return this.each(function() |
---|
20 | {var $this=$(this),objects=$this.data('objects');objects.container.unbind().remove();objects.list.children().unbind();objects.listContainer.remove();$this.unbind('.inputList').css({width:'',height:''});});},options:function(value) |
---|
21 | {return this.each(function() |
---|
22 | {privateMethods.setOptions($(this),value);});},autoLoad:function(value) |
---|
23 | {if(value!=null) |
---|
24 | {return this.each(function() |
---|
25 | {privateMethods.setAutoLoad($(this),value);});} |
---|
26 | else |
---|
27 | {var options=this.data('options');if(options) |
---|
28 | {return(options.autoLoad);} |
---|
29 | else |
---|
30 | {return(true);}}},listMaxWidth:function(value) |
---|
31 | {if(value!=null) |
---|
32 | {return this.each(function() |
---|
33 | {privateMethods.setListMaxWidth($(this),value);});} |
---|
34 | else |
---|
35 | {var options=this.data('options');if(options) |
---|
36 | {return(options.listMaxWidth);} |
---|
37 | else |
---|
38 | {return(0);}}},listMaxHeight:function(value) |
---|
39 | {if(value!=null) |
---|
40 | {return this.each(function() |
---|
41 | {privateMethods.setListMaxHeight($(this),value);});} |
---|
42 | else |
---|
43 | {var options=this.data('options');if(options) |
---|
44 | {return(options.listMaxHeight);} |
---|
45 | else |
---|
46 | {return(0);}}},serverUrl:function(value) |
---|
47 | {if(value!=null) |
---|
48 | {return this.each(function() |
---|
49 | {privateMethods.setServerUrl($(this),value);});} |
---|
50 | else |
---|
51 | {var options=this.data('options');if(options) |
---|
52 | {return(options.serverUrl);} |
---|
53 | else |
---|
54 | {return('');}}},cols:function() |
---|
55 | {var options=this.data('options'),properties=this.data('properties');if(!options.multiple) |
---|
56 | {return(properties.items[properties.index].cols);} |
---|
57 | else |
---|
58 | {var listCols=[];for(var i=0;i<properties.index.length;i++) |
---|
59 | {listCols.push(properties.items[properties.index[i]].cols);} |
---|
60 | return(listCols);}},popupMode:function(value) |
---|
61 | {if(value!=null) |
---|
62 | {return this.each(function() |
---|
63 | {privateMethods.setPopupMode($(this),value);});} |
---|
64 | else |
---|
65 | {var options=this.data('options');if(options) |
---|
66 | {return(options.popupMode);} |
---|
67 | else |
---|
68 | {return(0);}}},downArrow:function(value) |
---|
69 | {if(value!=null) |
---|
70 | {return this.each(function() |
---|
71 | {privateMethods.setDownArrow($(this),value);});} |
---|
72 | else |
---|
73 | {var options=this.data('options');if(options) |
---|
74 | {return(options.downArrow);} |
---|
75 | else |
---|
76 | {return('');}}},returnMode:function(value) |
---|
77 | {if(value!=null) |
---|
78 | {return this.each(function() |
---|
79 | {privateMethods.setReturnMode($(this),value);});} |
---|
80 | else |
---|
81 | {var options=this.data('options');if(options) |
---|
82 | {return(options.returnMode);} |
---|
83 | else |
---|
84 | {return('selected');}}},colsWidth:function(value) |
---|
85 | {if(value!=null) |
---|
86 | {return this.each(function() |
---|
87 | {privateMethods.setColsWidth($(this),value);});} |
---|
88 | else |
---|
89 | {var options=this.data('options');if(options) |
---|
90 | {return(options.colsWidth);} |
---|
91 | else |
---|
92 | {return('');}}},colsDisplayed:function(value) |
---|
93 | {if(value!=null) |
---|
94 | {return this.each(function() |
---|
95 | {privateMethods.setColsDisplayed($(this),value);});} |
---|
96 | else |
---|
97 | {var options=this.data('options');if(options) |
---|
98 | {return(options.colsDisplayed);} |
---|
99 | else |
---|
100 | {return('');}}},colsCss:function(value) |
---|
101 | {if(value!=null) |
---|
102 | {return this.each(function() |
---|
103 | {privateMethods.setColsCss($(this),value);});} |
---|
104 | else |
---|
105 | {var options=this.data('options');if(options) |
---|
106 | {return(options.colsCss);} |
---|
107 | else |
---|
108 | {return('');}}},items:function(value) |
---|
109 | {if(value!=null) |
---|
110 | {return this.each(function() |
---|
111 | {privateMethods.setItems($(this),value);});} |
---|
112 | else |
---|
113 | {var properties=this.data('properties');if(properties) |
---|
114 | {return(properties.items);} |
---|
115 | else |
---|
116 | {return('');}}},value:function(value) |
---|
117 | {if(value!=null) |
---|
118 | {return this.each(function() |
---|
119 | {privateMethods.setValue($(this),value);});} |
---|
120 | else |
---|
121 | {var properties=this.data('properties'),options=this.data('options');if(properties&&properties.index!=null&&!options.multiple&&properties.index>-1&&properties.index<properties.items.length) |
---|
122 | {return(properties.items[properties.index].value);} |
---|
123 | else if(properties&&properties.index!=null&&options.multiple) |
---|
124 | {var returned=[];if(options.returnMode=='selected') |
---|
125 | {for(var i=0;i<properties.index.length;i++) |
---|
126 | {if(properties.index[i]>-1&&properties.index[i]<properties.items.length) |
---|
127 | returned.push(properties.items[properties.index[i]].value);}} |
---|
128 | else |
---|
129 | {for(var i=0;i<properties.items.length;i++) |
---|
130 | {if($.inArray(i,properties.index)==-1) |
---|
131 | returned.push(properties.items[i].value);}} |
---|
132 | return(returned);} |
---|
133 | else |
---|
134 | {return(null);}}},isValid:function(value) |
---|
135 | {if(value!=null) |
---|
136 | {return this.each(function() |
---|
137 | {privateMethods.setIsValid($(this),value);});} |
---|
138 | else |
---|
139 | {var properties=this.data('properties');return(properties.isValid);}},load:function(value) |
---|
140 | {if(value&&$.isFunction(value)) |
---|
141 | {return this.each(function() |
---|
142 | {privateMethods.setEventLoad($(this),value);});} |
---|
143 | else |
---|
144 | {privateMethods.load(this);}},popup:function(value) |
---|
145 | {if(value&&$.isFunction(value)) |
---|
146 | {return this.each(function() |
---|
147 | {privateMethods.setEventPopup($(this),value);});} |
---|
148 | else |
---|
149 | {var options=this.data('options');if(options) |
---|
150 | {return(options.popup);} |
---|
151 | else |
---|
152 | {return(null);}}},change:function(value) |
---|
153 | {if(value&&$.isFunction(value)) |
---|
154 | {return this.each(function() |
---|
155 | {privateMethods.setEventChange($(this),value);});} |
---|
156 | else |
---|
157 | {var options=this.data('options');if(options) |
---|
158 | {return(options.change);} |
---|
159 | else |
---|
160 | {return(null);}}},numberOfItems:function() |
---|
161 | {var properties=this.data('properties');if(properties) |
---|
162 | {return(properties.items.length);} |
---|
163 | else |
---|
164 | {return(null);}},properties:function(value) |
---|
165 | {var properties=this.data('properties'),options=this.data('options');if(properties&&value==':first'&&properties.items.length>0) |
---|
166 | {return(properties.items[0]);} |
---|
167 | else if(properties&&properties.index!=null&&(value==':selected'||value==null)&&properties.items.length>0) |
---|
168 | {if(!options.multiple&&properties.index>-1&&properties.index<properties.items.length) |
---|
169 | {return(properties.items[properties.index]);} |
---|
170 | else if(options.multiple) |
---|
171 | {var returned=[];for(var i=0;i<properties.index.length;i++) |
---|
172 | {if(properties.index[i]>-1&&properties.index<properties.items.length) |
---|
173 | returned.push(properties.items[properties.index[i]]);} |
---|
174 | return(returned);} |
---|
175 | return(null);} |
---|
176 | else if(properties&&value!=null) |
---|
177 | {var index=privateMethods.findIndexByValue(this,value);if(index>-1) |
---|
178 | {return(properties.items[index]);} |
---|
179 | return(null);} |
---|
180 | else |
---|
181 | {return(null);}}};var privateMethods={setOptions:function(object,value) |
---|
182 | {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.setAutoLoad(object,(value.autoLoad!=null)?value.autoLoad:options.autoLoad);privateMethods.setListMaxWidth(object,(value.listMaxWidth!=null)?value.listMaxWidth:options.listMaxWidth);privateMethods.setListMaxHeight(object,(value.listMaxHeight!=null)?value.listMaxHeight:options.listMaxHeight);privateMethods.setServerUrl(object,(value.serverUrl!=null)?value.serverUrl:options.serverUrl);privateMethods.setPopupMode(object,(value.popupMode!=null)?value.popupMode:options.popupMode);privateMethods.setDownArrow(object,(value.downArrow!=null)?value.downArrow:options.downArrow);privateMethods.setEventPopup(object,(value.popup!=null)?value.popup:options.popup);privateMethods.setEventChange(object,(value.change!=null)?value.change:options.change);privateMethods.setEventLoad(object,(value.load!=null)?value.load:options.load);privateMethods.setColsWidth(object,(value.colsWidth!=null)?value.colsWidth:options.colsWidth);privateMethods.setColsDisplayed(object,(value.colsDisplayed!=null)?value.colsDisplayed:options.colsDisplayed);privateMethods.setColsCss(object,(value.colsCss!=null)?value.colsCss:options.colsCss);privateMethods.setItems(object,(value.items!=null)?value.items:options.items);privateMethods.setMultiple(object,(value.multiple!=null)?value.multiple:options.multiple);if(options.autoLoad)privateMethods.load(object);properties.initialized=true;},setIsValid:function(object,value) |
---|
183 | {var objects=object.data('objects'),properties=object.data('properties');if(properties.isValid!=value) |
---|
184 | {properties.isValid=value;if(properties.isValid) |
---|
185 | {objects.container.removeClass('ui-error');} |
---|
186 | else |
---|
187 | {objects.container.addClass('ui-error');}} |
---|
188 | return(properties.isValid);},setAutoLoad:function(object,value) |
---|
189 | {var options=object.data('options'),properties=object.data('properties');if((!properties.initialized||options.autoLoad!=value)&&(value==true||value==false)) |
---|
190 | {options.autoLoad=value;} |
---|
191 | return(options.autoLoad);},setReturnMode:function(object,value) |
---|
192 | {var options=object.data('options'),properties=object.data('properties');if((!properties.initialized||options.returnMode!=value)&&(value=='selected'||value=='notSelected')) |
---|
193 | {options.returnMode=value;} |
---|
194 | return(options.returnMode);},setColsWidth:function(object,value) |
---|
195 | {var options=object.data('options'),properties=object.data('properties'),width=0;if((!properties.initialized||options.colsWidth!=value)&&$.isArray(value)) |
---|
196 | {options.colsWidth=value;} |
---|
197 | return(options.colsWidth);},setColsDisplayed:function(object,value) |
---|
198 | {var options=object.data('options'),properties=object.data('properties');if((!properties.initialized||options.colsDisplayed!=value)&&$.isArray(value)) |
---|
199 | {options.colsDisplayed=value;} |
---|
200 | return(options.colsDisplayed);},setColsCss:function(object,value) |
---|
201 | {var options=object.data('options'),properties=object.data('properties');if((!properties.initialized||options.colsCss!=value)&&$.isArray(value)) |
---|
202 | {options.colsCss=value;} |
---|
203 | return(options.colsCss);},setListMaxWidth:function(object,value) |
---|
204 | {var options=object.data('options'),properties=object.data('properties'),objects=object.data('objects');if((!properties.initialized||options.listMaxWidth!=value)&&value>=0) |
---|
205 | {options.listMaxWidth=value;if(options.listMaxWidth>0) |
---|
206 | {objects.listContainer.css('max-width',options.listMaxWidth+'px');} |
---|
207 | else |
---|
208 | {objects.listContainer.css('max-width','');}} |
---|
209 | return(options.listMaxWidth);},setListMaxHeight:function(object,value) |
---|
210 | {var options=object.data('options'),properties=object.data('properties'),objects=object.data('objects');if((!properties.initialized||options.listMaxHeight!=value)&&value>=0) |
---|
211 | {options.listMaxHeight=value;if(options.listMaxHeight>0) |
---|
212 | {objects.listContainer.css('max-height',options.listMaxHeight+'px');} |
---|
213 | else |
---|
214 | {objects.listContainer.css('max-height','');}} |
---|
215 | return(options.listMaxHeight);},setServerUrl:function(object,value) |
---|
216 | {var options=object.data('options'),properties=object.data('properties');if(!properties.initialized||options.serverUrl!=value) |
---|
217 | {options.serverUrl=value;if(options.autoLoad&&properties.initialized)privateMethods.load(object);} |
---|
218 | return(options.serverUrl);},setMultiple:function(object,value) |
---|
219 | {var options=object.data('options'),properties=object.data('properties'),objects=object.data('objects');if((!properties.initialized||options.multiple!=value)&&(value==true||value==false)) |
---|
220 | {if(!value) |
---|
221 | {properties.index=-1;if(objects.containerList!=null) |
---|
222 | {objects.containerList.remove();objects.containerList=null;}} |
---|
223 | else |
---|
224 | {properties.index=[];objects.listContainer.addClass('ui-inputList-multiple');if(objects.containerList==null) |
---|
225 | {objects.containerList=$('<ul/>',{html:'<li> </li>'});objects.containerValue.html('').append(objects.containerList);}} |
---|
226 | options.multiple=value;} |
---|
227 | return(options.multiple);},setPopupMode:function(object,value) |
---|
228 | {var options=object.data('options'),properties=object.data('properties'),objects=object.data('objects');if((!properties.initialized||options.popupMode!=value)&&(value=='click'||value=='mouseout')) |
---|
229 | {options.popupMode=value;if(value=='mouseout') |
---|
230 | {objects.listContainer.unbind('mouseleave.inputList').unbind('mouseenter.inputList').bind('mouseleave.inputList',function() |
---|
231 | {privateMethods.displaySelector(object,false);});} |
---|
232 | else |
---|
233 | {objects.listContainer.unbind('mouseleave.inputList').bind('mouseleave.inputList',function() |
---|
234 | {properties.mouseOver=false;}).bind('mouseenter.inputList',function() |
---|
235 | {properties.mouseOver=true;});$(document).bind('focusout focusin',function(event) |
---|
236 | {if(!properties.mouseOver)privateMethods.displaySelector(object,false);event.stopPropagation();});}} |
---|
237 | return(options.popupMode);},setDownArrow:function(object,value) |
---|
238 | {var options=object.data('options'),properties=object.data('properties'),objects=object.data('objects');if(!properties.initialized||options.downArrow!=value) |
---|
239 | {options.downArrow=value;objects.containerArrow.html(options.downArrow);} |
---|
240 | return(options.downArrow);},setItems:function(object,value) |
---|
241 | {var properties=object.data('properties');if(value==''||value==null) |
---|
242 | {value=[];} |
---|
243 | else if(!$.isArray(value)) |
---|
244 | {try |
---|
245 | {value=$.parseJSON($.trim(value));} |
---|
246 | catch(e) |
---|
247 | {return(false);}} |
---|
248 | privateMethods.listClear(object);if(value.length>0)privateMethods.listAddItems(object,value);},setValue:function(object,value,trigger) |
---|
249 | {var options=object.data('options'),properties=object.data('properties'),objects=object.data('objects'),index=-1;re=/^(:invert|:all|:none)(?:(=|<|>)(\d+))$/i;target=re.exec(value);if(target!=null)value=target[1];switch(value) |
---|
250 | {case':first':if(properties.items.length>0)index=0;break;case':last':index=properties.items.length-1;break;case':invert':if(!options.multiple)return(false);properties.index=[];objects.list.find('.ui-inputList-item').each(function() |
---|
251 | {var $this=$(this),apply=true;if(target!=null) |
---|
252 | {switch(target[2]) |
---|
253 | {case'=':apply=($this.attr('level')==target[3]);break;case'>':apply=($this.attr('level')>=target[3]);break;case'<':apply=($this.attr('level')<=target[3]);break;}} |
---|
254 | if(apply) |
---|
255 | {if($this.hasClass('ui-inputList-selected-item')) |
---|
256 | {$this.removeClass('ui-inputList-selected-item');} |
---|
257 | else |
---|
258 | {$this.addClass('ui-inputList-selected-item');tmp=privateMethods.findIndexByValue(object,$this.attr('idvalue'));if(tmp>-1)properties.index.push(tmp);}}});privateMethods.setValue(object,[],false);return(false);break;case':none':if(!options.multiple)return(false);properties.index=[];objects.list.find('.ui-inputList-selected-item').each(function() |
---|
259 | {var $this=$(this),apply=true;if(target!=null) |
---|
260 | {switch(target[2]) |
---|
261 | {case'=':apply=($this.attr('level')==target[3]);break;case'>':apply=($this.attr('level')>=target[3]);break;case'<':apply=($this.attr('level')<=target[3]);break;}} |
---|
262 | if(apply)$this.removeClass('ui-inputList-selected-item');});privateMethods.setValue(object,[],false);return(false);break;case':all':if(!options.multiple)return(false);properties.index=[];objects.list.find('.ui-inputList-item').each(function() |
---|
263 | {var $this=$(this),apply=true;if(target!=null) |
---|
264 | {switch(target[2]) |
---|
265 | {case'=':apply=($this.attr('level')==target[3]);break;case'>':apply=($this.attr('level')>=target[3]);break;case'<':apply=($this.attr('level')<=target[3]);break;}} |
---|
266 | if(apply) |
---|
267 | {tmp=privateMethods.findIndexByValue(object,$this.attr('idvalue'));if(tmp>-1)properties.index.push(tmp);$this.addClass('ui-inputList-selected-item');}});privateMethods.setValue(object,[],false);return(false);break;default:if($.isArray(value)&&options.multiple) |
---|
268 | {index=[];for(var i=0;i<value.length;i++) |
---|
269 | {tmp=privateMethods.findIndexByValue(object,value[i]);if(tmp>-1)index.push(tmp);}} |
---|
270 | else |
---|
271 | {index=privateMethods.findIndexByValue(object,value);} |
---|
272 | break;} |
---|
273 | if(!options.multiple&&(!properties.initialized||properties.index!=index)&&index>-1) |
---|
274 | {objects.list.find('.ui-inputList-selected-item').removeClass('ui-inputList-selected-item');objects.list.find('[idvalue="'+value+'"]').addClass('ui-inputList-selected-item');properties.index=index;privateMethods.setItemContent(object,index,objects.containerValue);if(trigger)object.trigger('inputListChange',[properties.items[properties.index].value]);if(properties.index>-1)return(properties.items[properties.index].value);} |
---|
275 | else if(options.multiple) |
---|
276 | {if(!$.isArray(index)) |
---|
277 | {if(index<0||index==null)return(-1);index=[index];} |
---|
278 | tmp=[];for(var i=0;i<index.length;i++) |
---|
279 | {var item=objects.list.find('[idvalue="'+properties.items[index[i]].value+'"]');tmp.push(properties.items[index[i]].value);if(item.hasClass('ui-inputList-selected-item')) |
---|
280 | {item.removeClass('ui-inputList-selected-item');tmpIndex=$.inArray(index[i],properties.index);if(tmpIndex>-1)properties.index.splice(tmpIndex,1);} |
---|
281 | else |
---|
282 | {item.addClass('ui-inputList-selected-item');properties.index.push(index[i]);}} |
---|
283 | objects.containerList.html('');objects.list.children('.ui-inputList-selected-item').each(function() |
---|
284 | {var value=$(this).attr('idvalue'),index=privateMethods.findIndexByValue(object,value),li=$('<li/>',{'class':'ui-inputList-selected-item'});privateMethods.setItemContent(object,index,li);objects.containerList.append(li.prepend($('<span/>',{'html':'x','class':'ui-inputList-delete-item'}).bind('click.inputList',{object:object,value:value},function(event) |
---|
285 | {event.stopPropagation();privateMethods.setValue(event.data.object,event.data.value,true);})));});if(objects.containerList.children().length==0)objects.containerList.append('<li> </li>');if(trigger)object.trigger('inputListChange',[tmp]);return(tmp);} |
---|
286 | return(null);},displaySelector:function(object,value) |
---|
287 | {var options=object.data('options'),properties=object.data('properties'),objects=object.data('objects'),scrollBarWidth=0;if(properties.selectorVisible!=value) |
---|
288 | {properties.selectorVisible=value;if(properties.selectorVisible&&properties.items.length>0) |
---|
289 | {var index=0;objects.listContainer.css({display:'block','min-width':objects.listContainer.parent().css('width')});if($.isArray(properties.index)) |
---|
290 | {if(properties.index.length>0)index=properties.index[0];} |
---|
291 | else if(properties.index>-1) |
---|
292 | {index=properties.index;} |
---|
293 | scrollBarWidth=objects.listContainer.width()-objects.list.width();if(scrollBarWidth>0&&properties.firstPopup) |
---|
294 | {objects.listContainer.width(objects.listContainer.width()+scrollBarWidth);properties.firstPopup=false;} |
---|
295 | objects.listContainer.scrollTop(objects.listContainer.scrollTop()+objects.list.find('[idValue="'+properties.items[index].value+'"]').position().top);} |
---|
296 | else |
---|
297 | {objects.listContainer.css('display','none');} |
---|
298 | if(options.popup)object.trigger('inputListPopup',[properties.selectorVisible]);} |
---|
299 | return(properties.selectorVisible);},load:function(object) |
---|
300 | {var options=object.data('options'),properties=object.data('properties'),objects=object.data('objects');if(options.serverUrl=='')return(false);$.ajax({type:"POST",url:options.serverUrl,async:true,success:function(msg) |
---|
301 | {privateMethods.setItems(object,msg);properties.initialized=false;if(options.multiple) |
---|
302 | {privateMethods.setValue(object,':none');} |
---|
303 | else |
---|
304 | {privateMethods.setValue(object,':first');} |
---|
305 | properties.initialized=true;if(options.load)object.trigger('inputListLoad');},error:function(msg) |
---|
306 | {objects.listContainer.html('Error ! '+msg);}});},listClear:function(object) |
---|
307 | {var objects=object.data('objects'),options=object.data('options'),properties=object.data('properties');objects.list.children().unbind();objects.list.html('');if(options.multiple) |
---|
308 | {properties.index=[];} |
---|
309 | else |
---|
310 | {properties.index=-1;} |
---|
311 | properties.items=[];properties.firstPopup=true;},listAddItems:function(object,listItems) |
---|
312 | {var options=object.data('options'),properties=object.data('properties'),objects=object.data('objects'),width=0;for(var i=0;i<listItems.length;i++) |
---|
313 | {properties.items.push({value:listItems[i].value,cols:listItems[i].cols});var content=$('<div/>',{'class':'ui-inputList-value'}),li=$('<li/>',{'class':'ui-inputList-item','idValue':listItems[i].value}).bind('click.inputList',{object:object},function(event) |
---|
314 | {privateMethods.setValue(event.data.object,$(this).attr('idValue'),true);if(options.multiple) |
---|
315 | {} |
---|
316 | else |
---|
317 | {privateMethods.displaySelector(event.data.object,false);} |
---|
318 | if(options.multiple)objects.container.focus();});for(var j=0;j<listItems[i].cols.length;j++) |
---|
319 | {content.append($('<span/>',{html:listItems[i].cols[j],css:{width:privateMethods.getColWidth(object,j)},'class':privateMethods.getColCss(object,j)}));} |
---|
320 | li.append(content);if(options.multiple) |
---|
321 | {li.children().prepend('<div class="ui-inputList-check"></div>');} |
---|
322 | objects.list.append(li);}},findIndexByValue:function(object,value) |
---|
323 | {var properties=object.data('properties');for(var i=0;i<properties.items.length;i++) |
---|
324 | {if(properties.items[i].value==value)return(i);} |
---|
325 | return(-1);},setEventPopup:function(object,value) |
---|
326 | {var options=object.data('options');options.popup=value;object.unbind('inputListPopup');if(value)object.bind('inputListPopup',options.popup);return(options.popup);},setEventChange:function(object,value) |
---|
327 | {var options=object.data('options');options.change=value;object.unbind('inputListChange');if(value)object.bind('inputListChange',options.change);return(options.change);},setEventLoad:function(object,value) |
---|
328 | {var options=object.data('options');options.load=value;object.unbind('inputListLoad');if(value)object.bind('inputListLoad',options.load);return(options.load);},getColWidth:function(object,index) |
---|
329 | {var options=object.data('options');if(index>=0&&index<options.colsWidth.length&&options.colsWidth[index]!=''&&options.colsWidth[index]!=0) |
---|
330 | {return(options.colsWidth[index]+'px');} |
---|
331 | return('');},getColCss:function(object,index) |
---|
332 | {var options=object.data('options');if(index>=0&&index<options.colsCss.length) |
---|
333 | {return(options.colsCss[index]);} |
---|
334 | return('');},getColContent:function(object,itemIndex,index) |
---|
335 | {var properties=object.data('properties');if(index>=0&&index<=properties.items[itemIndex].cols.length) |
---|
336 | {return(properties.items[itemIndex].cols[index]);} |
---|
337 | return('');},setItemContent:function(object,index,container) |
---|
338 | {var options=object.data('options'),properties=object.data('properties'),colContent='',colsDisplayed=[];container.html('');if(options.colsDisplayed.length==0) |
---|
339 | {for(var j=0;j<properties.items[index].cols.length;j++) |
---|
340 | {colsDisplayed.push(j);}} |
---|
341 | else |
---|
342 | {colsDisplayed=options.colsDisplayed;} |
---|
343 | for(var j=0;j<colsDisplayed.length;j++) |
---|
344 | {colContent=privateMethods.getColContent(object,index,colsDisplayed[j]);if(colContent!=null) |
---|
345 | {container.append($('<span/>',{'html':colContent,css:{width:privateMethods.getColWidth(object,colsDisplayed[j])},'class':privateMethods.getColCss(object,colsDisplayed[j])}));}}}};$.fn.inputList=function(method) |
---|
346 | {if(publicMethods[method]) |
---|
347 | {return publicMethods[method].apply(this,Array.prototype.slice.call(arguments,1));} |
---|
348 | else if(typeof method==='object'||!method) |
---|
349 | {return publicMethods.init.apply(this,arguments);} |
---|
350 | else |
---|
351 | {$.error('Method '+method+' does not exist on jQuery.inputList');}}})(jQuery); |
---|