popupmenu.html 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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.PopupMenu</title>
  10. <script src="../base.js"></script>
  11. <script>
  12. goog.require('goog.positioning.Corner');
  13. goog.require('goog.object');
  14. goog.require('goog.ui.MenuItem');
  15. goog.require('goog.ui.PopupMenu');
  16. goog.require('goog.dom.TagName');
  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. <style>
  23. .event-log {
  24. border: 1px solid #CCC;
  25. height: 300px;
  26. position: absolute;
  27. right: 20px;
  28. width: 400px;
  29. }
  30. .event-log-content {
  31. height: 280px;
  32. overflow: auto;
  33. }
  34. </style>
  35. </head>
  36. <body>
  37. <h1>goog.ui.PopupMenu</h1>
  38. <div>
  39. This shows a 2 popup menus, each menu has been attached to two targets.
  40. <br><br>
  41. </div>
  42. <fieldset class="event-log">
  43. <legend>Event log</legend>
  44. <div id="event-log" class="event-log-content"></div>
  45. </fieldset>
  46. <div id="foo" style="width: 600px; height: 300px; background-color: #EEE">
  47. <div>
  48. <span>Hello there <i>I'm italic!</i></span>
  49. </div>
  50. <div><button id="bar">Decorated Popup attached to a Button</button></div>
  51. </div>
  52. <button id="bar2" style="position:absolute;left: 600px;top:330px;">Button</button>
  53. <button id="dButton">Decorated Popup</button>
  54. <div id="dMenu" for="dButton" class="goog-menu" style="display:none">
  55. <div class="goog-menuitem">A a</div>
  56. <div class="goog-menuitem">B b</div>
  57. <div class="goog-menuitem">C c</div>
  58. <div class="goog-menuitem">D d</div>
  59. <div class="goog-menuitem">E e</div>
  60. <div class="goog-menuitem">F f</div>
  61. </div>
  62. <script>
  63. var pm = new goog.ui.PopupMenu();
  64. pm.addItem(new goog.ui.MenuItem('One'));
  65. pm.addItem(new goog.ui.MenuItem('Two'));
  66. pm.addItem(new goog.ui.MenuItem('Three'));
  67. pm.addItem(new goog.ui.MenuItem('Four'));
  68. pm.addItem(new goog.ui.MenuItem('Five'));
  69. pm.addItem(new goog.ui.MenuItem('Six'));
  70. pm.addItem(new goog.ui.MenuItem('Seven'));
  71. pm.render(document.body);
  72. //pm.attach(document.getElementById('foo'), null, null);
  73. pm.attach(
  74. document.getElementById('bar2'),
  75. goog.positioning.Corner.TOP_LEFT,
  76. goog.positioning.Corner.BOTTOM_LEFT);
  77. pm.attach(document.getElementById('foo'));
  78. var pm2 = new goog.ui.PopupMenu();
  79. pm2.setToggleMode(true);
  80. pm2.decorate(document.getElementById('dMenu'));
  81. pm2.attach(
  82. document.getElementById('bar'),
  83. goog.positioning.Corner.BOTTOM_LEFT,
  84. goog.positioning.Corner.TOP_LEFT);
  85. function logEvent(e) {
  86. var entry = goog.dom.createDom(goog.dom.TagName.DIV, null,
  87. 'type: ' + e.type +
  88. ', target: ' + e.target.constructor.name +
  89. (e.target.getCaption ? ', caption: ' + e.target.getCaption() : ''));
  90. var eventLog = goog.dom.getElement('event-log');
  91. eventLog.appendChild(entry);
  92. // Scroll to the bottom.
  93. eventLog.scrollTop = eventLog.scrollHeight;
  94. }
  95. goog.object.forEach(goog.ui.Component.EventType, function(type) {
  96. goog.events.listen(pm, type, logEvent);
  97. goog.events.listen(pm2, type, logEvent);
  98. });
  99. </script>
  100. </body>
  101. </html>