combobox.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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.ComboBox</title>
  10. <script src="../base.js"></script>
  11. <script>
  12. goog.require('goog.events');
  13. goog.require('goog.ui.ComboBox');
  14. goog.require('goog.debug.DivConsole');
  15. goog.require('goog.dispose');
  16. goog.require('goog.dom');
  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/combobox.css">
  23. <style>
  24. html, body {
  25. overflow:hidden;
  26. margin: 0;
  27. padding: 5px;
  28. }
  29. #log {
  30. position: absolute;
  31. top: 50%;
  32. width: 100%;
  33. right: 0%;
  34. height: 50%;
  35. overflow: auto;
  36. }
  37. #c {
  38. margin-bottom: 10px;
  39. font-size: small;
  40. }
  41. /* Size the combobox so that it is sufficiently small to demonstrate the menu
  42. being positioned to left-align with the control. */
  43. .goog-combobox input {
  44. width: 100px;
  45. }
  46. fieldset {
  47. display: inline-block;
  48. margin: 10px;
  49. text-align: initial;
  50. }
  51. </style>
  52. </head>
  53. <body>
  54. <h1>goog.ui.ComboBox</h1>
  55. <div id="c">cb.value = '<span id="v"></span>'</div>
  56. <fieldset style="float:left">
  57. <legend>LTR</legend>
  58. <div class="combo"></div>
  59. </fieldset>
  60. <fieldset style="float:right">
  61. <legend>LTR</legend>
  62. <div class="combo"></div>
  63. </fieldset>
  64. <div style="text-align:center">
  65. <fieldset>
  66. <legend>LTR</legend>
  67. <div class="combo"></div>
  68. </fieldset>
  69. </div>
  70. <div style="clear:both"></div>
  71. <fieldset dir="rtl" style="float:left">
  72. <legend>RTL</legend>
  73. <div class="combo"></div>
  74. </fieldset>
  75. <fieldset dir="rtl" style="float:right">
  76. <legend>RTL</legend>
  77. <div class="combo"></div>
  78. </fieldset>
  79. <div style="text-align:center">
  80. <fieldset dir="rtl">
  81. <legend>RTL</legend>
  82. <div class="combo"></div>
  83. </fieldset>
  84. </div>
  85. <div style="clear:both"></div>
  86. <a href="javascript:void(logconsole.clear())">Clear Log</a>
  87. <div id="log"></div>
  88. <script type="text/javascript">
  89. // Set up a logger to track responses
  90. goog.debug.LogManager.getRoot().setLevel(goog.debug.Logger.Level.ALL);
  91. var logconsole = new goog.debug.DivConsole(document.getElementById('log'));
  92. logconsole.setCapturing(true);
  93. function createTestComboBox() {
  94. var cb = new goog.ui.ComboBox();
  95. cb.setUseDropdownArrow(true);
  96. cb.setDefaultText('Select a folder...');
  97. var caption = new goog.ui.ComboBoxItem('Select folder...');
  98. caption.setSticky(true);
  99. caption.setEnabled(false);
  100. cb.addItem(caption);
  101. cb.addItem(new goog.ui.ComboBoxItem('Inbox'));
  102. cb.addItem(new goog.ui.ComboBoxItem('Bills & statements'));
  103. cb.addItem(new goog.ui.ComboBoxItem('Cal alumni'));
  104. cb.addItem(new goog.ui.ComboBoxItem('Calendar Stuff'));
  105. cb.addItem(new goog.ui.ComboBoxItem('Design'));
  106. cb.addItem(new goog.ui.ComboBoxItem('Music'));
  107. cb.addItem(new goog.ui.ComboBoxItem('Netflix'));
  108. cb.addItem(new goog.ui.ComboBoxItem('Personal'));
  109. cb.addItem(new goog.ui.ComboBoxItem('Photos'));
  110. cb.addItem(new goog.ui.ComboBoxItem('Programming languages'));
  111. cb.addItem(new goog.ui.MenuSeparator());
  112. var newfolder = new goog.ui.ComboBoxItem('New Folder...');
  113. newfolder.setSticky(true);
  114. cb.addItem(newfolder);
  115. return cb;
  116. }
  117. var controls = [];
  118. var containerEls = goog.dom.getElementsByClass(goog.getCssName('combo'));
  119. for (var i = 0; i < containerEls.length; i++) {
  120. var cb = createTestComboBox();
  121. cb.render(containerEls[i]);
  122. goog.events.listen(cb, 'change', handleChangeEvent);
  123. controls.push(cb);
  124. }
  125. function handleChangeEvent(e) {
  126. goog.dom.setTextContent(document.getElementById('v'), e.target.getValue());
  127. }
  128. window.onbeforeunload = function() {
  129. goog.disposeAll(controls);
  130. };
  131. </script>
  132. </body>
  133. </html>