root / trunk / web / dojo / dijit / form / _FormWidget.js
History | View | Annotate | Download (5.05 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["dijit.form._FormWidget"]){ |
||
| 9 | dojo._hasResource["dijit.form._FormWidget"]=true; |
||
| 10 | dojo.provide("dijit.form._FormWidget");
|
||
| 11 | dojo.require("dojo.window");
|
||
| 12 | dojo.require("dijit._Widget");
|
||
| 13 | dojo.require("dijit._Templated");
|
||
| 14 | dojo.require("dijit._CssStateMixin");
|
||
| 15 | dojo.declare("dijit.form._FormWidget",[dijit._Widget,dijit._Templated,dijit._CssStateMixin],{name:"",alt:"",value:"",type:"text",tabIndex:"0",disabled:false,intermediateChanges:false,scrollOnFocus:true,attributeMap:dojo.delegate(dijit._Widget.prototype.attributeMap,{value:"focusNode",id:"focusNode",tabIndex:"focusNode",alt:"focusNode",title:"focusNode"}),postMixInProperties:function(){ |
||
| 16 | this.nameAttrSetting=this.name?("name=\""+this.name.replace(/'/g,""")+"\""):""; |
||
| 17 | this.inherited(arguments); |
||
| 18 | },postCreate:function(){ |
||
| 19 | this.inherited(arguments); |
||
| 20 | this.connect(this.domNode,"onmousedown","_onMouseDown"); |
||
| 21 | },_setDisabledAttr:function(_1){ |
||
| 22 | this.disabled=_1;
|
||
| 23 | dojo.attr(this.focusNode,"disabled",_1); |
||
| 24 | if(this.valueNode){ |
||
| 25 | dojo.attr(this.valueNode,"disabled",_1); |
||
| 26 | } |
||
| 27 | dijit.setWaiState(this.focusNode,"disabled",_1); |
||
| 28 | if(_1){
|
||
| 29 | this._hovering=false; |
||
| 30 | this._active=false; |
||
| 31 | var _2="tabIndex" in this.attributeMap?this.attributeMap.tabIndex:"focusNode"; |
||
| 32 | dojo.forEach(dojo.isArray(_2)?_2:[_2],function(_3){
|
||
| 33 | var _4=this[_3]; |
||
| 34 | if(dojo.isWebKit||dijit.hasDefaultTabStop(_4)){
|
||
| 35 | _4.setAttribute("tabIndex","-1"); |
||
| 36 | }else{
|
||
| 37 | _4.removeAttribute("tabIndex");
|
||
| 38 | } |
||
| 39 | },this);
|
||
| 40 | }else{
|
||
| 41 | this.focusNode.setAttribute("tabIndex",this.tabIndex); |
||
| 42 | } |
||
| 43 | },setDisabled:function(_5){ |
||
| 44 | dojo.deprecated("setDisabled("+_5+") is deprecated. Use set('disabled',"+_5+") instead.","","2.0"); |
||
| 45 | this.set("disabled",_5); |
||
| 46 | },_onFocus:function(e){ |
||
| 47 | if(this.scrollOnFocus){ |
||
| 48 | dojo.window.scrollIntoView(this.domNode);
|
||
| 49 | } |
||
| 50 | this.inherited(arguments); |
||
| 51 | },isFocusable:function(){ |
||
| 52 | return !this.disabled&&!this.readOnly&&this.focusNode&&(dojo.style(this.domNode,"display")!="none"); |
||
| 53 | },focus:function(){ |
||
| 54 | dijit.focus(this.focusNode);
|
||
| 55 | },compare:function(_6,_7){ |
||
| 56 | if(typeof _6=="number"&&typeof _7=="number"){ |
||
| 57 | return (isNaN(_6)&&isNaN(_7))?0:_6-_7; |
||
| 58 | }else{
|
||
| 59 | if(_6>_7){
|
||
| 60 | return 1; |
||
| 61 | }else{
|
||
| 62 | if(_6<_7){
|
||
| 63 | return -1; |
||
| 64 | }else{
|
||
| 65 | return 0; |
||
| 66 | } |
||
| 67 | } |
||
| 68 | } |
||
| 69 | },onChange:function(_8){ |
||
| 70 | },_onChangeActive:false,_handleOnChange:function(_9,_a){ |
||
| 71 | this._lastValue=_9;
|
||
| 72 | if(this._lastValueReported==undefined&&(_a===null||!this._onChangeActive)){ |
||
| 73 | this._resetValue=this._lastValueReported=_9; |
||
| 74 | } |
||
| 75 | if((this.intermediateChanges||_a||_a===undefined)&&((typeof _9!=typeof this._lastValueReported)||this.compare(_9,this._lastValueReported)!=0)){ |
||
| 76 | this._lastValueReported=_9;
|
||
| 77 | if(this._onChangeActive){ |
||
| 78 | if(this._onChangeHandle){ |
||
| 79 | clearTimeout(this._onChangeHandle);
|
||
| 80 | } |
||
| 81 | this._onChangeHandle=setTimeout(dojo.hitch(this,function(){ |
||
| 82 | this._onChangeHandle=null; |
||
| 83 | this.onChange(_9);
|
||
| 84 | }),0);
|
||
| 85 | } |
||
| 86 | } |
||
| 87 | },create:function(){ |
||
| 88 | this.inherited(arguments); |
||
| 89 | this._onChangeActive=true; |
||
| 90 | },destroy:function(){ |
||
| 91 | if(this._onChangeHandle){ |
||
| 92 | clearTimeout(this._onChangeHandle);
|
||
| 93 | this.onChange(this._lastValueReported); |
||
| 94 | } |
||
| 95 | this.inherited(arguments); |
||
| 96 | },setValue:function(_b){ |
||
| 97 | dojo.deprecated("dijit.form._FormWidget:setValue("+_b+") is deprecated. Use set('value',"+_b+") instead.","","2.0"); |
||
| 98 | this.set("value",_b); |
||
| 99 | },getValue:function(){ |
||
| 100 | dojo.deprecated(this.declaredClass+"::getValue() is deprecated. Use get('value') instead.","","2.0"); |
||
| 101 | return this.get("value"); |
||
| 102 | },_onMouseDown:function(e){ |
||
| 103 | if(!e.ctrlKey&&this.isFocusable()){ |
||
| 104 | var _c=this.connect(dojo.body(),"onmouseup",function(){ |
||
| 105 | if(this.isFocusable()){ |
||
| 106 | this.focus();
|
||
| 107 | } |
||
| 108 | this.disconnect(_c);
|
||
| 109 | }); |
||
| 110 | } |
||
| 111 | }}); |
||
| 112 | dojo.declare("dijit.form._FormValueWidget",dijit.form._FormWidget,{readOnly:false,attributeMap:dojo.delegate(dijit.form._FormWidget.prototype.attributeMap,{value:"",readOnly:"focusNode"}),_setReadOnlyAttr:function(_d){ |
||
| 113 | this.readOnly=_d;
|
||
| 114 | dojo.attr(this.focusNode,"readOnly",_d); |
||
| 115 | dijit.setWaiState(this.focusNode,"readonly",_d); |
||
| 116 | },postCreate:function(){ |
||
| 117 | this.inherited(arguments); |
||
| 118 | if(dojo.isIE){
|
||
| 119 | this.connect(this.focusNode||this.domNode,"onkeydown",this._onKeyDown); |
||
| 120 | } |
||
| 121 | if(this._resetValue===undefined){ |
||
| 122 | this._resetValue=this.value; |
||
| 123 | } |
||
| 124 | },_setValueAttr:function(_e,_f){ |
||
| 125 | this.value=_e;
|
||
| 126 | this._handleOnChange(_e,_f);
|
||
| 127 | },_getValueAttr:function(){ |
||
| 128 | return this._lastValue; |
||
| 129 | },undo:function(){ |
||
| 130 | this._setValueAttr(this._lastValueReported,false); |
||
| 131 | },reset:function(){ |
||
| 132 | this._hasBeenBlurred=false; |
||
| 133 | this._setValueAttr(this._resetValue,true); |
||
| 134 | },_onKeyDown:function(e){ |
||
| 135 | if(e.keyCode==dojo.keys.ESCAPE&&!(e.ctrlKey||e.altKey||e.metaKey)){
|
||
| 136 | var te;
|
||
| 137 | if(dojo.isIE){
|
||
| 138 | e.preventDefault(); |
||
| 139 | te=document.createEventObject(); |
||
| 140 | te.keyCode=dojo.keys.ESCAPE; |
||
| 141 | te.shiftKey=e.shiftKey; |
||
| 142 | e.srcElement.fireEvent("onkeypress",te);
|
||
| 143 | } |
||
| 144 | } |
||
| 145 | },_layoutHackIE7:function(){ |
||
| 146 | if(dojo.isIE==7){ |
||
| 147 | var _10=this.domNode; |
||
| 148 | var _11=_10.parentNode;
|
||
| 149 | var _12=_10.firstChild||_10;
|
||
| 150 | var _13=_12.style.filter;
|
||
| 151 | var _14=this; |
||
| 152 | while(_11&&_11.clientHeight==0){ |
||
| 153 | (function ping(){ |
||
| 154 | var _15=_14.connect(_11,"onscroll",function(e){ |
||
| 155 | _14.disconnect(_15); |
||
| 156 | _12.style.filter=(new Date()).getMilliseconds();
|
||
| 157 | setTimeout(function(){
|
||
| 158 | _12.style.filter=_13; |
||
| 159 | },0);
|
||
| 160 | }); |
||
| 161 | })(); |
||
| 162 | _11=_11.parentNode; |
||
| 163 | } |
||
| 164 | } |
||
| 165 | }}); |
||
| 166 | } |