/ext-4.1.0_b3/docs/extjs/examples/desktop/js/StartMenu.js

https://bitbucket.org/srogerf/javascript · JavaScript · 101 lines · 65 code · 23 blank · 13 comment · 5 complexity · 1d1201bbdaf360312ae17c80b62e3d96 MD5 · raw file

  1. /*!
  2. * Ext JS Library 4.0
  3. * Copyright(c) 2006-2011 Sencha Inc.
  4. * licensing@sencha.com
  5. * http://www.sencha.com/license
  6. */
  7. Ext.define('Ext.ux.desktop.StartMenu', {
  8. extend: 'Ext.panel.Panel',
  9. requires: [
  10. 'Ext.menu.Menu',
  11. 'Ext.toolbar.Toolbar'
  12. ],
  13. ariaRole: 'menu',
  14. cls: 'x-menu ux-start-menu',
  15. defaultAlign: 'bl-tl',
  16. iconCls: 'user',
  17. floating: true,
  18. shadow: true,
  19. // We have to hardcode a width because the internal Menu cannot drive our width.
  20. // This is combined with changing the align property of the menu's layout from the
  21. // typical 'stretchmax' to 'stretch' which allows the the items to fill the menu
  22. // area.
  23. width: 300,
  24. initComponent: function() {
  25. var me = this, menu = me.menu;
  26. me.menu = new Ext.menu.Menu({
  27. cls: 'ux-start-menu-body',
  28. border: false,
  29. floating: false,
  30. items: menu
  31. });
  32. me.menu.layout.align = 'stretch';
  33. me.items = [me.menu];
  34. me.layout = 'fit';
  35. Ext.menu.Manager.register(me);
  36. me.callParent();
  37. // TODO - relay menu events
  38. me.toolbar = new Ext.toolbar.Toolbar(Ext.apply({
  39. dock: 'right',
  40. cls: 'ux-start-menu-toolbar',
  41. vertical: true,
  42. width: 100
  43. }, me.toolConfig));
  44. me.toolbar.layout.align = 'stretch';
  45. me.addDocked(me.toolbar);
  46. delete me.toolItems;
  47. me.on('deactivate', function () {
  48. me.hide();
  49. });
  50. },
  51. addMenuItem: function() {
  52. var cmp = this.menu;
  53. cmp.add.apply(cmp, arguments);
  54. },
  55. addToolItem: function() {
  56. var cmp = this.toolbar;
  57. cmp.add.apply(cmp, arguments);
  58. },
  59. showBy: function(cmp, pos, off) {
  60. var me = this;
  61. if (me.floating && cmp) {
  62. me.layout.autoSize = true;
  63. me.show();
  64. // Component or Element
  65. cmp = cmp.el || cmp;
  66. // Convert absolute to floatParent-relative coordinates if necessary.
  67. var xy = me.el.getAlignToXY(cmp, pos || me.defaultAlign, off);
  68. if (me.floatParent) {
  69. var r = me.floatParent.getTargetEl().getViewRegion();
  70. xy[0] -= r.x;
  71. xy[1] -= r.y;
  72. }
  73. me.showAt(xy);
  74. me.doConstrain();
  75. }
  76. return me;
  77. }
  78. }); // StartMenu