1 | define([ |
---|
2 | "dojo/_base/declare", // declare |
---|
3 | "dojo/_base/event", // event.stop |
---|
4 | "dojo/keys", // keys.DOWN_ARROW |
---|
5 | "./_MenuBase", |
---|
6 | "dojo/text!./templates/MenuBar.html" |
---|
7 | ], function(declare, event, keys, _MenuBase, template){ |
---|
8 | |
---|
9 | /*===== |
---|
10 | var _MenuBase = dijit._MenuBase; |
---|
11 | =====*/ |
---|
12 | |
---|
13 | // module: |
---|
14 | // dijit/MenuBar |
---|
15 | // summary: |
---|
16 | // A menu bar, listing menu choices horizontally, like the "File" menu in most desktop applications |
---|
17 | |
---|
18 | return declare("dijit.MenuBar", _MenuBase, { |
---|
19 | // summary: |
---|
20 | // A menu bar, listing menu choices horizontally, like the "File" menu in most desktop applications |
---|
21 | |
---|
22 | templateString: template, |
---|
23 | |
---|
24 | baseClass: "dijitMenuBar", |
---|
25 | |
---|
26 | // _isMenuBar: [protected] Boolean |
---|
27 | // This is a MenuBar widget, not a (vertical) Menu widget. |
---|
28 | _isMenuBar: true, |
---|
29 | |
---|
30 | postCreate: function(){ |
---|
31 | var l = this.isLeftToRight(); |
---|
32 | this.connectKeyNavHandlers( |
---|
33 | l ? [keys.LEFT_ARROW] : [keys.RIGHT_ARROW], |
---|
34 | l ? [keys.RIGHT_ARROW] : [keys.LEFT_ARROW] |
---|
35 | ); |
---|
36 | |
---|
37 | // parameter to dijit.popup.open() about where to put popup (relative to this.domNode) |
---|
38 | this._orient = ["below"]; |
---|
39 | }, |
---|
40 | |
---|
41 | focusChild: function(item){ |
---|
42 | // overload focusChild so that whenever the focus is moved to a new item, |
---|
43 | // check the previous focused whether it has its popup open, if so, after |
---|
44 | // focusing the new item, open its submenu immediately |
---|
45 | var prev_item = this.focusedChild, |
---|
46 | showpopup = prev_item && prev_item.popup && prev_item.popup.isShowingNow; |
---|
47 | this.inherited(arguments); |
---|
48 | if(showpopup && item.popup && !item.disabled){ |
---|
49 | this._openPopup(); // TODO: on down arrow, _openPopup() is called here and in onItemClick() |
---|
50 | } |
---|
51 | }, |
---|
52 | |
---|
53 | _onKeyPress: function(/*Event*/ evt){ |
---|
54 | // summary: |
---|
55 | // Handle keyboard based menu navigation. |
---|
56 | // tags: |
---|
57 | // protected |
---|
58 | |
---|
59 | if(evt.ctrlKey || evt.altKey){ return; } |
---|
60 | |
---|
61 | switch(evt.charOrCode){ |
---|
62 | case keys.DOWN_ARROW: |
---|
63 | this._moveToPopup(evt); |
---|
64 | event.stop(evt); |
---|
65 | } |
---|
66 | }, |
---|
67 | |
---|
68 | onItemClick: function(/*dijit._Widget*/ item, /*Event*/ evt){ |
---|
69 | // summary: |
---|
70 | // Handle clicks on an item. Cancels a dropdown if already open. |
---|
71 | // tags: |
---|
72 | // private |
---|
73 | if(item.popup && item.popup.isShowingNow){ |
---|
74 | item.popup.onCancel(); |
---|
75 | }else{ |
---|
76 | this.inherited(arguments); |
---|
77 | } |
---|
78 | } |
---|
79 | }); |
---|
80 | |
---|
81 | }); |
---|