root / trunk / web / dojo / dojox / mobile / app / _FormWidget.js
History | View | Annotate | Download (3.59 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["dojox.mobile.app._FormWidget"]){ |
9 |
dojo._hasResource["dojox.mobile.app._FormWidget"]=true; |
10 |
dojo.provide("dojox.mobile.app._FormWidget");
|
11 |
dojo.experimental("dojox.mobile.app._FormWidget");
|
12 |
dojo.require("dojo.window");
|
13 |
dojo.require("dijit._Widget");
|
14 |
dojo.declare("dojox.mobile.app._FormWidget",dijit._Widget,{name:"",alt:"",value:"",type:"text",disabled:false,intermediateChanges:false,scrollOnFocus:false,attributeMap:dojo.delegate(dijit._Widget.prototype.attributeMap,{value:"focusNode",id:"focusNode",alt:"focusNode",title:"focusNode"}),postMixInProperties:function(){ |
15 |
this.nameAttrSetting=this.name?("name=\""+this.name.replace(/'/g,""")+"\""):""; |
16 |
this.inherited(arguments); |
17 |
},postCreate:function(){ |
18 |
this.inherited(arguments); |
19 |
this.connect(this.domNode,"onmousedown","_onMouseDown"); |
20 |
},_setDisabledAttr:function(_1){ |
21 |
this.disabled=_1;
|
22 |
dojo.attr(this.focusNode,"disabled",_1); |
23 |
if(this.valueNode){ |
24 |
dojo.attr(this.valueNode,"disabled",_1); |
25 |
} |
26 |
if(_1){
|
27 |
this._hovering=false; |
28 |
this._active=false; |
29 |
} |
30 |
},_onFocus:function(e){ |
31 |
if(this.scrollOnFocus){ |
32 |
dojo.window.scrollIntoView(this.domNode);
|
33 |
} |
34 |
this.inherited(arguments); |
35 |
},isFocusable:function(){ |
36 |
return !this.disabled&&!this.readOnly&&this.focusNode&&(dojo.style(this.domNode,"display")!="none"); |
37 |
},focus:function(){ |
38 |
this.focusNode.focus();
|
39 |
},compare:function(_2,_3){ |
40 |
if(typeof _2=="number"&&typeof _3=="number"){ |
41 |
return (isNaN(_2)&&isNaN(_3))?0:_2-_3; |
42 |
}else{
|
43 |
if(_2>_3){
|
44 |
return 1; |
45 |
}else{
|
46 |
if(_2<_3){
|
47 |
return -1; |
48 |
}else{
|
49 |
return 0; |
50 |
} |
51 |
} |
52 |
} |
53 |
},onChange:function(_4){ |
54 |
},_onChangeActive:false,_handleOnChange:function(_5,_6){ |
55 |
this._lastValue=_5;
|
56 |
if(this._lastValueReported==undefined&&(_6===null||!this._onChangeActive)){ |
57 |
this._resetValue=this._lastValueReported=_5; |
58 |
} |
59 |
if((this.intermediateChanges||_6||_6===undefined)&&((typeof _5!=typeof this._lastValueReported)||this.compare(_5,this._lastValueReported)!=0)){ |
60 |
this._lastValueReported=_5;
|
61 |
if(this._onChangeActive){ |
62 |
if(this._onChangeHandle){ |
63 |
clearTimeout(this._onChangeHandle);
|
64 |
} |
65 |
this._onChangeHandle=setTimeout(dojo.hitch(this,function(){ |
66 |
this._onChangeHandle=null; |
67 |
this.onChange(_5);
|
68 |
}),0);
|
69 |
} |
70 |
} |
71 |
},create:function(){ |
72 |
this.inherited(arguments); |
73 |
this._onChangeActive=true; |
74 |
},destroy:function(){ |
75 |
if(this._onChangeHandle){ |
76 |
clearTimeout(this._onChangeHandle);
|
77 |
this.onChange(this._lastValueReported); |
78 |
} |
79 |
this.inherited(arguments); |
80 |
},_onMouseDown:function(e){ |
81 |
if(this.isFocusable()){ |
82 |
var _7=this.connect(dojo.body(),"onmouseup",function(){ |
83 |
if(this.isFocusable()){ |
84 |
this.focus();
|
85 |
} |
86 |
this.disconnect(_7);
|
87 |
}); |
88 |
} |
89 |
},selectInputText:function(_8,_9,_a){ |
90 |
var _b=dojo.global;
|
91 |
var _c=dojo.doc;
|
92 |
_8=dojo.byId(_8); |
93 |
if(isNaN(_9)){
|
94 |
_9=0;
|
95 |
} |
96 |
if(isNaN(_a)){
|
97 |
_a=_8.value?_8.value.length:0;
|
98 |
} |
99 |
dijit.focus(_8); |
100 |
if(_b["getSelection"]&&_8.setSelectionRange){ |
101 |
_8.setSelectionRange(_9,_a); |
102 |
} |
103 |
}}); |
104 |
dojo.declare("dojox.mobile.app._FormValueWidget",dojox.mobile.app._FormWidget,{readOnly:false,attributeMap:dojo.delegate(dojox.mobile.app._FormWidget.prototype.attributeMap,{value:"",readOnly:"focusNode"}),_setReadOnlyAttr:function(_d){ |
105 |
this.readOnly=_d;
|
106 |
dojo.attr(this.focusNode,"readOnly",_d); |
107 |
},postCreate:function(){ |
108 |
this.inherited(arguments); |
109 |
if(this._resetValue===undefined){ |
110 |
this._resetValue=this.value; |
111 |
} |
112 |
},_setValueAttr:function(_e,_f){ |
113 |
this.value=_e;
|
114 |
this._handleOnChange(_e,_f);
|
115 |
},_getValueAttr:function(){ |
116 |
return this._lastValue; |
117 |
},undo:function(){ |
118 |
this._setValueAttr(this._lastValueReported,false); |
119 |
},reset:function(){ |
120 |
this._hasBeenBlurred=false; |
121 |
this._setValueAttr(this._resetValue,true); |
122 |
}}); |
123 |
} |