root / trunk / web / dojo / dijit / _HasDropDown.js @ 9
History | View | Annotate | Download (5.27 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._HasDropDown"]){ |
9 |
dojo._hasResource["dijit._HasDropDown"]=true; |
10 |
dojo.provide("dijit._HasDropDown");
|
11 |
dojo.require("dijit._base.place");
|
12 |
dojo.require("dijit._Widget");
|
13 |
dojo.declare("dijit._HasDropDown",null,{_buttonNode:null,_arrowWrapperNode:null,_popupStateNode:null,_aroundNode:null,dropDown:null,autoWidth:true,forceWidth:false,maxHeight:0,dropDownPosition:["below","above"],_stopClickEvents:true,_onDropDownMouseDown:function(e){ |
14 |
if(this.disabled||this.readOnly){ |
15 |
return;
|
16 |
} |
17 |
this._docHandler=this.connect(dojo.doc,"onmouseup","_onDropDownMouseUp"); |
18 |
this.toggleDropDown();
|
19 |
},_onDropDownMouseUp:function(e){ |
20 |
if(e&&this._docHandler){ |
21 |
this.disconnect(this._docHandler); |
22 |
} |
23 |
var _1=this.dropDown,_2=false; |
24 |
if(e&&this._opened){ |
25 |
var c=dojo.position(this._buttonNode,true); |
26 |
if(!(e.pageX>=c.x&&e.pageX<=c.x+c.w)||!(e.pageY>=c.y&&e.pageY<=c.y+c.h)){
|
27 |
var t=e.target;
|
28 |
while(t&&!_2){
|
29 |
if(dojo.hasClass(t,"dijitPopup")){ |
30 |
_2=true;
|
31 |
}else{
|
32 |
t=t.parentNode; |
33 |
} |
34 |
} |
35 |
if(_2){
|
36 |
t=e.target; |
37 |
if(_1.onItemClick){
|
38 |
var _3;
|
39 |
while(t&&!(_3=dijit.byNode(t))){
|
40 |
t=t.parentNode; |
41 |
} |
42 |
if(_3&&_3.onClick&&_3.getParent){
|
43 |
_3.getParent().onItemClick(_3,e); |
44 |
} |
45 |
} |
46 |
return;
|
47 |
} |
48 |
} |
49 |
} |
50 |
if(this._opened&&_1.focus){ |
51 |
window.setTimeout(dojo.hitch(_1,"focus"),1); |
52 |
} |
53 |
},_onDropDownClick:function(e){ |
54 |
if(this._stopClickEvents){ |
55 |
dojo.stopEvent(e); |
56 |
} |
57 |
},_setupDropdown:function(){ |
58 |
this._buttonNode=this._buttonNode||this.focusNode||this.domNode; |
59 |
this._popupStateNode=this._popupStateNode||this.focusNode||this._buttonNode; |
60 |
this._aroundNode=this._aroundNode||this.domNode; |
61 |
this.connect(this._buttonNode,"onmousedown","_onDropDownMouseDown"); |
62 |
this.connect(this._buttonNode,"onclick","_onDropDownClick"); |
63 |
this.connect(this._buttonNode,"onkeydown","_onDropDownKeydown"); |
64 |
this.connect(this._buttonNode,"onkeyup","_onKey"); |
65 |
if(this._setStateClass){ |
66 |
this.connect(this,"openDropDown","_setStateClass"); |
67 |
this.connect(this,"closeDropDown","_setStateClass"); |
68 |
} |
69 |
var _4={"after":this.isLeftToRight()?"Right":"Left","before":this.isLeftToRight()?"Left":"Right","above":"Up","below":"Down","left":"Left","right":"Right"}[this.dropDownPosition[0]]||this.dropDownPosition[0]||"Down"; |
70 |
dojo.addClass(this._arrowWrapperNode||this._buttonNode,"dijit"+_4+"ArrowButton"); |
71 |
},postCreate:function(){ |
72 |
this._setupDropdown();
|
73 |
this.inherited(arguments); |
74 |
},destroyDescendants:function(){ |
75 |
if(this.dropDown){ |
76 |
if(!this.dropDown._destroyed){ |
77 |
this.dropDown.destroyRecursive();
|
78 |
} |
79 |
delete this.dropDown; |
80 |
} |
81 |
this.inherited(arguments); |
82 |
},_onDropDownKeydown:function(e){ |
83 |
if(e.keyCode==dojo.keys.DOWN_ARROW||e.keyCode==dojo.keys.ENTER||e.keyCode==dojo.keys.SPACE){
|
84 |
e.preventDefault(); |
85 |
} |
86 |
},_onKey:function(e){ |
87 |
if(this.disabled||this.readOnly){ |
88 |
return;
|
89 |
} |
90 |
var d=this.dropDown; |
91 |
if(d&&this._opened&&d.handleKey){ |
92 |
if(d.handleKey(e)===false){ |
93 |
return;
|
94 |
} |
95 |
} |
96 |
if(d&&this._opened&&e.keyCode==dojo.keys.ESCAPE){ |
97 |
this.toggleDropDown();
|
98 |
}else{
|
99 |
if(d&&!this._opened&&(e.keyCode==dojo.keys.DOWN_ARROW||e.keyCode==dojo.keys.ENTER||e.keyCode==dojo.keys.SPACE)){ |
100 |
this.toggleDropDown();
|
101 |
if(d.focus){
|
102 |
setTimeout(dojo.hitch(d,"focus"),1); |
103 |
} |
104 |
} |
105 |
} |
106 |
},_onBlur:function(){ |
107 |
this.closeDropDown();
|
108 |
this.inherited(arguments); |
109 |
},isLoaded:function(){ |
110 |
return true; |
111 |
},loadDropDown:function(_5){ |
112 |
_5(); |
113 |
},toggleDropDown:function(){ |
114 |
if(this.disabled||this.readOnly){ |
115 |
return;
|
116 |
} |
117 |
this.focus();
|
118 |
var _6=this.dropDown; |
119 |
if(!_6){
|
120 |
return;
|
121 |
} |
122 |
if(!this._opened){ |
123 |
if(!this.isLoaded()){ |
124 |
this.loadDropDown(dojo.hitch(this,"openDropDown")); |
125 |
return;
|
126 |
}else{
|
127 |
this.openDropDown();
|
128 |
} |
129 |
}else{
|
130 |
this.closeDropDown();
|
131 |
} |
132 |
},openDropDown:function(){ |
133 |
var _7=this.dropDown; |
134 |
var _8=_7.domNode;
|
135 |
var _9=this; |
136 |
if(!this._preparedNode){ |
137 |
dijit.popup.moveOffScreen(_8); |
138 |
this._preparedNode=true; |
139 |
if(_8.style.width){
|
140 |
this._explicitDDWidth=true; |
141 |
} |
142 |
if(_8.style.height){
|
143 |
this._explicitDDHeight=true; |
144 |
} |
145 |
} |
146 |
if(this.maxHeight||this.forceWidth||this.autoWidth){ |
147 |
var _a={display:"",visibility:"hidden"}; |
148 |
if(!this._explicitDDWidth){ |
149 |
_a.width="";
|
150 |
} |
151 |
if(!this._explicitDDHeight){ |
152 |
_a.height="";
|
153 |
} |
154 |
dojo.style(_8,_a); |
155 |
var mb=dojo.marginBox(_8);
|
156 |
var _b=(this.maxHeight&&mb.h>this.maxHeight); |
157 |
dojo.style(_8,{overflowX:"hidden",overflowY:_b?"auto":"hidden"}); |
158 |
if(_b){
|
159 |
mb.h=this.maxHeight;
|
160 |
if("w" in mb){ |
161 |
mb.w+=16;
|
162 |
} |
163 |
}else{
|
164 |
delete mb.h;
|
165 |
} |
166 |
delete mb.t;
|
167 |
delete mb.l;
|
168 |
if(this.forceWidth){ |
169 |
mb.w=this.domNode.offsetWidth;
|
170 |
}else{
|
171 |
if(this.autoWidth){ |
172 |
mb.w=Math.max(mb.w,this.domNode.offsetWidth);
|
173 |
}else{
|
174 |
delete mb.w;
|
175 |
} |
176 |
} |
177 |
if(dojo.isFunction(_7.resize)){
|
178 |
_7.resize(mb); |
179 |
}else{
|
180 |
dojo.marginBox(_8,mb); |
181 |
} |
182 |
} |
183 |
var _c=dijit.popup.open({parent:this,popup:_7,around:this._aroundNode,orient:dijit.getPopupAroundAlignment((this.dropDownPosition&&this.dropDownPosition.length)?this.dropDownPosition:["below"],this.isLeftToRight()),onExecute:function(){ |
184 |
_9.closeDropDown(true);
|
185 |
},onCancel:function(){ |
186 |
_9.closeDropDown(true);
|
187 |
},onClose:function(){ |
188 |
dojo.attr(_9._popupStateNode,"popupActive",false); |
189 |
dojo.removeClass(_9._popupStateNode,"dijitHasDropDownOpen");
|
190 |
_9._opened=false;
|
191 |
_9.state="";
|
192 |
}}); |
193 |
dojo.attr(this._popupStateNode,"popupActive","true"); |
194 |
dojo.addClass(_9._popupStateNode,"dijitHasDropDownOpen");
|
195 |
this._opened=true; |
196 |
this.state="Opened"; |
197 |
return _c;
|
198 |
},closeDropDown:function(_d){ |
199 |
if(this._opened){ |
200 |
if(_d){
|
201 |
this.focus();
|
202 |
} |
203 |
dijit.popup.close(this.dropDown);
|
204 |
this._opened=false; |
205 |
this.state=""; |
206 |
} |
207 |
}}); |
208 |
} |