1 | /* file: ui.categorySelector.js - v1.1.0 | minified on 2011/01/28 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={autoLoad:true,galleryRoot:true,displayStatus:true,listMaxWidth:0,listMaxHeight:0,levelIndent:16,iconWidthEC:15,serverUrl:'plugins/GrumPluginClasses/gpc_ajax.php',filter:'accessible',popup:null,change:null,load:null,multiple:false,userMode:'public',popupMode:'click',displayPath:false,downArrow:'⇓'};$this.data('options',options);if(!properties) |
---|
6 | {$this.data('properties',{index:-1,initialized:false,selectorVisible:false,categories:[],labelStatus:['',''],mouseOver:false,isValid:true});properties=$this.data('properties');} |
---|
7 | if(!objects) |
---|
8 | {objects={container:$('<div/>',{'class':'ui-category-selector',tabindex:0,css:{width:'100%'}}).bind('click.categorySelector',function() |
---|
9 | {privateMethods.displaySelector($this,!$this.data('properties').selectorVisible);$(this).focus();}),containerName:$('<div/>',{html:' ','class':'ui-category-selector-name'}),containerList:null,containerStatus:$('<div/>',{'class':'ui-category-selector-status',css:{float:'right',display:(options.displayStatus)?'block':'none'}}),containerArrow:$('<div/>',{html:'⇓','class':'ui-category-selector-arrow',css:{'float':'right',cursor:'pointer'}}).bind('mousedown',function() |
---|
10 | {$(this).addClass('ui-category-selector-arrow-active');}).bind('mouseup',function() |
---|
11 | {$(this).removeClass('ui-category-selector-arrow-active');}),listContainer:$('<div/>',{html:"",'class':'ui-category-selector-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.html()!='')privateMethods.setItems($this,$this.html());$this.html('').append(objects.container.append(objects.containerArrow).append(objects.containerStatus).append(objects.containerName)).append(objects.listContainer.append(objects.list));});},destroy:function() |
---|
13 | {return this.each(function() |
---|
14 | {var $this=$(this),objects=$this.data('objects');objects.container.unbind().remove();objects.list.children().unbind();objects.listContainer.remove();$this.unbind('.categorySelector').css({width:'',height:''});});},options:function(value) |
---|
15 | {return this.each(function() |
---|
16 | {privateMethods.setOptions($(this),value);});},autoLoad:function(value) |
---|
17 | {if(value!=null) |
---|
18 | {return this.each(function() |
---|
19 | {privateMethods.setAutoLoad($(this),value);});} |
---|
20 | else |
---|
21 | {var options=this.data('options');if(options) |
---|
22 | {return(options.autoLoad);} |
---|
23 | else |
---|
24 | {return(true);}}},galleryRoot:function(value) |
---|
25 | {if(value!=null) |
---|
26 | {return this.each(function() |
---|
27 | {privateMethods.setGalleryRoot($(this),value);});} |
---|
28 | else |
---|
29 | {var options=this.data('options');if(options) |
---|
30 | {return(options.galleryRoot);} |
---|
31 | else |
---|
32 | {return(true);}}},listMaxWidth:function(value) |
---|
33 | {if(value!=null) |
---|
34 | {return this.each(function() |
---|
35 | {privateMethods.setListMaxWidth($(this),value);});} |
---|
36 | else |
---|
37 | {var options=this.data('options');if(options) |
---|
38 | {return(options.listMaxWidth);} |
---|
39 | else |
---|
40 | {return(0);}}},listMaxHeight:function(value) |
---|
41 | {if(value!=null) |
---|
42 | {return this.each(function() |
---|
43 | {privateMethods.setListMaxHeight($(this),value);});} |
---|
44 | else |
---|
45 | {var options=this.data('options');if(options) |
---|
46 | {return(options.listMaxHeight);} |
---|
47 | else |
---|
48 | {return(0);}}},displayStatus:function(value) |
---|
49 | {if(value!=null) |
---|
50 | {return this.each(function() |
---|
51 | {privateMethods.setDisplayStatus($(this),value);});} |
---|
52 | else |
---|
53 | {var options=this.data('options');if(options) |
---|
54 | {return(options.displayStatus);} |
---|
55 | else |
---|
56 | {return(true);}}},levelIndent:function(value) |
---|
57 | {if(value!=null) |
---|
58 | {return this.each(function() |
---|
59 | {privateMethods.setLevelIndent($(this),value);});} |
---|
60 | else |
---|
61 | {var options=this.data('options');if(options) |
---|
62 | {return(options.levelIndent);} |
---|
63 | else |
---|
64 | {return(0);}}},serverUrl:function(value) |
---|
65 | {if(value!=null) |
---|
66 | {return this.each(function() |
---|
67 | {privateMethods.setServerUrl($(this),value);});} |
---|
68 | else |
---|
69 | {var options=this.data('options');if(options) |
---|
70 | {return(options.serverUrl);} |
---|
71 | else |
---|
72 | {return('');}}},filter:function(value) |
---|
73 | {if(value!=null) |
---|
74 | {return this.each(function() |
---|
75 | {privateMethods.setFilter($(this),value);});} |
---|
76 | else |
---|
77 | {var options=this.data('options');if(options) |
---|
78 | {return(options.filter);} |
---|
79 | else |
---|
80 | {return('');}}},collapse:function(value) |
---|
81 | {return this.each(function() |
---|
82 | {if(!value)value=':all';privateMethods.setExpandCollapse($(this),value,'C');});},expand:function(value) |
---|
83 | {return this.each(function() |
---|
84 | {if(!value)value=':all';privateMethods.setExpandCollapse($(this),value,'E');});},iconWidthEC:function(value) |
---|
85 | {if(value!=null) |
---|
86 | {return this.each(function() |
---|
87 | {privateMethods.setIconWidthEC($(this),value);});} |
---|
88 | else |
---|
89 | {var options=this.data('options');if(options) |
---|
90 | {return(options.iconWidthEC);} |
---|
91 | else |
---|
92 | {return(0);}}},userMode:function(value) |
---|
93 | {if(value!=null) |
---|
94 | {return this.each(function() |
---|
95 | {privateMethods.setUserMode($(this),value);});} |
---|
96 | else |
---|
97 | {var options=this.data('options');if(options) |
---|
98 | {return(options.userMode);} |
---|
99 | else |
---|
100 | {return(0);}}},name:function() |
---|
101 | {var options=this.data('options'),properties=this.data('properties');if(!options.multiple) |
---|
102 | {return(properties.categories[properties.index].name);} |
---|
103 | else |
---|
104 | {var listNames=[];for(var i=0;i<properties.index.length;i++) |
---|
105 | {listNames.push(properties.categories[properties.index[i]].name);} |
---|
106 | return(listNames);}},popupMode:function(value) |
---|
107 | {if(value!=null) |
---|
108 | {return this.each(function() |
---|
109 | {privateMethods.setPopupMode($(this),value);});} |
---|
110 | else |
---|
111 | {var options=this.data('options');if(options) |
---|
112 | {return(options.popupMode);} |
---|
113 | else |
---|
114 | {return(0);}}},displayPath:function(value) |
---|
115 | {if(value!=null) |
---|
116 | {return this.each(function() |
---|
117 | {privateMethods.setDisplayPath($(this),value);});} |
---|
118 | else |
---|
119 | {var options=this.data('options');if(options) |
---|
120 | {return(options.displayPath);} |
---|
121 | else |
---|
122 | {return(0);}}},downArrow:function(value) |
---|
123 | {if(value!=null) |
---|
124 | {return this.each(function() |
---|
125 | {privateMethods.setDownArrow($(this),value);});} |
---|
126 | else |
---|
127 | {var options=this.data('options');if(options) |
---|
128 | {return(options.downArrow);} |
---|
129 | else |
---|
130 | {return('');}}},value:function(value) |
---|
131 | {if(value!=null) |
---|
132 | {return this.each(function() |
---|
133 | {privateMethods.setValue($(this),value);});} |
---|
134 | else |
---|
135 | {var properties=this.data('properties'),options=this.data('options');if(properties&&properties.index!=null&&!options.multiple&&properties.index>-1&&properties.index<properties.categories.length) |
---|
136 | {return(properties.categories[properties.index].id);} |
---|
137 | else if(properties&&properties.index!=null&&options.multiple) |
---|
138 | {var returned=[];for(var i=0;i<properties.index.length;i++) |
---|
139 | {if(properties.index[i]>-1&&properties.index[i]<properties.categories.length) |
---|
140 | returned.push(properties.categories[properties.index[i]].id);} |
---|
141 | return(returned);} |
---|
142 | else |
---|
143 | {return(null);}}},isValid:function(value) |
---|
144 | {if(value!=null) |
---|
145 | {return this.each(function() |
---|
146 | {privateMethods.setIsValid($(this),value);});} |
---|
147 | else |
---|
148 | {var properties=this.data('properties');return(properties.isValid);}},load:function(value) |
---|
149 | {if(value&&$.isFunction(value)) |
---|
150 | {return this.each(function() |
---|
151 | {privateMethods.setEventLoad($(this),value);});} |
---|
152 | else |
---|
153 | {privateMethods.load(this);}},popup:function(value) |
---|
154 | {if(value&&$.isFunction(value)) |
---|
155 | {return this.each(function() |
---|
156 | {privateMethods.setEventPopup($(this),value);});} |
---|
157 | else |
---|
158 | {var options=this.data('options');if(options) |
---|
159 | {return(options.popup);} |
---|
160 | else |
---|
161 | {return(null);}}},change:function(value) |
---|
162 | {if(value&&$.isFunction(value)) |
---|
163 | {return this.each(function() |
---|
164 | {privateMethods.setEventChange($(this),value);});} |
---|
165 | else |
---|
166 | {var options=this.data('options');if(options) |
---|
167 | {return(options.change);} |
---|
168 | else |
---|
169 | {return(null);}}},numberOfCategories:function() |
---|
170 | {var properties=this.data('properties');if(properties) |
---|
171 | {return(properties.categories.length);} |
---|
172 | else |
---|
173 | {return(null);}},properties:function(value) |
---|
174 | {var properties=this.data('properties'),options=this.data('options');if(properties&&value==':first'&&properties.categories.length>0) |
---|
175 | {return(properties.categories[0]);} |
---|
176 | else if(properties&&properties.index!=null&&(value==':selected'||value==null)&&properties.categories.length>0) |
---|
177 | {if(!options.multiple&&properties.index>-1&&properties.index<properties.categories.length) |
---|
178 | {return(properties.categories[properties.index]);} |
---|
179 | else if(options.multiple) |
---|
180 | {var returned=[];for(var i=0;i<properties.index.length;i++) |
---|
181 | {if(properties.index[i]>-1&&properties.index<properties.categories.length) |
---|
182 | returned.push(properties.categories[properties.index[i]]);} |
---|
183 | return(returned);} |
---|
184 | return(null);} |
---|
185 | else if(properties&&value>-1) |
---|
186 | {var index=privateMethods.findIndexByValue(this,value);if(index>-1) |
---|
187 | {return(properties.categories[index]);} |
---|
188 | return(null);} |
---|
189 | else |
---|
190 | {return(null);}}};var privateMethods={setOptions:function(object,value) |
---|
191 | {var properties=object.data('properties'),options=object.data('options');if(!$.isPlainObject(value))return(false);properties.initialized=false;privateMethods.setAutoLoad(object,(value.autoLoad!=null)?value.autoLoad:options.autoLoad);privateMethods.setGalleryRoot(object,(value.galleryRoot!=null)?value.galleryRoot:options.galleryRoot);privateMethods.setDisplayStatus(object,(value.displayStatus!=null)?value.displayStatus:options.displayStatus);privateMethods.setListMaxWidth(object,(value.listMaxWidth!=null)?value.listMaxWidth:options.listMaxWidth);privateMethods.setListMaxHeight(object,(value.listMaxHeight!=null)?value.listMaxHeight:options.listMaxHeight);privateMethods.setLevelIndent(object,(value.levelIndent!=null)?value.levelIndent:options.levelIndent);privateMethods.setIconWidthEC(object,(value.iconWidthEC!=null)?value.iconWidthEC:options.iconWidthEC);privateMethods.setServerUrl(object,(value.serverUrl!=null)?value.serverUrl:options.serverUrl);privateMethods.setFilter(object,(value.filter!=null)?value.filter:options.filter);privateMethods.setUserMode(object,(value.userMode!=null)?value.userMode:options.userMode);privateMethods.setPopupMode(object,(value.popupMode!=null)?value.popupMode:options.popupMode);privateMethods.setDisplayPath(object,(value.displayPath!=null)?value.displayPath:options.displayPath);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.setMultiple(object,(value.multiple!=null)?value.multiple:options.multiple);if(options.autoLoad)privateMethods.load(object);properties.initialized=true;},setIsValid:function(object,value) |
---|
192 | {var objects=object.data('objects'),properties=object.data('properties');if(properties.isValid!=value) |
---|
193 | {properties.isValid=value;if(properties.isValid) |
---|
194 | {objects.container.removeClass('ui-error');} |
---|
195 | else |
---|
196 | {objects.container.addClass('ui-error');}} |
---|
197 | return(properties.isValid);},setAutoLoad:function(object,value) |
---|
198 | {var options=object.data('options'),properties=object.data('properties');if((!properties.initialized||options.autoLoad!=value)&&(value==true||value==false)) |
---|
199 | {options.autoLoad=value;} |
---|
200 | return(options.autoLoad);},setGalleryRoot:function(object,value) |
---|
201 | {var options=object.data('options'),properties=object.data('properties');if((!properties.initialized||options.galleryRoot!=value)&&(value==true||value==false)) |
---|
202 | {options.galleryRoot=value;if(options.autoLoad&&properties.initialized)privateMethods.load(object);} |
---|
203 | return(options.galleryRoot);},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);},setDisplayStatus:function(object,value) |
---|
216 | {var options=object.data('options'),properties=object.data('properties'),objects=object.data('objects');if((!properties.initialized||options.displayStatus!=value)&&(value==true||value==false)) |
---|
217 | {options.displayStatus=value;if(options.displayStatus) |
---|
218 | {object.find('.ui-category-selector-status').show();} |
---|
219 | else |
---|
220 | {object.find('.ui-category-selector-status').hide();}} |
---|
221 | return(options.displayStatus);},setLevelIndent:function(object,value) |
---|
222 | {var options=object.data('options'),properties=object.data('properties'),objects=object.data('objects');if((!properties.initialized||options.levelIndent!=value)&&value>=0) |
---|
223 | {options.levelIndent=value;objects.list.find('.ui-category-selector-item').each(function() |
---|
224 | {$(this).css('padding-left',(options.iconWidthEC+$(this).attr('level')*options.levelIndent)+'px');});} |
---|
225 | return(options.levelIndent);},setServerUrl:function(object,value) |
---|
226 | {var options=object.data('options'),properties=object.data('properties');if(!properties.initialized||options.serverUrl!=value) |
---|
227 | {options.serverUrl=value;if(options.autoLoad&&properties.initialized)privateMethods.load(object);} |
---|
228 | return(options.serverUrl);},setFilter:function(object,value) |
---|
229 | {var options=object.data('options'),properties=object.data('properties');if((!properties.initialized||options.filter!=value)&&(value=='none'||value=='accessible'||value=='public')) |
---|
230 | {options.filter=value;if(options.autoLoad&&properties.initialized)privateMethods.load(object);} |
---|
231 | return(options.filter);},setIconWidthEC:function(object,value) |
---|
232 | {var options=object.data('options'),properties=object.data('properties'),objects=object.data('objects');if((!properties.initialized||options.iconWidthEC!=value)&&value>=0) |
---|
233 | {options.iconWidthEC=value;objects.list.find('.ui-category-selector-item').each(function() |
---|
234 | {$(this).css('padding-left',(options.iconWidthEC+$(this).attr('level')*options.levelIndent)+'px');});} |
---|
235 | return(options.iconWidthEC);},setMultiple:function(object,value) |
---|
236 | {var options=object.data('options'),properties=object.data('properties'),objects=object.data('objects');if((!properties.initialized||options.multiple!=value)&&(value==true||value==false)) |
---|
237 | {if(!value) |
---|
238 | {properties.index=-1;if(objects.containerList!=null) |
---|
239 | {objects.containerList.remove();objects.containerList=null;}} |
---|
240 | else |
---|
241 | {properties.index=[];objects.listContainer.addClass('ui-category-selector-multiple');if(objects.containerList==null) |
---|
242 | {objects.containerList=$('<ul/>',{css:{listStyle:'none',padding:'0px',margin:'0px',overflow:"auto"},html:'<li> </li>'});objects.containerName.html('').append(objects.containerList);}} |
---|
243 | options.multiple=value;} |
---|
244 | return(options.multiple);},setUserMode:function(object,value) |
---|
245 | {var options=object.data('options'),properties=object.data('properties');if((!properties.initialized||options.userMode!=value)&&(value=='admin'||value=='public')) |
---|
246 | {options.userMode=value;if(options.autoLoad&&properties.initialized)privateMethods.load(object);} |
---|
247 | return(options.userMode);},setPopupMode:function(object,value) |
---|
248 | {var options=object.data('options'),properties=object.data('properties'),objects=object.data('objects');if((!properties.initialized||options.popupMode!=value)&&(value=='click'||value=='mouseout')) |
---|
249 | {options.popupMode=value;if(value=='mouseout') |
---|
250 | {objects.listContainer.unbind('mouseleave.categorySelector').unbind('mouseenter.categorySelector').bind('mouseleave.categorySelector',function() |
---|
251 | {privateMethods.displaySelector(object,false);});} |
---|
252 | else |
---|
253 | {objects.listContainer.unbind('mouseleave.categorySelector').bind('mouseleave.categorySelector',function() |
---|
254 | {properties.mouseOver=false;}).bind('mouseenter.categorySelector',function() |
---|
255 | {properties.mouseOver=true;});$(document).bind('focusout focusin',function(event) |
---|
256 | {if(!properties.mouseOver)privateMethods.displaySelector(object,false);});}} |
---|
257 | return(options.popupMode);},setDisplayPath:function(object,value) |
---|
258 | {var options=object.data('options'),properties=object.data('properties'),objects=object.data('objects');if((!properties.initialized||options.displayPath!=value)&&(value==true||value==false)) |
---|
259 | {options.displayPath=value;} |
---|
260 | return(options.userMode);},setDownArrow:function(object,value) |
---|
261 | {var options=object.data('options'),properties=object.data('properties'),objects=object.data('objects');if(!properties.initialized||options.downArrow!=value) |
---|
262 | {options.downArrow=value;objects.containerArrow.html(options.downArrow);} |
---|
263 | return(options.downArrow);},setItems:function(object,value) |
---|
264 | {var properties=object.data('properties'),options=object.data('options'),objects=object.data('objects');if(value==''||value==null) |
---|
265 | {value={status:['',''],categories:[]}} |
---|
266 | else if($.isArray(value)) |
---|
267 | {value={status:'public',categories:value}} |
---|
268 | else |
---|
269 | {try |
---|
270 | {value=$.parseJSON($.trim(value));} |
---|
271 | catch(e) |
---|
272 | {return(false);}} |
---|
273 | properties.labelStatus=value.status;privateMethods.listClear(object);if(value.categories.length>0)privateMethods.listAddItems(object,value.categories,objects.list);properties.initialized=false;if(options.multiple) |
---|
274 | {privateMethods.setValue(object,':none');} |
---|
275 | else |
---|
276 | {privateMethods.setValue(object,':first');} |
---|
277 | properties.initialized=true;if(options.load)object.trigger('categorySelectorLoad');},setExpandCollapse:function(object,value,mode) |
---|
278 | {var objects=object.data('objects');re=/^(?:(:all)(?:(=|<|>|\+)(\d+))?)|(?:(\d+)(<|>|\+))?$/i;target=re.exec(value);if(target!=null) |
---|
279 | {switch(mode) |
---|
280 | {case'C':applyExpandCollapse=privateMethods.applyCollapse;break;case'E':applyExpandCollapse=privateMethods.applyExpand;break;} |
---|
281 | if(target[1]==':all') |
---|
282 | {objects.list.find('.ui-category-selector-expandable-item, .ui-category-selector-collapsable-item').each(applyExpandCollapse);} |
---|
283 | else if(target[4]!=null) |
---|
284 | {switch(target[5]) |
---|
285 | {case'+':objects.list.find('.ui-category-selector-expandable-item, .ui-category-selector-collapsable-item').each(privateMethods.applyCollapse);objects.list.find(':has([catId='+target[4]+'])').prev().each(privateMethods.applyExpand);objects.list.find('[catId='+target[4]+']').each(applyExpandCollapse);break;case'>':objects.list.find('[catId='+target[4]+'] + ul').find('.ui-category-selector-expandable-item, .ui-category-selector-collapsable-item').each(applyExpandCollapse);objects.list.find('[catId='+target[4]+']').each(applyExpandCollapse);break;case'<':objects.list.find(':has([catId='+target[4]+'])').prev().each(applyExpandCollapse);objects.list.find('[catId='+target[4]+']').each(applyExpandCollapse);break;default:objects.list.find('[catId='+target[4]+']').each(applyExpandCollapse);break;}}}},applyExpand:function(index,domElt) |
---|
286 | {privateMethods.applyExpandCollapse(index,domElt,'E');},applyCollapse:function(index,domElt) |
---|
287 | {privateMethods.applyExpandCollapse(index,domElt,'C');},applyExpandCollapse:function(index,domElt,mode) |
---|
288 | {action='';var $domElt=$(domElt);if(target.length>2&&target[2]!=null&&target[3]!=null) |
---|
289 | {switch(target[2]) |
---|
290 | {case'=':if($domElt.attr('level')==target[3])action=mode;break;case'>':if($domElt.attr('level')>=target[3])action=mode;break;case'<':if($domElt.attr('level')<=target[3])action=mode;break;case'+':if((mode=='E'&&$domElt.attr('level')<=target[3])||(mode=='C'&&$domElt.attr('level')>=target[3])) |
---|
291 | {action=mode;} |
---|
292 | else |
---|
293 | {action=(mode=='C')?'E':'C';} |
---|
294 | break;}} |
---|
295 | else action=mode;switch(action) |
---|
296 | {case'C':$domElt.removeClass('ui-category-selector-expandable-item ui-category-selector-collapsable-item').addClass('ui-category-selector-expandable-item').next().hide();break;case'E':$domElt.removeClass('ui-category-selector-expandable-item ui-category-selector-collapsable-item').addClass('ui-category-selector-collapsable-item').next().show();break;}},setValue:function(object,value,trigger) |
---|
297 | {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) |
---|
298 | {case':first':if(properties.categories.length>0)index=0;break;case':last':index=properties.categories.length-1;break;case':invert':if(!options.multiple)return(false);properties.index=[];objects.list.find('.ui-category-selector-item').each(function() |
---|
299 | {var $this=$(this),apply=true;if(target!=null) |
---|
300 | {switch(target[2]) |
---|
301 | {case'=':apply=($this.attr('level')==target[3]);break;case'>':apply=($this.attr('level')>=target[3]);break;case'<':apply=($this.attr('level')<=target[3]);break;}} |
---|
302 | if(apply) |
---|
303 | {if($this.hasClass('ui-category-selector-selected-item')) |
---|
304 | {$this.removeClass('ui-category-selector-selected-item');} |
---|
305 | else |
---|
306 | {$this.addClass('ui-category-selector-selected-item');tmp=privateMethods.findIndexByValue(object,$this.attr('catId'));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-category-selector-selected-item').each(function() |
---|
307 | {var $this=$(this),apply=true;if(target!=null) |
---|
308 | {switch(target[2]) |
---|
309 | {case'=':apply=($this.attr('level')==target[3]);break;case'>':apply=($this.attr('level')>=target[3]);break;case'<':apply=($this.attr('level')<=target[3]);break;}} |
---|
310 | if(apply)$this.removeClass('ui-category-selector-selected-item');});privateMethods.setValue(object,[],false);return(false);break;case':all':if(!options.multiple)return(false);properties.index=[];objects.list.find('.ui-category-selector-item').each(function() |
---|
311 | {var $this=$(this),apply=true;if(target!=null) |
---|
312 | {switch(target[2]) |
---|
313 | {case'=':apply=($this.attr('level')==target[3]);break;case'>':apply=($this.attr('level')>=target[3]);break;case'<':apply=($this.attr('level')<=target[3]);break;}} |
---|
314 | if(apply) |
---|
315 | {tmp=privateMethods.findIndexByValue(object,$this.attr('catId'));if(tmp>-1)properties.index.push(tmp);$this.addClass('ui-category-selector-selected-item');}});privateMethods.setValue(object,[],false);return(false);break;default:if($.isArray(value)&&options.multiple) |
---|
316 | {index=[];for(var i=0;i<value.length;i++) |
---|
317 | {tmp=privateMethods.findIndexByValue(object,value[i]);if(tmp>-1)index.push(tmp);}} |
---|
318 | else |
---|
319 | {index=privateMethods.findIndexByValue(object,value);} |
---|
320 | break;} |
---|
321 | if(!options.multiple&&(!properties.initialized||properties.index!=index)&&index>-1) |
---|
322 | {objects.list.find('.ui-category-selector-selected-item').removeClass('ui-category-selector-selected-item');objects.list.find('[catId="'+value+'"]').addClass('ui-category-selector-selected-item');title=privateMethods.getParentName(object,objects.list.find('[catId="'+value+'"] div.ui-category-selector-name')).replace('&','&').replace('>','>').replace('<','<');properties.index=index;objects.containerName.html(properties.categories[properties.index].name).attr('title',title);objects.containerStatus.html(properties.labelStatus[properties.categories[properties.index].status]);if(trigger&&options.change)object.trigger('categorySelectorChange',[properties.categories[properties.index].id]);if(properties.index>-1)return(properties.categories[properties.index].id);} |
---|
323 | else if(options.multiple) |
---|
324 | {if(!$.isArray(index)) |
---|
325 | {if(index<0||index==null)return(-1);index=[index];} |
---|
326 | tmp=[];for(var i=0;i<index.length;i++) |
---|
327 | {var item=objects.list.find('[catId="'+properties.categories[index[i]].id+'"]');if(item.hasClass('ui-category-selector-selected-item')) |
---|
328 | {item.removeClass('ui-category-selector-selected-item');tmpIndex=$.inArray(index[i],properties.index);if(tmpIndex>-1)properties.index.splice(tmpIndex,1);} |
---|
329 | else |
---|
330 | {item.addClass('ui-category-selector-selected-item');properties.index.push(index[i]);} |
---|
331 | tmp.push(properties.categories[index[i]].id);} |
---|
332 | objects.containerList.html('');objects.list.find('.ui-category-selector-selected-item div.ui-category-selector-name').each(function() |
---|
333 | {var path='';title=privateMethods.getParentName(object,$(this)).replace('&','&').replace('>','>').replace('<','<');if(!options.displayPath) |
---|
334 | {path=$(this).html();} |
---|
335 | else |
---|
336 | {path=title;} |
---|
337 | objects.containerList.append($('<li/>',{html:path,title:title,'class':'ui-category-selector-selected-cat'}).prepend($('<span/>',{html:'x'}).bind('click.categorySelector',{object:object,value:$(this).parent().parent().attr('catid')},function(event) |
---|
338 | {event.stopPropagation();privateMethods.setValue(event.data.object,event.data.value);})))});if(objects.containerList.children().length==0)objects.containerList.append('<li> </li>');if(trigger&&options.change)object.trigger('categorySelectorChange',[tmp]);return(tmp);} |
---|
339 | return(null);},getParentName:function(object,item) |
---|
340 | {if(item==null||item.length==0)return('');foundItem=item.parent().parent().parent().prev().find('div.ui-category-selector-name');if(foundItem.length==0)return(item.html());return(privateMethods.getParentName(object,foundItem)+' / '+item.html());},displaySelector:function(object,value) |
---|
341 | {var options=object.data('options'),properties=object.data('properties'),objects=object.data('objects');if(properties.selectorVisible!=value) |
---|
342 | {properties.selectorVisible=value;if(properties.selectorVisible&&properties.categories.length>0) |
---|
343 | {var index=0;objects.listContainer.css({display:'block','min-width':objects.listContainer.parent().css('width')});if($.isArray(properties.index)) |
---|
344 | {if(properties.index.length>0)index=properties.index[0];} |
---|
345 | else if(properties.index>-1) |
---|
346 | {index=properties.index;} |
---|
347 | objects.listContainer.scrollTop(objects.listContainer.scrollTop()+objects.list.find('[catId="'+properties.categories[index].id+'"]').position().top);} |
---|
348 | else |
---|
349 | {objects.listContainer.css('display','none');} |
---|
350 | if(options.popup)object.trigger('categorySelectorPopup',[properties.selectorVisible]);} |
---|
351 | return(properties.selectorVisible);},load:function(object) |
---|
352 | {var options=object.data('options'),objects=object.data('objects');if(options.serverUrl=='')return(false);$.ajax({type:"POST",url:options.serverUrl,async:true,data:{ajaxfct:options.userMode+'.categorySelector.getList',filter:options.filter,galleryRoot:options.galleryRoot?'y':'n',tree:'y'},success:function(msg) |
---|
353 | {privateMethods.setItems(object,msg);},error:function(msg) |
---|
354 | {objects.listContainer.html('Error ! '+msg);}});},listClear:function(object) |
---|
355 | {var objects=object.data('objects'),options=object.data('options'),properties=object.data('properties');objects.list.children().unbind();objects.list.html('');if(options.multiple) |
---|
356 | {properties.index=[];} |
---|
357 | else |
---|
358 | {properties.index=-1;} |
---|
359 | properties.categories=[];},listAddItems:function(object,listItems,parent) |
---|
360 | {var options=object.data('options'),properties=object.data('properties'),objects=object.data('objects');var previousLevel=-1;for(var i=0;i<listItems.length;i++) |
---|
361 | {properties.categories.push({id:listItems[i].id,level:listItems[i].level,name:listItems[i].name,status:listItems[i].status,childs:listItems[i].childs.length});if(options.displayStatus) |
---|
362 | {status="<div class='ui-category-selector-status'>"+properties.labelStatus[listItems[i].status]+"</div>";} |
---|
363 | else |
---|
364 | {status="";} |
---|
365 | var spaceWidth=(options.iconWidthEC+listItems[i].level*options.levelIndent),li=$('<li/>',{'class':'ui-category-selector-item',html:"<div>"+status+"<div class='ui-category-selector-name'>"+listItems[i].name+"</div></div>",catId:listItems[i].id,level:listItems[i].level,css:{'padding-left':spaceWidth+'px'}}).bind('click.categorySelector',{object:object,expandArea:spaceWidth,nbchilds:listItems[i].childs.length},function(event) |
---|
366 | {event.layerX=event.pageX-$(event.currentTarget).offset().left;event.layerY=event.pageY-$(event.currentTarget).offset().top;if(event.layerX<event.data.expandArea&&event.data.nbchilds>0) |
---|
367 | {if($(this).hasClass('ui-category-selector-expandable-item')) |
---|
368 | {$(this).removeClass('ui-category-selector-expandable-item').addClass('ui-category-selector-collapsable-item').next().show();} |
---|
369 | else |
---|
370 | {$(this).removeClass('ui-category-selector-collapsable-item').addClass('ui-category-selector-expandable-item').next().hide();}} |
---|
371 | else |
---|
372 | {privateMethods.setValue(event.data.object,$(this).attr('catId'),true);if(options.multiple) |
---|
373 | {} |
---|
374 | else |
---|
375 | {privateMethods.displaySelector(event.data.object,false);}} |
---|
376 | if(options.multiple)objects.container.focus();});if(listItems[i].childs.length>0) |
---|
377 | {li.addClass('ui-category-selector-collapsable-item').css('background-position',(options.levelIndent*listItems[i].level)+'px 0px');} |
---|
378 | if(options.multiple) |
---|
379 | {li.children().prepend('<div class="ui-category-selector-check"></div>');} |
---|
380 | parent.append(li);if(listItems[i].childs.length>0) |
---|
381 | {var ul=$('<ul/>',{'class':'ui-category-selector-group',css:{listStyle:'none',padding:'0px',margin:'0px','font-size':(100-listItems[i].level*2)+'%'}});li.after(ul);privateMethods.listAddItems(object,listItems[i].childs,ul);}}},findIndexByValue:function(object,value) |
---|
382 | {var properties=object.data('properties');for(var i=0;i<properties.categories.length;i++) |
---|
383 | {if(properties.categories[i].id==value)return(i);} |
---|
384 | return(-1);},setEventPopup:function(object,value) |
---|
385 | {var options=object.data('options');options.popup=value;object.unbind('categorySelectorPopup');if(value)object.bind('categorySelectorPopup',options.popup);return(options.popup);},setEventChange:function(object,value) |
---|
386 | {var options=object.data('options');options.change=value;object.unbind('categorySelectorChange');if(value)object.bind('categorySelectorChange',options.change);return(options.change);},setEventLoad:function(object,value) |
---|
387 | {var options=object.data('options');options.load=value;object.unbind('categorySelectorLoad');if(value)object.bind('categorySelectorLoad',options.load);return(options.load);}};$.fn.categorySelector=function(method) |
---|
388 | {if(publicMethods[method]) |
---|
389 | {return publicMethods[method].apply(this,Array.prototype.slice.call(arguments,1));} |
---|
390 | else if(typeof method==='object'||!method) |
---|
391 | {return publicMethods.init.apply(this,arguments);} |
---|
392 | else |
---|
393 | {$.error('Method '+method+' does not exist on jQuery.categorySelector');}}})(jQuery); |
---|