MenuBar.js 2.4 KB

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