Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / mobile / app / TextBox.js @ 10

History | View | Annotate | Download (3.94 KB)

1 9 andrej.cim
/*
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["dojox.mobile.app.TextBox"]){
9
dojo._hasResource["dojox.mobile.app.TextBox"]=true;
10
dojo.provide("dojox.mobile.app.TextBox");
11
dojo.experimental("dojox.mobile.app.TextBox");
12
dojo.require("dojox.mobile.app._Widget");
13
dojo.require("dojox.mobile.app._FormWidget");
14
dojo.declare("dojox.mobile.app.TextBox",dojox.mobile.app._FormValueWidget,{trim:false,uppercase:false,lowercase:false,propercase:false,maxLength:"",selectOnClick:false,placeHolder:"",baseClass:"mblTextBox",attributeMap:dojo.delegate(dojox.mobile.app._FormValueWidget.prototype.attributeMap,{maxLength:"focusNode"}),buildRendering:function(){
15
var _1=this.srcNodeRef;
16
if(!_1||_1.tagName!="INPUT"){
17
_1=dojo.create("input",{});
18
}
19
dojo.attr(_1,{type:"text",value:dojo.attr(this.srcNodeRef,"value")||"",placeholder:this.placeHolder||null});
20
this.domNode=this.textbox=this.focusNode=_1;
21
},_setPlaceHolderAttr:function(v){
22
this.placeHolder=v;
23
if(this.textbox){
24
dojo.attr(this.textbox,"placeholder",v);
25
}
26
},_getValueAttr:function(){
27
return this.parse(this.get("displayedValue"),this.constraints);
28
},_setValueAttr:function(_2,_3,_4){
29
var _5;
30
if(_2!==undefined){
31
_5=this.filter(_2);
32
if(typeof _4!="string"){
33
if(_5!==null&&((typeof _5!="number")||!isNaN(_5))){
34
_4=this.filter(this.format(_5,this.constraints));
35
}else{
36
_4="";
37
}
38
}
39
}
40
if(_4!=null&&_4!=undefined&&((typeof _4)!="number"||!isNaN(_4))&&this.textbox.value!=_4){
41
this.textbox.value=_4;
42
}
43
this.inherited(arguments,[_5,_3]);
44
},displayedValue:"",_getDisplayedValueAttr:function(){
45
return this.filter(this.textbox.value);
46
},_setDisplayedValueAttr:function(_6){
47
if(_6===null||_6===undefined){
48
_6="";
49
}else{
50
if(typeof _6!="string"){
51
_6=String(_6);
52
}
53
}
54
this.textbox.value=_6;
55
this._setValueAttr(this.get("value"),undefined,_6);
56
},format:function(_7,_8){
57
return ((_7==null||_7==undefined)?"":(_7.toString?_7.toString():_7));
58
},parse:function(_9,_a){
59
return _9;
60
},_refreshState:function(){
61
},_onInput:function(e){
62
if(e&&e.type&&/key/i.test(e.type)&&e.keyCode){
63
switch(e.keyCode){
64
case dojo.keys.SHIFT:
65
case dojo.keys.ALT:
66
case dojo.keys.CTRL:
67
case dojo.keys.TAB:
68
return;
69
}
70
}
71
if(this.intermediateChanges){
72
var _b=this;
73
setTimeout(function(){
74
_b._handleOnChange(_b.get("value"),false);
75
},0);
76
}
77
this._refreshState();
78
},postCreate:function(){
79
this.textbox.setAttribute("value",this.textbox.value);
80
this.inherited(arguments);
81
if(dojo.isMoz||dojo.isOpera){
82
this.connect(this.textbox,"oninput",this._onInput);
83
}else{
84
this.connect(this.textbox,"onkeydown",this._onInput);
85
this.connect(this.textbox,"onkeyup",this._onInput);
86
this.connect(this.textbox,"onpaste",this._onInput);
87
this.connect(this.textbox,"oncut",this._onInput);
88
}
89
},_blankValue:"",filter:function(_c){
90
if(_c===null){
91
return this._blankValue;
92
}
93
if(typeof _c!="string"){
94
return _c;
95
}
96
if(this.trim){
97
_c=dojo.trim(_c);
98
}
99
if(this.uppercase){
100
_c=_c.toUpperCase();
101
}
102
if(this.lowercase){
103
_c=_c.toLowerCase();
104
}
105
if(this.propercase){
106
_c=_c.replace(/[^\s]+/g,function(_d){
107
return _d.substring(0,1).toUpperCase()+_d.substring(1);
108
});
109
}
110
return _c;
111
},_setBlurValue:function(){
112
this._setValueAttr(this.get("value"),true);
113
},_onBlur:function(e){
114
if(this.disabled){
115
return;
116
}
117
this._setBlurValue();
118
this.inherited(arguments);
119
if(this._selectOnClickHandle){
120
this.disconnect(this._selectOnClickHandle);
121
}
122
if(this.selectOnClick&&dojo.isMoz){
123
this.textbox.selectionStart=this.textbox.selectionEnd=undefined;
124
}
125
},_onFocus:function(by){
126
if(this.disabled||this.readOnly){
127
return;
128
}
129
if(this.selectOnClick&&by=="mouse"){
130
this._selectOnClickHandle=this.connect(this.domNode,"onmouseup",function(){
131
this.disconnect(this._selectOnClickHandle);
132
var _e;
133
_e=this.textbox.selectionStart==this.textbox.selectionEnd;
134
if(_e){
135
this.selectInputText(this.textbox);
136
}
137
});
138
}
139
this._refreshState();
140
this.inherited(arguments);
141
},reset:function(){
142
this.textbox.value="";
143
this.inherited(arguments);
144
}});
145
}