]>
git.wh0rd.org - tt-rss.git/blob - lib/dijit/form/TextBox.js
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
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
;
17 this.inherited(arguments
);
18 },_setPlaceHolderAttr:function(v
){
21 this._attachPoints
.push("_phspan");
22 this._phspan
=dojo
.create("span",{className
:"dijitPlaceHolder dijitInputField"},this.textbox
,"after");
24 this._phspan
.innerHTML
="";
25 this._phspan
.appendChild(document
.createTextNode(v
));
26 this._updatePlaceHolder();
27 },_updatePlaceHolder:function(){
29 this._phspan
.style
.display
=(this.placeHolder
&&!this._focused
&&!this.textbox
.value
)?"":"none";
31 },_getValueAttr:function(){
32 return this.parse(this.get("displayedValue"),this.constraints
);
33 },_setValueAttr:function(_2
,_3
,_4
){
37 if(typeof _4
!="string"){
38 if(_5
!==null&&((typeof _5
!="number")||!isNaN(_5
))){
39 _4
=this.filter(this.format(_5
,this.constraints
));
45 if(_4
!=null&&_4
!=undefined&&((typeof _4
)!="number"||!isNaN(_4
))&&this.textbox
.value
!=_4
){
46 this.textbox
.value
=_4
;
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){
62 if(typeof _7
!="string"){
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
){
72 },_refreshState:function(){
73 },_onInput:function(e
){
74 if(e
&&e
.type
&&/key/i.test(e
.type
)&&e
.keyCode
){
83 if(this.intermediateChanges
){
85 setTimeout(function(){
86 _c
._handleOnChange(_c
.get("value"),false);
90 },postCreate:function(){
92 var s
=dojo
.getComputedStyle(this.domNode
);
96 var _d
=this.domNode
.getElementsByTagName("INPUT");
98 for(var i
=0;i
<_d
.length
;i
++){
99 _d
[i
].style
.fontFamily
=ff
;
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
);
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
);
115 },_blankValue
:"",filter:function(_e
){
117 return this._blankValue
;
119 if(typeof _e
!="string"){
132 _e
=_e
.replace(/[^\s]+/g,function(_f
){
133 return _f
.substring(0,1).toUpperCase()+_f
.substring(1);
137 },_setBlurValue:function(){
138 this._setValueAttr(this.get("value"),true);
139 },_onBlur:function(e
){
143 this._setBlurValue();
144 this.inherited(arguments
);
145 if(this._selectOnClickHandle
){
146 this.disconnect(this._selectOnClickHandle
);
148 if(this.selectOnClick
&&dojo
.isMoz
){
149 this.textbox
.selectionStart
=this.textbox
.selectionEnd
=undefined;
151 this._updatePlaceHolder();
152 },_onFocus:function(by
){
153 if(this.disabled
||this.readOnly
){
156 if(this.selectOnClick
&&by
=="mouse"){
157 this._selectOnClickHandle
=this.connect(this.domNode
,"onmouseup",function(){
158 this.disconnect(this._selectOnClickHandle
);
161 var _11
=dojo
.doc
.selection
.createRange();
162 var _12
=_11
.parentElement();
163 _10
=_12
==this.textbox
&&_11
.text
.length
==0;
165 _10
=this.textbox
.selectionStart
==this.textbox
.selectionEnd
;
168 dijit
.selectInputText(this.textbox
);
172 this._updatePlaceHolder();
173 this._refreshState();
174 this.inherited(arguments
);
176 this.textbox
.value
="";
177 this.inherited(arguments
);
179 dijit
.selectInputText=function(_13
,_14
,_15
){
187 _15
=_13
.value
?_13
.value
.length
:0;
190 if(_17
["selection"]&&dojo
.body()["createTextRange"]){
191 if(_13
.createTextRange
){
192 var _18
=_13
.createTextRange();
195 moveStart("character",-99999);
196 moveStart("character",_14
);
197 moveEnd("character",_15
-_14
);
202 if(_16
["getSelection"]){
203 if(_13
.setSelectionRange
){
204 _13
.setSelectionRange(_14
,_15
);