source: extensions/GrumPluginClasses/js/ui.iconSelector.min.js @ 9683

Last change on this file since 9683 was 8961, checked in by grum, 14 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: 8.4 KB
Line 
1/* file: ui.iconSelector.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={images:[],numCols:1,numRows:8,cellWidth:32,cellHeight:32,popup:null,change:null};if(opt)$.extend(options,opt);$this.data('options',options);if(!properties)
6{$this.data('properties',{index:-1,initialized:false,selectorVisible:false});properties=$this.data('properties');}
7if(!objects)
8{objects={container:$('<div/>',{'class':' ui-icon-selector '}).bind('click.iconSelector',function()
9{privateMethods.displaySelector($this,!$this.data('properties').selectorVisible);}),listContainer:$('<div/>',{html:"",'class':' ui-icon-selector-list ',css:{overflow:"auto",width:'0px',height:'0px',display:'none',position:'absolute'}}).bind('mouseleave.iconSelector',function()
10{privateMethods.displaySelector($this,false);}),list:$('<ul/>',{css:{listStyle:'none',padding:'0px',margin:'0px'}})};$this.html('').append(objects.container).append(objects.listContainer.append(objects.list));$this.data('objects',objects);}
11privateMethods.setImages($this,options.images);privateMethods.setCellWidth($this,options.cellWidth);privateMethods.setCellHeight($this,options.cellHeight);privateMethods.setNumCols($this,options.numCols);privateMethods.setNumRows($this,options.numRows);privateMethods.setEventPopup($this,options.popup);privateMethods.setEventChange($this,options.change);if(options.images.length>0)privateMethods.setValue($this,options.images[0]);properties.initialized=true;});},destroy:function()
12{return this.each(function()
13{var $this=$(this),objects=$this.data('objects');objects.container.unbind().remove();objects.list.children().unbind();objects.listContainer.remove();$this.unbind('.iconSelector').css({width:'',height:'',backgroundImage:''});});},images:function(list)
14{if(list)
15{return this.each(function()
16{privateMethods.setImages($(this),list);});}
17else
18{var options=this.data('options');if(options)
19{return(options.images);}
20else
21{return([]);}}},numCols:function(value)
22{if(value)
23{return this.each(function()
24{privateMethods.setCols($(this),value);});}
25else
26{var options=this.data('options');if(options)
27{return(options.numCols);}
28else
29{return(0);}}},numRows:function(value)
30{if(value)
31{return this.each(function()
32{privateMethods.setRows($(this),value);});}
33else
34{var options=this.data('options');if(options)
35{return(options.numRows);}
36else
37{return(0);}}},cellWidth:function(value)
38{if(value)
39{return this.each(function()
40{privateMethods.setCellWidth($(this),value);});}
41else
42{var options=this.data('options');if(options)
43{return(options.cellWidth);}
44else
45{return(0);}}},cellHeight:function(value)
46{if(value)
47{return this.each(function()
48{privateMethods.setCellHeight($(this),value);});}
49else
50{var options=this.data('options');if(options)
51{return(options.cellHeight);}
52else
53{return(0);}}},value:function(value)
54{if(value)
55{return this.each(function()
56{privateMethods.setValue($(this),value);});}
57else
58{var options=this.data('options'),properties=this.data('properties');if(options&&properties&&properties.index>-1&&properties.index<options.images.length)
59{return(options.images[properties.index]);}
60else
61{return('');}}},popup:function(value)
62{if(value&&$.isFunction(value))
63{return this.each(function()
64{privateMethods.setEventPopup($(this),value);});}
65else
66{var options=this.data('options');if(options)
67{return(options.popup);}
68else
69{return(null);}}},change:function(value)
70{if(value&&$.isFunction(value))
71{return this.each(function()
72{privateMethods.setEventChange($(this),value);});}
73else
74{var options=this.data('options');if(options)
75{return(options.change);}
76else
77{return(null);}}}};var privateMethods={updateListArea:function(object)
78{var options=object.data('options'),objects=object.data('objects'),icon=objects.list.children().first(),width=icon.outerWidth()*options.numCols,height=icon.outerHeight()*options.numRows;objects.listContainer.css({width:width+'px',height:height+'px'});delta=width-objects.listContainer.get(0).clientWidth;if(delta>0)
79{objects.listContainer.css('width',(width+delta)+'px');}},setImages:function(object,value)
80{var options=object.data('options'),objects=object.data('objects'),properties=object.data('properties');options.images=value;objects.list.children().unbind();objects.list.html('');for(var i=0;i<options.images.length;i++)
81{liClass=' ui-icon-selector-icon ';if(i==properties.index)
82{liClass+=' ui-icon-selector-selected-icon ';}
83objects.list.append($('<li indexValue="'+i+'" class="'+liClass+'" style="display:inline-block;width:'+options.cellWidth+'px;height:'+options.cellHeight+'px;background-image:url('+options.images[i]+');"></li>').bind('click',{object:object},function(event)
84{privateMethods.setValueByIndex(event.data.object,$(this).attr('indexValue'),true);privateMethods.displaySelector(event.data.object,false);}));}
85return(options.images);},setNumCols:function(object,value)
86{var options=object.data('options'),properties=object.data('properties');if((!properties.initialized||options.numCols!=value)&&value>0)
87{options.numCols=value;}
88return(options.numCols);},setNumRows:function(object,value)
89{var options=object.data('options'),properties=object.data('properties');if((!properties.initialized||options.numRows!=value)&&value>0)
90{options.numRows=value;}
91return(options.numRows);},setCellWidth:function(object,value)
92{var options=object.data('options'),properties=object.data('properties'),objects=object.data('objects');if((!properties.initialized||options.cellWidth!=value)&&value>=0)
93{options.cellWidth=value;objects.container.css('width',value+'px');}
94return(options.cellWidth);},setCellHeight:function(object,value)
95{var options=object.data('options'),properties=object.data('properties'),objects=object.data('objects');if((!properties.initialized||options.cellHeight!=value)&&value>=0)
96{options.cellHeight=value;objects.container.css('height',value+'px');}
97return(options.cellHeight);},setValue:function(object,value)
98{var options=object.data('options'),properties=object.data('properties'),index=-1;switch(value)
99{case':first':if(options.images.length>0)index=0;break;case':last':index=options.images.length-1;break;default:index=$.inArray(value,options.images);break;}
100if((!properties.initialized||properties.index!=index)&&index>-1)
101{privateMethods.setValueByIndex(object,index,false);}
102return(options.images[properties.index]);},setValueByIndex:function(object,value,trigger)
103{var options=object.data('options'),properties=object.data('properties'),objects=object.data('objects');if((!properties.initialized||properties.index!=value)&&value>-1&&value<options.images.length)
104{objects.list.children('.ui-icon-selector-selected-icon').removeClass('ui-icon-selector-selected-icon');objects.list.children('[indexValue="'+value+'"]').addClass('ui-icon-selector-selected-icon');properties.index=value;objects.container.css('background-image','url('+options.images[properties.index]+')');if(trigger&&options.change)object.trigger('iconSelectorChange',[properties.index]);}
105return(options.images[properties.index]);},displaySelector:function(object,value)
106{var options=object.data('options'),properties=object.data('properties'),objects=object.data('objects');if(properties.selectorVisible!=value)
107{properties.selectorVisible=value;if(properties.selectorVisible)
108{objects.listContainer.css('display','block').scrollTop(objects.listContainer.scrollTop()+objects.list.children('[indexValue="'+properties.index+'"]').position().top);privateMethods.updateListArea(object);}
109else
110{objects.listContainer.css('display','none');}
111if(options.popup)object.trigger('iconSelectorPopup',[properties.selectorVisible]);}
112return(properties.selectorVisible);},setEventPopup:function(object,value)
113{var options=object.data('options');options.popup=value;object.unbind('iconSelectorPopup');if(value)object.bind('iconSelectorPopup',options.popup);return(options.popup);},setEventChange:function(object,value)
114{var options=object.data('options');options.change=value;object.unbind('iconSelectorChange');if(value)object.bind('iconSelectorChange',options.change);return(options.change);}};$.fn.iconSelector=function(method)
115{if(publicMethods[method])
116{return publicMethods[method].apply(this,Array.prototype.slice.call(arguments,1));}
117else if(typeof method==='object'||!method)
118{return publicMethods.init.apply(this,arguments);}
119else
120{$.error('Method '+method+' does not exist on jQuery.iconSelector');}}})(jQuery);
Note: See TracBrowser for help on using the repository browser.