MenuBar.js.uncompressed.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. // module:
  11. // dijit/MenuBar
  12. return declare("dijit.MenuBar", _MenuBase, {
  13. // summary:
  14. // A menu bar, listing menu choices horizontally, like the "File" menu in most desktop applications
  15. templateString: template,
  16. baseClass: "dijitMenuBar",
  17. // _isMenuBar: [protected] Boolean
  18. // This is a MenuBar widget, not a (vertical) Menu widget.
  19. _isMenuBar: true,
  20. postCreate: function(){
  21. this.inherited(arguments);
  22. var l = this.isLeftToRight();
  23. this.connectKeyNavHandlers(
  24. l ? [keys.LEFT_ARROW] : [keys.RIGHT_ARROW],
  25. l ? [keys.RIGHT_ARROW] : [keys.LEFT_ARROW]
  26. );
  27. // parameter to dijit.popup.open() about where to put popup (relative to this.domNode)
  28. this._orient = ["below"];
  29. },
  30. _moveToPopup: function(/*Event*/ evt){
  31. // summary:
  32. // This handles the down arrow key, opening a submenu if one exists.
  33. // Unlike _MenuBase._moveToPopup(), will never move to the next item in the MenuBar.
  34. // tags:
  35. // private
  36. if(this.focusedChild && this.focusedChild.popup && !this.focusedChild.disabled){
  37. this.onItemClick(this.focusedChild, evt);
  38. }
  39. },
  40. focusChild: function(item){
  41. // overload focusChild so that whenever the focus is moved to a new item,
  42. // check the previous focused whether it has its popup open, if so, after
  43. // focusing the new item, open its submenu immediately
  44. var prev_item = this.focusedChild,
  45. showpopup = prev_item && prev_item.popup && prev_item.popup.isShowingNow;
  46. this.inherited(arguments);
  47. if(showpopup && item.popup && !item.disabled){
  48. this._openPopup(true); // TODO: on down arrow, _openPopup() is called here and in onItemClick()
  49. }
  50. },
  51. _onKeyPress: function(/*Event*/ evt){
  52. // summary:
  53. // Handle keyboard based menu navigation.
  54. // tags:
  55. // protected
  56. if(evt.ctrlKey || evt.altKey){ return; }
  57. switch(evt.charOrCode){
  58. case keys.DOWN_ARROW:
  59. this._moveToPopup(evt);
  60. event.stop(evt);
  61. }
  62. },
  63. onItemClick: function(/*dijit/_WidgetBase*/ item, /*Event*/ evt){
  64. // summary:
  65. // Handle clicks on an item. Also called by _moveToPopup() due to a down-arrow key on the item.
  66. // Cancels a dropdown if already open and click is either mouse or space/enter.
  67. // Don't close dropdown due to down arrow.
  68. // tags:
  69. // private
  70. if(item.popup && item.popup.isShowingNow && (evt.type !== "keypress" || evt.keyCode !== keys.DOWN_ARROW)){
  71. item.popup.onCancel();
  72. }else{
  73. this.inherited(arguments);
  74. }
  75. }
  76. });
  77. });