root / trunk / web / dojo / dijit / form / TextBox.js @ 12
History | View | Annotate | Download (6.11 KB)
1 |
/*
|
---|---|
2 |
Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
3 |
Available via Academic Free License >= 2.1 OR the modified BSD license.
|
4 |
see: http://dojotoolkit.org/license for details
|
5 |
*/
|
6 |
|
7 |
|
8 |
if(!dojo._hasResource["dijit.form.TextBox"]){ |
9 |
dojo._hasResource["dijit.form.TextBox"]=true; |
10 |
dojo.provide("dijit.form.TextBox");
|
11 |
dojo.require("dijit.form._FormWidget");
|
12 |
dojo.declare("dijit.form.TextBox",dijit.form._FormValueWidget,{trim:false,uppercase:false,lowercase:false,propercase:false,maxLength:"",selectOnClick:false,placeHolder:"",templateString:dojo.cache("dijit.form","templates/TextBox.html","<div class=\"dijit dijitReset dijitInline dijitLeft\" id=\"widget_${id}\" waiRole=\"presentation\"\n\t><div class=\"dijitReset dijitInputField dijitInputContainer\"\n\t\t><input class=\"dijitReset dijitInputInner\" dojoAttachPoint='textbox,focusNode' autocomplete=\"off\"\n\t\t\t${!nameAttrSetting} type='${type}'\n\t/></div\n></div>\n"),_singleNodeTemplate:"<input class=\"dijit dijitReset dijitLeft dijitInputField\" dojoAttachPoint=\"textbox,focusNode\" autocomplete=\"off\" type=\"${type}\" ${!nameAttrSetting} />",_buttonInputDisabled:dojo.isIE?"disabled":"",baseClass:"dijitTextBox",attributeMap:dojo.delegate(dijit.form._FormValueWidget.prototype.attributeMap,{maxLength:"focusNode"}),postMixInProperties:function(){ |
13 |
var _1=this.type.toLowerCase(); |
14 |
if(this.templateString.toLowerCase()=="input"||((_1=="hidden"||_1=="file")&&this.templateString==dijit.form.TextBox.prototype.templateString)){ |
15 |
this.templateString=this._singleNodeTemplate; |
16 |
} |
17 |
this.inherited(arguments); |
18 |
},_setPlaceHolderAttr:function(v){ |
19 |
this.placeHolder=v;
|
20 |
if(!this._phspan){ |
21 |
this._attachPoints.push("_phspan"); |
22 |
this._phspan=dojo.create("span",{className:"dijitPlaceHolder dijitInputField"},this.textbox,"after"); |
23 |
} |
24 |
this._phspan.innerHTML=""; |
25 |
this._phspan.appendChild(document.createTextNode(v));
|
26 |
this._updatePlaceHolder();
|
27 |
},_updatePlaceHolder:function(){ |
28 |
if(this._phspan){ |
29 |
this._phspan.style.display=(this.placeHolder&&!this._focused&&!this.textbox.value)?"":"none"; |
30 |
} |
31 |
},_getValueAttr:function(){ |
32 |
return this.parse(this.get("displayedValue"),this.constraints); |
33 |
},_setValueAttr:function(_2,_3,_4){ |
34 |
var _5;
|
35 |
if(_2!==undefined){ |
36 |
_5=this.filter(_2);
|
37 |
if(typeof _4!="string"){ |
38 |
if(_5!==null&&((typeof _5!="number")||!isNaN(_5))){ |
39 |
_4=this.filter(this.format(_5,this.constraints)); |
40 |
}else{
|
41 |
_4="";
|
42 |
} |
43 |
} |
44 |
} |
45 |
if(_4!=null&&_4!=undefined&&((typeof _4)!="number"||!isNaN(_4))&&this.textbox.value!=_4){ |
46 |
this.textbox.value=_4;
|
47 |
} |
48 |
this._updatePlaceHolder();
|
49 |
this.inherited(arguments,[_5,_3]); |
50 |
},displayedValue:"",getDisplayedValue:function(){ |
51 |
dojo.deprecated(this.declaredClass+"::getDisplayedValue() is deprecated. Use set('displayedValue') instead.","","2.0"); |
52 |
return this.get("displayedValue"); |
53 |
},_getDisplayedValueAttr:function(){ |
54 |
return this.filter(this.textbox.value); |
55 |
},setDisplayedValue:function(_6){ |
56 |
dojo.deprecated(this.declaredClass+"::setDisplayedValue() is deprecated. Use set('displayedValue', ...) instead.","","2.0"); |
57 |
this.set("displayedValue",_6); |
58 |
},_setDisplayedValueAttr:function(_7){ |
59 |
if(_7===null||_7===undefined){ |
60 |
_7="";
|
61 |
}else{
|
62 |
if(typeof _7!="string"){ |
63 |
_7=String(_7); |
64 |
} |
65 |
} |
66 |
this.textbox.value=_7;
|
67 |
this._setValueAttr(this.get("value"),undefined,_7); |
68 |
},format:function(_8,_9){ |
69 |
return ((_8==null||_8==undefined)?"":(_8.toString?_8.toString():_8)); |
70 |
},parse:function(_a,_b){ |
71 |
return _a;
|
72 |
},_refreshState:function(){ |
73 |
},_onInput:function(e){ |
74 |
if(e&&e.type&&/key/i.test(e.type)&&e.keyCode){ |
75 |
switch(e.keyCode){
|
76 |
case dojo.keys.SHIFT:
|
77 |
case dojo.keys.ALT:
|
78 |
case dojo.keys.CTRL:
|
79 |
case dojo.keys.TAB:
|
80 |
return;
|
81 |
} |
82 |
} |
83 |
if(this.intermediateChanges){ |
84 |
var _c=this; |
85 |
setTimeout(function(){
|
86 |
_c._handleOnChange(_c.get("value"),false); |
87 |
},0);
|
88 |
} |
89 |
this._refreshState();
|
90 |
},postCreate:function(){ |
91 |
if(dojo.isIE){
|
92 |
var s=dojo.getComputedStyle(this.domNode); |
93 |
if(s){
|
94 |
var ff=s.fontFamily;
|
95 |
if(ff){
|
96 |
var _d=this.domNode.getElementsByTagName("INPUT"); |
97 |
if(_d){
|
98 |
for(var i=0;i<_d.length;i++){ |
99 |
_d[i].style.fontFamily=ff; |
100 |
} |
101 |
} |
102 |
} |
103 |
} |
104 |
} |
105 |
this.textbox.setAttribute("value",this.textbox.value); |
106 |
this.inherited(arguments); |
107 |
if(dojo.isMoz||dojo.isOpera){
|
108 |
this.connect(this.textbox,"oninput",this._onInput); |
109 |
}else{
|
110 |
this.connect(this.textbox,"onkeydown",this._onInput); |
111 |
this.connect(this.textbox,"onkeyup",this._onInput); |
112 |
this.connect(this.textbox,"onpaste",this._onInput); |
113 |
this.connect(this.textbox,"oncut",this._onInput); |
114 |
} |
115 |
},_blankValue:"",filter:function(_e){ |
116 |
if(_e===null){ |
117 |
return this._blankValue; |
118 |
} |
119 |
if(typeof _e!="string"){ |
120 |
return _e;
|
121 |
} |
122 |
if(this.trim){ |
123 |
_e=dojo.trim(_e); |
124 |
} |
125 |
if(this.uppercase){ |
126 |
_e=_e.toUpperCase(); |
127 |
} |
128 |
if(this.lowercase){ |
129 |
_e=_e.toLowerCase(); |
130 |
} |
131 |
if(this.propercase){ |
132 |
_e=_e.replace(/[^\s]+/g,function(_f){ |
133 |
return _f.substring(0,1).toUpperCase()+_f.substring(1); |
134 |
}); |
135 |
} |
136 |
return _e;
|
137 |
},_setBlurValue:function(){ |
138 |
this._setValueAttr(this.get("value"),true); |
139 |
},_onBlur:function(e){ |
140 |
if(this.disabled){ |
141 |
return;
|
142 |
} |
143 |
this._setBlurValue();
|
144 |
this.inherited(arguments); |
145 |
if(this._selectOnClickHandle){ |
146 |
this.disconnect(this._selectOnClickHandle); |
147 |
} |
148 |
if(this.selectOnClick&&dojo.isMoz){ |
149 |
this.textbox.selectionStart=this.textbox.selectionEnd=undefined; |
150 |
} |
151 |
this._updatePlaceHolder();
|
152 |
},_onFocus:function(by){ |
153 |
if(this.disabled||this.readOnly){ |
154 |
return;
|
155 |
} |
156 |
if(this.selectOnClick&&by=="mouse"){ |
157 |
this._selectOnClickHandle=this.connect(this.domNode,"onmouseup",function(){ |
158 |
this.disconnect(this._selectOnClickHandle); |
159 |
var _10;
|
160 |
if(dojo.isIE){
|
161 |
var _11=dojo.doc.selection.createRange();
|
162 |
var _12=_11.parentElement();
|
163 |
_10=_12==this.textbox&&_11.text.length==0; |
164 |
}else{
|
165 |
_10=this.textbox.selectionStart==this.textbox.selectionEnd; |
166 |
} |
167 |
if(_10){
|
168 |
dijit.selectInputText(this.textbox);
|
169 |
} |
170 |
}); |
171 |
} |
172 |
this._updatePlaceHolder();
|
173 |
this._refreshState();
|
174 |
this.inherited(arguments); |
175 |
},reset:function(){ |
176 |
this.textbox.value=""; |
177 |
this.inherited(arguments); |
178 |
}}); |
179 |
dijit.selectInputText=function(_13,_14,_15){ |
180 |
var _16=dojo.global;
|
181 |
var _17=dojo.doc;
|
182 |
_13=dojo.byId(_13); |
183 |
if(isNaN(_14)){
|
184 |
_14=0;
|
185 |
} |
186 |
if(isNaN(_15)){
|
187 |
_15=_13.value?_13.value.length:0;
|
188 |
} |
189 |
dijit.focus(_13); |
190 |
if(_17["selection"]&&dojo.body()["createTextRange"]){ |
191 |
if(_13.createTextRange){
|
192 |
var _18=_13.createTextRange();
|
193 |
with(_18){
|
194 |
collapse(true);
|
195 |
moveStart("character",-99999); |
196 |
moveStart("character",_14);
|
197 |
moveEnd("character",_15-_14);
|
198 |
select(); |
199 |
} |
200 |
} |
201 |
}else{
|
202 |
if(_16["getSelection"]){ |
203 |
if(_13.setSelectionRange){
|
204 |
_13.setSelectionRange(_14,_15); |
205 |
} |
206 |
} |
207 |
} |
208 |
}; |
209 |
} |