root / trunk / web / dojo / dijit / Menu.js @ 13
History | View | Annotate | Download (8.95 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.Menu"]){ |
||
9 | dojo._hasResource["dijit.Menu"]=true; |
||
10 | dojo.provide("dijit.Menu");
|
||
11 | dojo.require("dojo.window");
|
||
12 | dojo.require("dijit._Widget");
|
||
13 | dojo.require("dijit._KeyNavContainer");
|
||
14 | dojo.require("dijit._Templated");
|
||
15 | dojo.declare("dijit._MenuBase",[dijit._Widget,dijit._Templated,dijit._KeyNavContainer],{parentMenu:null,popupDelay:500,startup:function(){ |
||
16 | if(this._started){ |
||
17 | return;
|
||
18 | } |
||
19 | dojo.forEach(this.getChildren(),function(_1){ |
||
20 | _1.startup(); |
||
21 | }); |
||
22 | this.startupKeyNavChildren();
|
||
23 | this.inherited(arguments); |
||
24 | },onExecute:function(){ |
||
25 | },onCancel:function(_2){ |
||
26 | },_moveToPopup:function(_3){ |
||
27 | if(this.focusedChild&&this.focusedChild.popup&&!this.focusedChild.disabled){ |
||
28 | this.focusedChild._onClick(_3);
|
||
29 | }else{
|
||
30 | var _4=this._getTopMenu(); |
||
31 | if(_4&&_4._isMenuBar){
|
||
32 | _4.focusNext(); |
||
33 | } |
||
34 | } |
||
35 | },_onPopupHover:function(_5){ |
||
36 | if(this.currentPopup&&this.currentPopup._pendingClose_timer){ |
||
37 | var _6=this.currentPopup.parentMenu; |
||
38 | if(_6.focusedChild){
|
||
39 | _6.focusedChild._setSelected(false);
|
||
40 | } |
||
41 | _6.focusedChild=this.currentPopup.from_item;
|
||
42 | _6.focusedChild._setSelected(true);
|
||
43 | this._stopPendingCloseTimer(this.currentPopup); |
||
44 | } |
||
45 | },onItemHover:function(_7){ |
||
46 | if(this.isActive){ |
||
47 | this.focusChild(_7);
|
||
48 | if(this.focusedChild.popup&&!this.focusedChild.disabled&&!this.hover_timer){ |
||
49 | this.hover_timer=setTimeout(dojo.hitch(this,"_openPopup"),this.popupDelay); |
||
50 | } |
||
51 | } |
||
52 | if(this.focusedChild){ |
||
53 | this.focusChild(_7);
|
||
54 | } |
||
55 | this._hoveredChild=_7;
|
||
56 | },_onChildBlur:function(_8){ |
||
57 | this._stopPopupTimer();
|
||
58 | _8._setSelected(false);
|
||
59 | var _9=_8.popup;
|
||
60 | if(_9){
|
||
61 | this._stopPendingCloseTimer(_9);
|
||
62 | _9._pendingClose_timer=setTimeout(function(){
|
||
63 | _9._pendingClose_timer=null;
|
||
64 | if(_9.parentMenu){
|
||
65 | _9.parentMenu.currentPopup=null;
|
||
66 | } |
||
67 | dijit.popup.close(_9); |
||
68 | },this.popupDelay);
|
||
69 | } |
||
70 | },onItemUnhover:function(_a){ |
||
71 | if(this.isActive){ |
||
72 | this._stopPopupTimer();
|
||
73 | } |
||
74 | if(this._hoveredChild==_a){ |
||
75 | this._hoveredChild=null; |
||
76 | } |
||
77 | },_stopPopupTimer:function(){ |
||
78 | if(this.hover_timer){ |
||
79 | clearTimeout(this.hover_timer);
|
||
80 | this.hover_timer=null; |
||
81 | } |
||
82 | },_stopPendingCloseTimer:function(_b){ |
||
83 | if(_b._pendingClose_timer){
|
||
84 | clearTimeout(_b._pendingClose_timer); |
||
85 | _b._pendingClose_timer=null;
|
||
86 | } |
||
87 | },_stopFocusTimer:function(){ |
||
88 | if(this._focus_timer){ |
||
89 | clearTimeout(this._focus_timer);
|
||
90 | this._focus_timer=null; |
||
91 | } |
||
92 | },_getTopMenu:function(){ |
||
93 | for(var _c=this;_c.parentMenu;_c=_c.parentMenu){ |
||
94 | } |
||
95 | return _c;
|
||
96 | },onItemClick:function(_d,_e){ |
||
97 | if(typeof this.isShowingNow=="undefined"){ |
||
98 | this._markActive();
|
||
99 | } |
||
100 | this.focusChild(_d);
|
||
101 | if(_d.disabled){
|
||
102 | return false; |
||
103 | } |
||
104 | if(_d.popup){
|
||
105 | this._openPopup();
|
||
106 | }else{
|
||
107 | this.onExecute();
|
||
108 | _d.onClick(_e); |
||
109 | } |
||
110 | },_openPopup:function(){ |
||
111 | this._stopPopupTimer();
|
||
112 | var _f=this.focusedChild; |
||
113 | if(!_f){
|
||
114 | return;
|
||
115 | } |
||
116 | var _10=_f.popup;
|
||
117 | if(_10.isShowingNow){
|
||
118 | return;
|
||
119 | } |
||
120 | if(this.currentPopup){ |
||
121 | this._stopPendingCloseTimer(this.currentPopup); |
||
122 | dijit.popup.close(this.currentPopup);
|
||
123 | } |
||
124 | _10.parentMenu=this;
|
||
125 | _10.from_item=_f; |
||
126 | var _11=this; |
||
127 | dijit.popup.open({parent:this,popup:_10,around:_f.domNode,orient:this._orient||(this.isLeftToRight()?{"TR":"TL","TL":"TR","BR":"BL","BL":"BR"}:{"TL":"TR","TR":"TL","BL":"BR","BR":"BL"}),onCancel:function(){ |
||
128 | _11.focusChild(_f); |
||
129 | _11._cleanUp(); |
||
130 | _f._setSelected(true);
|
||
131 | _11.focusedChild=_f; |
||
132 | },onExecute:dojo.hitch(this,"_cleanUp")}); |
||
133 | this.currentPopup=_10;
|
||
134 | _10.connect(_10.domNode,"onmouseenter",dojo.hitch(_11,"_onPopupHover")); |
||
135 | if(_10.focus){
|
||
136 | _10._focus_timer=setTimeout(dojo.hitch(_10,function(){
|
||
137 | this._focus_timer=null; |
||
138 | this.focus();
|
||
139 | }),0);
|
||
140 | } |
||
141 | },_markActive:function(){ |
||
142 | this.isActive=true; |
||
143 | dojo.addClass(this.domNode,"dijitMenuActive"); |
||
144 | dojo.removeClass(this.domNode,"dijitMenuPassive"); |
||
145 | },onOpen:function(e){ |
||
146 | this.isShowingNow=true; |
||
147 | this._markActive();
|
||
148 | },_markInactive:function(){ |
||
149 | this.isActive=false; |
||
150 | dojo.removeClass(this.domNode,"dijitMenuActive"); |
||
151 | dojo.addClass(this.domNode,"dijitMenuPassive"); |
||
152 | },onClose:function(){ |
||
153 | this._stopFocusTimer();
|
||
154 | this._markInactive();
|
||
155 | this.isShowingNow=false; |
||
156 | this.parentMenu=null; |
||
157 | },_closeChild:function(){ |
||
158 | this._stopPopupTimer();
|
||
159 | if(this.focusedChild){ |
||
160 | this.focusedChild._setSelected(false); |
||
161 | this.focusedChild._onUnhover();
|
||
162 | this.focusedChild=null; |
||
163 | } |
||
164 | if(this.currentPopup){ |
||
165 | dijit.popup.close(this.currentPopup);
|
||
166 | this.currentPopup=null; |
||
167 | } |
||
168 | },_onItemFocus:function(_12){ |
||
169 | if(this._hoveredChild&&this._hoveredChild!=_12){ |
||
170 | this._hoveredChild._onUnhover();
|
||
171 | } |
||
172 | },_onBlur:function(){ |
||
173 | this._cleanUp();
|
||
174 | this.inherited(arguments); |
||
175 | },_cleanUp:function(){ |
||
176 | this._closeChild();
|
||
177 | if(typeof this.isShowingNow=="undefined"){ |
||
178 | this._markInactive();
|
||
179 | } |
||
180 | }}); |
||
181 | dojo.declare("dijit.Menu",dijit._MenuBase,{constructor:function(){ |
||
182 | this._bindings=[];
|
||
183 | },templateString:dojo.cache("dijit","templates/Menu.html","<table class=\"dijit dijitMenu dijitMenuPassive dijitReset dijitMenuTable\" waiRole=\"menu\" tabIndex=\"${tabIndex}\" dojoAttachEvent=\"onkeypress:_onKeyPress\" cellspacing=0>\n\t<tbody class=\"dijitReset\" dojoAttachPoint=\"containerNode\"></tbody>\n</table>\n"),baseClass:"dijitMenu",targetNodeIds:[],contextMenuForWindow:false,leftClickToOpen:false,refocus:true,postCreate:function(){ |
||
184 | if(this.contextMenuForWindow){ |
||
185 | this.bindDomNode(dojo.body());
|
||
186 | }else{
|
||
187 | dojo.forEach(this.targetNodeIds,this.bindDomNode,this); |
||
188 | } |
||
189 | var k=dojo.keys,l=this.isLeftToRight(); |
||
190 | this._openSubMenuKey=l?k.RIGHT_ARROW:k.LEFT_ARROW;
|
||
191 | this._closeSubMenuKey=l?k.LEFT_ARROW:k.RIGHT_ARROW;
|
||
192 | this.connectKeyNavHandlers([k.UP_ARROW],[k.DOWN_ARROW]);
|
||
193 | },_onKeyPress:function(evt){ |
||
194 | if(evt.ctrlKey||evt.altKey){
|
||
195 | return;
|
||
196 | } |
||
197 | switch(evt.charOrCode){
|
||
198 | case this._openSubMenuKey: |
||
199 | this._moveToPopup(evt);
|
||
200 | dojo.stopEvent(evt); |
||
201 | break;
|
||
202 | case this._closeSubMenuKey: |
||
203 | if(this.parentMenu){ |
||
204 | if(this.parentMenu._isMenuBar){ |
||
205 | this.parentMenu.focusPrev();
|
||
206 | }else{
|
||
207 | this.onCancel(false); |
||
208 | } |
||
209 | }else{
|
||
210 | dojo.stopEvent(evt); |
||
211 | } |
||
212 | break;
|
||
213 | } |
||
214 | },_iframeContentWindow:function(_13){ |
||
215 | var win=dojo.window.get(this._iframeContentDocument(_13))||this._iframeContentDocument(_13)["__parent__"]||(_13.name&&dojo.doc.frames[_13.name])||null; |
||
216 | return win;
|
||
217 | },_iframeContentDocument:function(_14){ |
||
218 | var doc=_14.contentDocument||(_14.contentWindow&&_14.contentWindow.document)||(_14.name&&dojo.doc.frames[_14.name]&&dojo.doc.frames[_14.name].document)||null; |
||
219 | return doc;
|
||
220 | },bindDomNode:function(_15){ |
||
221 | _15=dojo.byId(_15); |
||
222 | var cn;
|
||
223 | if(_15.tagName.toLowerCase()=="iframe"){ |
||
224 | var _16=_15,win=this._iframeContentWindow(_16); |
||
225 | cn=dojo.withGlobal(win,dojo.body); |
||
226 | }else{
|
||
227 | cn=(_15==dojo.body()?dojo.doc.documentElement:_15); |
||
228 | } |
||
229 | var _17={node:_15,iframe:_16}; |
||
230 | dojo.attr(_15,"_dijitMenu"+this.id,this._bindings.push(_17)); |
||
231 | var _18=dojo.hitch(this,function(cn){ |
||
232 | return [dojo.connect(cn,this.leftClickToOpen?"onclick":"oncontextmenu",this,function(evt){ |
||
233 | dojo.stopEvent(evt); |
||
234 | this._scheduleOpen(evt.target,_16,{x:evt.pageX,y:evt.pageY}); |
||
235 | }),dojo.connect(cn,"onkeydown",this,function(evt){ |
||
236 | if(evt.shiftKey&&evt.keyCode==dojo.keys.F10){
|
||
237 | dojo.stopEvent(evt); |
||
238 | this._scheduleOpen(evt.target,_16);
|
||
239 | } |
||
240 | })]; |
||
241 | }); |
||
242 | _17.connects=cn?_18(cn):[]; |
||
243 | if(_16){
|
||
244 | _17.onloadHandler=dojo.hitch(this,function(){ |
||
245 | var win=this._iframeContentWindow(_16); |
||
246 | cn=dojo.withGlobal(win,dojo.body); |
||
247 | _17.connects=_18(cn); |
||
248 | }); |
||
249 | if(_16.addEventListener){
|
||
250 | _16.addEventListener("load",_17.onloadHandler,false); |
||
251 | }else{
|
||
252 | _16.attachEvent("onload",_17.onloadHandler);
|
||
253 | } |
||
254 | } |
||
255 | },unBindDomNode:function(_19){ |
||
256 | var _1a;
|
||
257 | try{
|
||
258 | _1a=dojo.byId(_19); |
||
259 | } |
||
260 | catch(e){
|
||
261 | return;
|
||
262 | } |
||
263 | var _1b="_dijitMenu"+this.id; |
||
264 | if(_1a&&dojo.hasAttr(_1a,_1b)){
|
||
265 | var bid=dojo.attr(_1a,_1b)-1,b=this._bindings[bid]; |
||
266 | dojo.forEach(b.connects,dojo.disconnect); |
||
267 | var _1c=b.iframe;
|
||
268 | if(_1c){
|
||
269 | if(_1c.removeEventListener){
|
||
270 | _1c.removeEventListener("load",b.onloadHandler,false); |
||
271 | }else{
|
||
272 | _1c.detachEvent("onload",b.onloadHandler);
|
||
273 | } |
||
274 | } |
||
275 | dojo.removeAttr(_1a,_1b); |
||
276 | delete this._bindings[bid]; |
||
277 | } |
||
278 | },_scheduleOpen:function(_1d,_1e,_1f){ |
||
279 | if(!this._openTimer){ |
||
280 | this._openTimer=setTimeout(dojo.hitch(this,function(){ |
||
281 | delete this._openTimer; |
||
282 | this._openMyself({target:_1d,iframe:_1e,coords:_1f}); |
||
283 | }),1);
|
||
284 | } |
||
285 | },_openMyself:function(_20){ |
||
286 | var _21=_20.target,_22=_20.iframe,_23=_20.coords;
|
||
287 | if(_23){
|
||
288 | if(_22){
|
||
289 | var od=_21.ownerDocument,ifc=dojo.position(_22,true),win=this._iframeContentWindow(_22),_24=dojo.withGlobal(win,"_docScroll",dojo); |
||
290 | var cs=dojo.getComputedStyle(_22),tp=dojo._toPixelValue,_25=(dojo.isIE&&dojo.isQuirks?0:tp(_22,cs.paddingLeft))+(dojo.isIE&&dojo.isQuirks?tp(_22,cs.borderLeftWidth):0),top=(dojo.isIE&&dojo.isQuirks?0:tp(_22,cs.paddingTop))+(dojo.isIE&&dojo.isQuirks?tp(_22,cs.borderTopWidth):0); |
||
291 | _23.x+=ifc.x+_25-_24.x; |
||
292 | _23.y+=ifc.y+top-_24.y; |
||
293 | } |
||
294 | }else{
|
||
295 | _23=dojo.position(_21,true);
|
||
296 | _23.x+=10;
|
||
297 | _23.y+=10;
|
||
298 | } |
||
299 | var _26=this; |
||
300 | var _27=dijit.getFocus(this); |
||
301 | function _28(){ |
||
302 | if(_26.refocus){
|
||
303 | dijit.focus(_27); |
||
304 | } |
||
305 | dijit.popup.close(_26); |
||
306 | }; |
||
307 | dijit.popup.open({popup:this,x:_23.x,y:_23.y,onExecute:_28,onCancel:_28,orient:this.isLeftToRight()?"L":"R"}); |
||
308 | this.focus();
|
||
309 | this._onBlur=function(){ |
||
310 | this.inherited("_onBlur",arguments); |
||
311 | dijit.popup.close(this);
|
||
312 | }; |
||
313 | },uninitialize:function(){ |
||
314 | dojo.forEach(this._bindings,function(b){ |
||
315 | if(b){
|
||
316 | this.unBindDomNode(b.node);
|
||
317 | } |
||
318 | },this);
|
||
319 | this.inherited(arguments); |
||
320 | }}); |
||
321 | dojo.require("dijit.MenuItem");
|
||
322 | dojo.require("dijit.PopupMenuItem");
|
||
323 | dojo.require("dijit.CheckedMenuItem");
|
||
324 | dojo.require("dijit.MenuSeparator");
|
||
325 | } |