MenuBar.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. Copyright (c) 2004-2012, 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. if(!dojo._hasResource["dijit.MenuBar"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dijit.MenuBar"] = true;
  8. dojo.provide("dijit.MenuBar");
  9. dojo.require("dijit.Menu");
  10. dojo.declare("dijit.MenuBar", dijit._MenuBase, {
  11. // summary:
  12. // A menu bar, listing menu choices horizontally, like the "File" menu in most desktop applications
  13. templateString: dojo.cache("dijit", "templates/MenuBar.html", "<div class=\"dijitMenuBar dijitMenuPassive\" dojoAttachPoint=\"containerNode\" role=\"menubar\" tabIndex=\"${tabIndex}\" dojoAttachEvent=\"onkeypress: _onKeyPress\"></div>\n"),
  14. baseClass: "dijitMenuBar",
  15. // _isMenuBar: [protected] Boolean
  16. // This is a MenuBar widget, not a (vertical) Menu widget.
  17. _isMenuBar: true,
  18. postCreate: function(){
  19. var k = dojo.keys, l = this.isLeftToRight();
  20. this.connectKeyNavHandlers(
  21. l ? [k.LEFT_ARROW] : [k.RIGHT_ARROW],
  22. l ? [k.RIGHT_ARROW] : [k.LEFT_ARROW]
  23. );
  24. // parameter to dijit.popup.open() about where to put popup (relative to this.domNode)
  25. this._orient = this.isLeftToRight() ? {BL: 'TL'} : {BR: 'TR'};
  26. },
  27. focusChild: function(item){
  28. // overload focusChild so that whenever the focus is moved to a new item,
  29. // check the previous focused whether it has its popup open, if so, after
  30. // focusing the new item, open its submenu immediately
  31. var prev_item = this.focusedChild,
  32. showpopup = prev_item && prev_item.popup && prev_item.popup.isShowingNow;
  33. this.inherited(arguments);
  34. if(showpopup && item.popup && !item.disabled){
  35. this._openPopup(); // TODO: on down arrow, _openPopup() is called here and in onItemClick()
  36. }
  37. },
  38. _onKeyPress: function(/*Event*/ evt){
  39. // summary:
  40. // Handle keyboard based menu navigation.
  41. // tags:
  42. // protected
  43. if(evt.ctrlKey || evt.altKey){ return; }
  44. switch(evt.charOrCode){
  45. case dojo.keys.DOWN_ARROW:
  46. this._moveToPopup(evt);
  47. dojo.stopEvent(evt);
  48. }
  49. },
  50. onItemClick: function(/*dijit._Widget*/ item, /*Event*/ evt){
  51. // summary:
  52. // Handle clicks on an item. Cancels a dropdown if already open.
  53. // tags:
  54. // private
  55. if(item.popup && item.popup.isShowingNow){
  56. item.popup.onCancel();
  57. }else{
  58. this.inherited(arguments);
  59. }
  60. }
  61. });
  62. }