1 | /* file: ui.inputText.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={languages:[],currentLanguage:'',languagesValues:{},languageSelector:'',multilines:false,disabled:false,textAlign:'left',displayChar:0,maxChar:0,numRows:1,regExp:'',value:'',change:null};if(options.value==''&&$.trim($this.html())!='')options.value=$.trim($this.html());$this.data('options',options);if(!properties) |
---|
6 | {$this.data('properties',{initialized:false,re:/.*/,value:0,isValid:true,languagesValues:{}});properties=$this.data('properties');} |
---|
7 | if(!objects) |
---|
8 | {objects={container:$('<div/>',{'class':'ui-inputText',css:{width:'100%'}}).bind('click.inputText',function() |
---|
9 | {objects.input.focus();}),input:null};$this.html('').append(objects.container);$this.data('objects',objects);} |
---|
10 | privateMethods.setOptions($this,opt);});},destroy:function() |
---|
11 | {return this.each(function() |
---|
12 | {var $this=$(this),objects=$this.data('objects');objects.input.unbind().remove();objects.container.unbind().remove();$this.unbind('.inputText').css({width:'',height:''});});},options:function(value) |
---|
13 | {return(this.each(function() |
---|
14 | {privateMethods.setOptions($(this),value);}));},disabled:function(value) |
---|
15 | {if(value!=null) |
---|
16 | {return(this.each(function() |
---|
17 | {privateMethods.setDisabled($(this),value);}));} |
---|
18 | else |
---|
19 | {var options=this.data('options');if(options) |
---|
20 | {return(options.disabled);} |
---|
21 | else |
---|
22 | {return('');}}},textAlign:function(value) |
---|
23 | {if(value!=null) |
---|
24 | {return(this.each(function() |
---|
25 | {privateMethods.setTextAlign($(this),value);}));} |
---|
26 | else |
---|
27 | {var options=this.data('options');if(options) |
---|
28 | {return(options.textAlign);} |
---|
29 | else |
---|
30 | {return('');}}},displayChar:function(value) |
---|
31 | {if(value!=null) |
---|
32 | {return(this.each(function() |
---|
33 | {privateMethods.setDisplayChar($(this),value);}));} |
---|
34 | else |
---|
35 | {var options=this.data('options');if(options) |
---|
36 | {return(options.displayChar);} |
---|
37 | else |
---|
38 | {return('');}}},maxChar:function(value) |
---|
39 | {if(value!=null) |
---|
40 | {return(this.each(function() |
---|
41 | {privateMethods.setMaxChar($(this),value);}));} |
---|
42 | else |
---|
43 | {var options=this.data('options');if(options) |
---|
44 | {return(options.maxChar);} |
---|
45 | else |
---|
46 | {return('');}}},numRows:function(value) |
---|
47 | {if(value!=null) |
---|
48 | {return(this.each(function() |
---|
49 | {privateMethods.setNumRows($(this),value);}));} |
---|
50 | else |
---|
51 | {var options=this.data('options');if(options) |
---|
52 | {return(options.numRows);} |
---|
53 | else |
---|
54 | {return('');}}},regExp:function(value) |
---|
55 | {if(value!=null) |
---|
56 | {return(this.each(function() |
---|
57 | {privateMethods.setRegExp($(this),value);}));} |
---|
58 | else |
---|
59 | {var options=this.data('options');if(options) |
---|
60 | {return(options.regExp);} |
---|
61 | else |
---|
62 | {return('');}}},multilines:function() |
---|
63 | {var properties=this.data('properties');return(properties.multilines);},languages:function(value) |
---|
64 | {if(value!=null) |
---|
65 | {return(this.each(function() |
---|
66 | {privateMethods.setLanguages($(this),value);}));} |
---|
67 | else |
---|
68 | {var options=this.data('options');return(options.languages);}},currentLanguage:function(value) |
---|
69 | {if(value!=null) |
---|
70 | {return(this.each(function() |
---|
71 | {privateMethods.setCurrentLanguage($(this),value);}));} |
---|
72 | else |
---|
73 | {var options=this.data('options');return(options.currentLanguage);}},languageSelector:function(value) |
---|
74 | {if(value!=null) |
---|
75 | {return(this.each(function() |
---|
76 | {privateMethods.setLanguageSelector($(this),value);}));} |
---|
77 | else |
---|
78 | {var options=this.data('options');return(options.languageSelector);}},languagesValues:function(value) |
---|
79 | {if(value!=null) |
---|
80 | {return(this.each(function() |
---|
81 | {privateMethods.setLanguagesValues($(this),value);}));} |
---|
82 | else |
---|
83 | {var properties=this.data('properties');return(properties.languagesValues);}},value:function(value,language) |
---|
84 | {if(value!=null) |
---|
85 | {var options=this.data('options');return(this.each(function() |
---|
86 | {if(language!=null) |
---|
87 | {privateMethods.setLanguageValue($(this),language,value,options.currentLanguage==language);} |
---|
88 | else |
---|
89 | {privateMethods.setValue($(this),value,true);}}));} |
---|
90 | else |
---|
91 | {var properties=this.data('properties');return(properties.value);}},isValid:function(value) |
---|
92 | {if(value!=null) |
---|
93 | {return(this.each(function() |
---|
94 | {privateMethods.setIsValid($(this),value);}));} |
---|
95 | else |
---|
96 | {var properties=this.data('properties');return(properties.isValid);}},change:function(value) |
---|
97 | {if(value!=null&&$.isFunction(value)) |
---|
98 | {return(this.each(function() |
---|
99 | {privateMethods.setEventChange($(this),value);}));} |
---|
100 | else |
---|
101 | {var options=this.data('options');if(options) |
---|
102 | {return(options.change);} |
---|
103 | else |
---|
104 | {return(null);}}},doTranslation:function() |
---|
105 | {return(this.each(function() |
---|
106 | {privateMethods.doTranslation($(this));}));}};var privateMethods={isValid:function(object,value) |
---|
107 | {var properties=object.data('properties');return(properties.re.exec(value))},setOptions:function(object,value) |
---|
108 | {var properties=object.data('properties'),options=object.data('options');if(!$.isPlainObject(value))return(false);properties.initialized=false;privateMethods.setMultilines(object,(value.multilines!=null)?value.multilines:options.multilines);privateMethods.setDisplayChar(object,(value.displayChar!=null)?value.displayChar:options.displayChar);privateMethods.setMaxChar(object,(value.maxChar!=null)?value.maxChar:options.maxChar);privateMethods.setNumRows(object,(value.numRows!=null)?value.numRows:options.numRows);privateMethods.setRegExp(object,(value.regExp!=null)?value.regExp:options.regExp);privateMethods.setLanguages(object,(value.languages!=null)?value.languages:options.languages);privateMethods.setLanguagesValues(object,(value.languagesValues!=null)?value.languagesValues:options.languagesValues);privateMethods.setCurrentLanguage(object,(value.currentLanguage!=null)?value.currentLanguage:options.currentLanguage);privateMethods.setLanguageSelector(object,(value.languageSelector!=null)?value.languageSelector:options.languageSelector);if((properties.languagesValues[options.currentLanguage]!=null&&properties.languagesValues[options.currentLanguage]!=''||properties.languagesValues[options.currentLanguage]==null)&&(value.value!=null&&value.value!=''||options.value!=''))privateMethods.setValue(object,(value.value!=null)?value.value:options.value,true);privateMethods.setTextAlign(object,(value.textAlign!=null)?value.textAlign:options.textAlign);privateMethods.setEventChange(object,(value.change!=null)?value.change:options.change);properties.initialized=true;},setRegExp:function(object,value) |
---|
109 | {var properties=object.data('properties'),flagRE=/^\/(.*)\/(.*)$/,flags=flagRE.exec(value);if(flags==null) |
---|
110 | {flags=['.*',''];} |
---|
111 | delete properties.re;properties.re=new RegExp(flags[1],flags[2]);},setIsValid:function(object,value) |
---|
112 | {var objects=object.data('objects'),properties=object.data('properties');if(properties.isValid!=value&&properties.initialized) |
---|
113 | {properties.isValid=value;if(properties.isValid) |
---|
114 | {objects.container.removeClass('ui-error');objects.input.removeClass('ui-error');} |
---|
115 | else |
---|
116 | {objects.container.addClass('ui-error');objects.input.addClass('ui-error');}} |
---|
117 | return(properties.isValid);},setDisplayChar:function(object,value) |
---|
118 | {var options=object.data('options'),objects=object.data('objects');properties=object.data('properties');if((!properties.initialized||options.displayChar!=value)&&value>=0) |
---|
119 | {options.displayChar=value;if(options.displayChar>0) |
---|
120 | {if(options.multilines) |
---|
121 | {objects.input.attr('cols',options.displayChar);} |
---|
122 | else |
---|
123 | {objects.input.attr('size',options.displayChar);}} |
---|
124 | else |
---|
125 | {if(options.multilines) |
---|
126 | {objects.input.removeAttr('size');} |
---|
127 | else |
---|
128 | {objects.input.removeAttr('cols');}}} |
---|
129 | if(object.width()>0) |
---|
130 | {objects.input.css({'width':object.width()+'px','max-width':object.width()+'px'});} |
---|
131 | return(options.displayChar);},setMaxChar:function(object,value) |
---|
132 | {var options=object.data('options'),objects=object.data('objects'),properties=object.data('properties');if((!properties.initialized||options.maxChar!=value)&&value>=0) |
---|
133 | {options.maxChar=value;if(!options.multilines) |
---|
134 | {if(options.maxChar>0) |
---|
135 | {objects.input.attr('maxlength',options.maxChar);} |
---|
136 | else |
---|
137 | {objects.input.removeAttr('maxlength');}}} |
---|
138 | return(options.maxChar);},setNumRows:function(object,value) |
---|
139 | {var options=object.data('options'),objects=object.data('objects'),properties=object.data('properties');if((!properties.initialized||options.numRows!=value)&&value>0) |
---|
140 | {options.numRows=value;if(options.multilines) |
---|
141 | {objects.input.attr('rows',options.numRows);}} |
---|
142 | return(options.numRows);},setDisabled:function(object,value) |
---|
143 | {var options=object.data('options'),objects=object.data('objects'),properties=object.data('properties');if((!properties.initialized||options.disabled!=value)&&(value==true||value==false)) |
---|
144 | {options.disabled=value;objects.input.attr('disabled',options.disabled);} |
---|
145 | return(options.disabled);},setTextAlign:function(object,value) |
---|
146 | {var options=object.data('options'),objects=object.data('objects'),properties=object.data('properties');if((!properties.initialized||options.textAlign!=value)&&(value=='left'||value=='right')) |
---|
147 | {options.textAlign=value;objects.input.css('text-align',options.textAlign);} |
---|
148 | return(options.textAlign);},setMultilines:function(object,value) |
---|
149 | {var options=object.data('options'),objects=object.data('objects'),properties=object.data('properties');if((!properties.initialized||options.multilines!=value)&&(value==true||value==false)) |
---|
150 | {options.multilines=value;if(options.multilines) |
---|
151 | {objects.input=$('<textarea/>');} |
---|
152 | else |
---|
153 | {objects.input=$('<input>',{type:"text",value:''});} |
---|
154 | objects.container.append(objects.input.bind('keyup.inputText',function(event) |
---|
155 | {return(privateMethods.keyUp(object,event));}).bind('change.inputText',function(event) |
---|
156 | {return(privateMethods.change(object,event));}).bind('keydown.inputText',function(event) |
---|
157 | {return(privateMethods.keyDown(object,event));}));} |
---|
158 | return(options.textAlign);},setLanguages:function(object,value) |
---|
159 | {var properties=object.data('properties'),options=object.data('options');options.languages=value;options.languagesValues={};if(options.languages.length>0) |
---|
160 | {if($.inArray(options.currentLanguage,options.languages)<0||options.currentLanguage=='')options.currentLanguage=options.languages[0];for(var i=0;i<options.languages.length;i++) |
---|
161 | {properties.languagesValues[options.languages[i]]='';}} |
---|
162 | else |
---|
163 | {options.currentLanguage='';} |
---|
164 | return(options.languages);},setLanguagesValues:function(object,value) |
---|
165 | {var options=object.data('options'),properties=object.data('properties');for(var langValue in value) |
---|
166 | {if(properties.languagesValues[langValue]!=null) |
---|
167 | privateMethods.setLanguageValue(object,langValue,value[langValue],langValue==options.currentLanguage);} |
---|
168 | return(properties.languagesValues);},setLanguageValue:function(object,language,value,updateInput) |
---|
169 | {var options=object.data('options'),properties=object.data('properties');if(properties.languagesValues[language]!=null) |
---|
170 | {properties.languagesValues[language]=value;if(updateInput)privateMethods.setValue(object,properties.languagesValues[options.currentLanguage],true);} |
---|
171 | return(options.languagesValues);},setCurrentLanguage:function(object,value) |
---|
172 | {var options=object.data('options'),properties=object.data('properties');if((!properties.initialized||options.currentLanguage!=value)&&$.inArray(value,options.languages)>=0) |
---|
173 | {options.currentLanguage=value;privateMethods.setValue(object,properties.languagesValues[options.currentLanguage],true);} |
---|
174 | return(options.currentLanguage);},setLanguageSelector:function(object,value) |
---|
175 | {var options=object.data('options'),properties=object.data('properties');if((!properties.initialized||options.languageSelector!=value)&&value!=''&&$('#'+value).length>0) |
---|
176 | {if(options.languageSelector!='')$('#'+options.languageSelector).unbind('inputListChange');options.languageSelector=value;if(options.languageSelector!='') |
---|
177 | $('#'+options.languageSelector).bind('inputListChange',function(event,lang) |
---|
178 | {privateMethods.setCurrentLanguage(object,lang);});} |
---|
179 | return(options.currentLanguage);},setValue:function(object,value,apply) |
---|
180 | {var options=object.data('options'),properties=object.data('properties'),objects=object.data('objects');if(properties.initialized&&properties.value==value) |
---|
181 | {return(properties.value);} |
---|
182 | privateMethods.setIsValid(object,true);properties.value=value;if(apply) |
---|
183 | {objects.input.val(properties.value);} |
---|
184 | if(options.currentLanguage!='')privateMethods.setLanguageValue(object,options.currentLanguage,value,false);if(options.change)object.trigger('inputTextChange',properties.value);return(properties.value);},setEventChange:function(object,value) |
---|
185 | {var options=object.data('options');options.change=value;object.unbind('inputTextChange');if(value)object.bind('inputTextChange',options.change);return(options.change);},keyUp:function(object,event) |
---|
186 | {var objects=object.data('objects');if(event.keyCode==9||event.keyCode==12||event.keyCode==16||event.keyCode==17||event.keyCode==18||event.keyCode==33||event.keyCode==34||event.keyCode==35||event.keyCode==36||event.keyCode==37||event.keyCode==38||event.keyCode==39||event.keyCode==40||event.keyCode==45||event.keyCode==93)return(false);return(privateMethods.setValue(object,objects.input.val(),false));},change:function(object,event) |
---|
187 | {var objects=object.data('objects');return(privateMethods.setValue(object,objects.input.val(),false))},keyDown:function(object,event) |
---|
188 | {var objects=object.data('objects'),options=object.data('options');if(options.maxChar>0&&objects.input.val().length>=options.maxChar&&!(event.keyCode==8||event.keyCode==9||event.keyCode==12||event.keyCode==16||event.keyCode==17||event.keyCode==18||event.keyCode==33||event.keyCode==34||event.keyCode==35||event.keyCode==36||event.keyCode==37||event.keyCode==38||event.keyCode==39||event.keyCode==40||event.keyCode==45||event.keyCode==46||event.keyCode==93||objects.input.get(0).selectionStart!=objects.input.get(0).selectionEnd))return(false);},doTranslation:function(object) |
---|
189 | {var objects=object.data('objects'),properties=object.data('properties'),options=object.data('options');if(googleTranslate!=null) |
---|
190 | {googleTranslate(properties.value,'',options.currentLanguage.substr(0,2),function(result) |
---|
191 | {privateMethods.setValue(object,result,true);});}}};$.fn.inputText=function(method) |
---|
192 | {if(publicMethods[method]) |
---|
193 | {return publicMethods[method].apply(this,Array.prototype.slice.call(arguments,1));} |
---|
194 | else if(typeof method==='object'||!method) |
---|
195 | {return publicMethods.init.apply(this,arguments);} |
---|
196 | else |
---|
197 | {$.error('Method '+method+' does not exist on jQuery.inputText');}}})(jQuery); |
---|