source: extensions/GrumPluginClasses/js/ui.inputList.min.js @ 10338

Last change on this file since 10338 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: 23.1 KB
Line 
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');}
7if(!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;}
15else if(tmp.values!=null)
16{values=tmp.values;}
17if(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);});}
26else
27{var options=this.data('options');if(options)
28{return(options.autoLoad);}
29else
30{return(true);}}},listMaxWidth:function(value)
31{if(value!=null)
32{return this.each(function()
33{privateMethods.setListMaxWidth($(this),value);});}
34else
35{var options=this.data('options');if(options)
36{return(options.listMaxWidth);}
37else
38{return(0);}}},listMaxHeight:function(value)
39{if(value!=null)
40{return this.each(function()
41{privateMethods.setListMaxHeight($(this),value);});}
42else
43{var options=this.data('options');if(options)
44{return(options.listMaxHeight);}
45else
46{return(0);}}},serverUrl:function(value)
47{if(value!=null)
48{return this.each(function()
49{privateMethods.setServerUrl($(this),value);});}
50else
51{var options=this.data('options');if(options)
52{return(options.serverUrl);}
53else
54{return('');}}},cols:function()
55{var options=this.data('options'),properties=this.data('properties');if(!options.multiple)
56{return(properties.items[properties.index].cols);}
57else
58{var listCols=[];for(var i=0;i<properties.index.length;i++)
59{listCols.push(properties.items[properties.index[i]].cols);}
60return(listCols);}},popupMode:function(value)
61{if(value!=null)
62{return this.each(function()
63{privateMethods.setPopupMode($(this),value);});}
64else
65{var options=this.data('options');if(options)
66{return(options.popupMode);}
67else
68{return(0);}}},downArrow:function(value)
69{if(value!=null)
70{return this.each(function()
71{privateMethods.setDownArrow($(this),value);});}
72else
73{var options=this.data('options');if(options)
74{return(options.downArrow);}
75else
76{return('');}}},returnMode:function(value)
77{if(value!=null)
78{return this.each(function()
79{privateMethods.setReturnMode($(this),value);});}
80else
81{var options=this.data('options');if(options)
82{return(options.returnMode);}
83else
84{return('selected');}}},colsWidth:function(value)
85{if(value!=null)
86{return this.each(function()
87{privateMethods.setColsWidth($(this),value);});}
88else
89{var options=this.data('options');if(options)
90{return(options.colsWidth);}
91else
92{return('');}}},colsDisplayed:function(value)
93{if(value!=null)
94{return this.each(function()
95{privateMethods.setColsDisplayed($(this),value);});}
96else
97{var options=this.data('options');if(options)
98{return(options.colsDisplayed);}
99else
100{return('');}}},colsCss:function(value)
101{if(value!=null)
102{return this.each(function()
103{privateMethods.setColsCss($(this),value);});}
104else
105{var options=this.data('options');if(options)
106{return(options.colsCss);}
107else
108{return('');}}},items:function(value)
109{if(value!=null)
110{return this.each(function()
111{privateMethods.setItems($(this),value);});}
112else
113{var properties=this.data('properties');if(properties)
114{return(properties.items);}
115else
116{return('');}}},value:function(value)
117{if(value!=null)
118{return this.each(function()
119{privateMethods.setValue($(this),value);});}
120else
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);}
123else 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)
127returned.push(properties.items[properties.index[i]].value);}}
128else
129{for(var i=0;i<properties.items.length;i++)
130{if($.inArray(i,properties.index)==-1)
131returned.push(properties.items[i].value);}}
132return(returned);}
133else
134{return(null);}}},isValid:function(value)
135{if(value!=null)
136{return this.each(function()
137{privateMethods.setIsValid($(this),value);});}
138else
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);});}
143else
144{privateMethods.load(this);}},popup:function(value)
145{if(value&&$.isFunction(value))
146{return this.each(function()
147{privateMethods.setEventPopup($(this),value);});}
148else
149{var options=this.data('options');if(options)
150{return(options.popup);}
151else
152{return(null);}}},change:function(value)
153{if(value&&$.isFunction(value))
154{return this.each(function()
155{privateMethods.setEventChange($(this),value);});}
156else
157{var options=this.data('options');if(options)
158{return(options.change);}
159else
160{return(null);}}},numberOfItems:function()
161{var properties=this.data('properties');if(properties)
162{return(properties.items.length);}
163else
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]);}
167else 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]);}
170else 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)
173returned.push(properties.items[properties.index[i]]);}
174return(returned);}
175return(null);}
176else if(properties&&value!=null)
177{var index=privateMethods.findIndexByValue(this,value);if(index>-1)
178{return(properties.items[index]);}
179return(null);}
180else
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');}
186else
187{objects.container.addClass('ui-error');}}
188return(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;}
191return(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;}
194return(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;}
197return(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;}
200return(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;}
203return(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');}
207else
208{objects.listContainer.css('max-width','');}}
209return(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');}
213else
214{objects.listContainer.css('max-height','');}}
215return(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);}
218return(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;}}
223else
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);}}
226options.multiple=value;}
227return(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);});}
232else
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();});}}
237return(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);}
240return(options.downArrow);},setItems:function(object,value)
241{var properties=object.data('properties');if(value==''||value==null)
242{value=[];}
243else if(!$.isArray(value))
244{try
245{value=$.parseJSON($.trim(value));}
246catch(e)
247{return(false);}}
248privateMethods.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;}}
254if(apply)
255{if($this.hasClass('ui-inputList-selected-item'))
256{$this.removeClass('ui-inputList-selected-item');}
257else
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;}}
262if(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;}}
266if(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);}}
270else
271{index=privateMethods.findIndexByValue(object,value);}
272break;}
273if(!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);}
275else if(options.multiple)
276{if(!$.isArray(index))
277{if(index<0||index==null)return(-1);index=[index];}
278tmp=[];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);}
281else
282{item.addClass('ui-inputList-selected-item');properties.index.push(index[i]);}}
283objects.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);}
286return(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];}
291else if(properties.index>-1)
292{index=properties.index;}
293scrollBarWidth=objects.listContainer.width()-objects.list.width();if(scrollBarWidth>0&&properties.firstPopup)
294{objects.listContainer.width(objects.listContainer.width()+scrollBarWidth);properties.firstPopup=false;}
295objects.listContainer.scrollTop(objects.listContainer.scrollTop()+objects.list.find('[idValue="'+properties.items[index].value+'"]').position().top);}
296else
297{objects.listContainer.css('display','none');}
298if(options.popup)object.trigger('inputListPopup',[properties.selectorVisible]);}
299return(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');}
303else
304{privateMethods.setValue(object,':first');}
305properties.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=[];}
309else
310{properties.index=-1;}
311properties.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{}
316else
317{privateMethods.displaySelector(event.data.object,false);}
318if(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)}));}
320li.append(content);if(options.multiple)
321{li.children().prepend('<div class="ui-inputList-check"></div>');}
322objects.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);}
325return(-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');}
331return('');},getColCss:function(object,index)
332{var options=object.data('options');if(index>=0&&index<options.colsCss.length)
333{return(options.colsCss[index]);}
334return('');},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]);}
337return('');},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);}}
341else
342{colsDisplayed=options.colsDisplayed;}
343for(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));}
348else if(typeof method==='object'||!method)
349{return publicMethods.init.apply(this,arguments);}
350else
351{$.error('Method '+method+' does not exist on jQuery.inputList');}}})(jQuery);
Note: See TracBrowser for help on using the repository browser.