submenus2.html 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <!DOCTYPE html>
  2. <html>
  3. <!--
  4. Copyright 2010 The Closure Library Authors. All Rights Reserved.
  5. Use of this source code is governed by the Apache License, Version 2.0.
  6. See the COPYING file for details.
  7. -->
  8. <head>
  9. <title>goog.ui.SubMenu</title>
  10. <script src="../base.js"></script>
  11. <script>
  12. goog.require('goog.debug');
  13. goog.require('goog.positioning.Corner');
  14. goog.require('goog.ui.Menu');
  15. goog.require('goog.ui.SubMenu');
  16. goog.require('goog.ui.PopupMenu');
  17. </script>
  18. <link rel="stylesheet" href="css/demo.css">
  19. <link rel="stylesheet" href="../css/menu.css">
  20. <link rel="stylesheet" href="../css/menuitem.css">
  21. <link rel="stylesheet" href="../css/menuseparator.css">
  22. <link rel="stylesheet" href="../css/submenu.css">
  23. </head>
  24. <body>
  25. <h1>goog.ui.SubMenu</h1>
  26. <p>Demonstration of different hierarchical menus which share its submenus.
  27. A flyweight pattern demonstration for submenus.</p>
  28. <p><button id="button">Open menu</button></p>
  29. <div id="sharedMenu" class="goog-menu">
  30. <div class="goog-menuitem">Google</div>
  31. <div class="goog-menuitem">Yahoo</div>
  32. <div class="goog-menuitem">MSN</div>
  33. <hr>
  34. <div class="goog-menuitem">Bla...</div>
  35. </div>
  36. <script>
  37. // Popup menu with sub menus
  38. var menu = new goog.ui.PopupMenu();
  39. menu.attach(document.getElementById('button'),
  40. goog.positioning.Corner.BOTTOM_LEFT,
  41. goog.positioning.Corner.TOP_LEFT);
  42. var sharedDecoratedSubmenu = new goog.ui.Menu();
  43. sharedDecoratedSubmenu.decorate(document.getElementById('sharedMenu'));
  44. var sharedSubmenu = new goog.ui.Menu();
  45. var sa = new goog.ui.SubMenu('Shared sub one');
  46. sa.addItem(new goog.ui.MenuItem('Shared sub sub one'));
  47. sa.addItem(new goog.ui.MenuItem('Shared sub sub two'));
  48. sharedSubmenu.addItem(sa);
  49. sharedSubmenu.addItem(new goog.ui.MenuItem('Shared sub two'));
  50. sharedSubmenu.addItem(new goog.ui.MenuItem('Shared sub three'));
  51. var sb = new goog.ui.SubMenu('Shared sub four');
  52. sb.setMenu(sharedDecoratedSubmenu);
  53. sharedSubmenu.addItem(sb);
  54. var a = new goog.ui.SubMenu('Zero');
  55. var b = new goog.ui.SubMenu('Ten');
  56. var c = new goog.ui.SubMenu('Twenty');
  57. var d = new goog.ui.SubMenu('Thirty');
  58. var e = new goog.ui.SubMenu('Has shared one');
  59. var f = new goog.ui.SubMenu('Has shared two');
  60. var g = new goog.ui.SubMenu('Has shared three');
  61. var h = new goog.ui.SubMenu('Has decorated shared one');
  62. var i = new goog.ui.SubMenu('Has decorated shared two');
  63. var j = new goog.ui.SubMenu('Has decorated shared three');
  64. e.setMenu(sharedSubmenu);
  65. f.setMenu(sharedSubmenu);
  66. g.setMenu(sharedSubmenu);
  67. h.setMenu(sharedDecoratedSubmenu);
  68. i.setMenu(sharedDecoratedSubmenu);
  69. j.setMenu(sharedDecoratedSubmenu);
  70. var aa = new goog.ui.SubMenu('One')
  71. aa.setEnabled(false);
  72. aa.addItem(new goog.ui.MenuItem('Add'));
  73. aa.addItem(new goog.ui.MenuItem('Subtract'));
  74. aa.addItem(new goog.ui.MenuItem('Multiply'));
  75. a.addItem(aa);
  76. a.addItem(new goog.ui.MenuItem('Two'));
  77. a.addItem(new goog.ui.MenuItem('Three'));
  78. a.addItem(new goog.ui.MenuItem('Four'));
  79. b.addItem(new goog.ui.MenuItem('Eleven'));
  80. b.addItem(new goog.ui.MenuItem('Thirteen'));
  81. b.addItem(new goog.ui.MenuItem('Fourteen'));
  82. b.addItem(new goog.ui.MenuItem('Fifteen'));
  83. c.addItem(new goog.ui.MenuItem('Twenty-one'));
  84. var cb = new goog.ui.SubMenu('Twenty-Two')
  85. cb.addItem(new goog.ui.MenuItem('Add'));
  86. cb.addItem(new goog.ui.MenuItem('Subtract'));
  87. cb.addItem(new goog.ui.MenuItem('Multiply'));
  88. var cbd = new goog.ui.SubMenu('More')
  89. cbd.addItem(new goog.ui.MenuItem('Square Root'));
  90. cbd.addItem(new goog.ui.MenuItem('Power'));
  91. cbd.addItem(new goog.ui.MenuItem('Square'));
  92. cb.addItem(cbd);
  93. c.addItem(cb);
  94. c.addItem(new goog.ui.MenuItem('Twenty-three'));
  95. c.addItem(new goog.ui.MenuItem('Twenty-four'));
  96. d.addItem(new goog.ui.MenuItem('Thirty-one'));
  97. d.addItem(new goog.ui.MenuItem('Thirty-two'));
  98. d.addItem(new goog.ui.MenuItem('Thirty-three'));
  99. d.addItem(new goog.ui.MenuItem('Thirty-four'));
  100. menu.addItem(a);
  101. menu.addItem(new goog.ui.MenuItem('AaAaAaAaAaAa'));
  102. menu.addItem(new goog.ui.MenuItem('BbBbBbBbBbBb'));
  103. menu.addItem(b);
  104. menu.addItem(c);
  105. menu.addItem(d);
  106. menu.addItem(e);
  107. menu.addItem(f);
  108. menu.addItem(g);
  109. menu.addItem(h);
  110. menu.addItem(i);
  111. menu.addItem(j);
  112. var ccc = new goog.ui.MenuItem('CcCcCcCcCcCc');
  113. ccc.setEnabled(false);
  114. menu.addItem(ccc);
  115. menu.addItem(new goog.ui.MenuItem('DdDdDdDdDdDd'));
  116. menu.render();
  117. menu.getElement().id = 'foo';
  118. goog.events.listen(menu, 'action', function(e) {
  119. var action = e.target.getCaption();
  120. alert(action);
  121. });
  122. </script>
  123. </body>
  124. </html>