tabbar.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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.TabBar</title>
  10. <link rel="stylesheet" href="css/demo.css">
  11. <link rel="stylesheet" href="../css/roundedtab.css">
  12. <link rel="stylesheet" href="../css/tab.css">
  13. <link rel="stylesheet" href="../css/tabbar.css">
  14. <style>
  15. fieldset {
  16. padding: 10px;
  17. border: 1px solid #369;
  18. }
  19. .goog-tab-content {
  20. height: 9em;
  21. margin: 0;
  22. border: 1px solid #6b90da;
  23. border-top: 0;
  24. padding: 4px 8px;
  25. background: #fff;
  26. overflow: auto;
  27. }
  28. </style>
  29. <script src="../base.js"></script>
  30. <script>
  31. goog.require('goog.debug.DivConsole');
  32. goog.require('goog.debug.LogManager');
  33. goog.require('goog.dom');
  34. goog.require('goog.events');
  35. goog.require('goog.events.EventType');
  36. goog.require('goog.log');
  37. goog.require('goog.log.Level');
  38. goog.require('goog.object');
  39. goog.require('goog.ui.Component.EventType');
  40. goog.require('goog.ui.RoundedTabRenderer');
  41. goog.require('goog.ui.Tab');
  42. goog.require('goog.ui.TabBar');
  43. </script>
  44. </head>
  45. <body>
  46. <h1>goog.ui.TabBar</h1>
  47. <p>
  48. A <b>goog.ui.TabBar</b> is a subclass of <b>goog.ui.Container</b>,
  49. designed to host one or more <b>goog.ui.Tab</b>s. The tabs in the
  50. first four tab bars on this demo page were decorated using the default
  51. tab renderer. Tabs in the last two tab bars were decorated using the
  52. rounded tab renderer (<b>goog.ui.RoundedTabRenderer</b>).
  53. </p>
  54. <table border="0" cellpadding="0" cellspacing="10" width="100%">
  55. <tbody>
  56. <tr valign="top">
  57. <td width="50%">
  58. <b>Above tab content:</b><br><br>
  59. <div id="top" class="goog-tab-bar goog-tab-bar-top">
  60. <div class="goog-tab goog-tab-selected">Hello</div>
  61. <div class="goog-tab">Settings</div>
  62. <div class="goog-tab">More</div>
  63. <div class="goog-tab goog-tab-disabled">Advanced</div>
  64. </div>
  65. <!-- Use goog-tab-bar-clear to separate the tabs from the content. -->
  66. <div class="goog-tab-bar-clear"></div>
  67. <div id="top_content" class="goog-tab-content">
  68. Use the keyboard or the mouse to switch tabs.
  69. </div>
  70. <label>
  71. Show/hide the first tab
  72. <input type="checkbox" id="show_top" checked>
  73. </label>
  74. <label>
  75. Enable/disable the fourth tab
  76. <input type="checkbox" id="enable_top">
  77. </label>
  78. </td>
  79. <td width="50%">
  80. <b>Below tab content:</b><br><br>
  81. <div id="bottom_content" class="goog-tab-content">
  82. Use the keyboard or the mouse to switch tabs.
  83. </div>
  84. <!-- Use goog-tab-bar-clear to separate the tabs from the content. -->
  85. <div class="goog-tab-bar-clear"></div>
  86. <div id="bottom" class="goog-tab-bar goog-tab-bar-bottom">
  87. <div class="goog-tab">Hello</div>
  88. <div class="goog-tab goog-tab-selected">Settings</div>
  89. <div class="goog-tab">More</div>
  90. <div class="goog-tab goog-tab-disabled">Advanced</div>
  91. </div>
  92. <!-- Use goog-tab-bar-clear to separate the tabs from the content. -->
  93. <div class="goog-tab-bar-clear"></div>
  94. <label>
  95. Show/hide the first tab
  96. <input type="checkbox" id="show_bottom" checked>
  97. </label>
  98. <label>
  99. Enable/disable the fourth tab
  100. <input type="checkbox" id="enable_bottom">
  101. </label>
  102. </td>
  103. </tr>
  104. <tr valign="top">
  105. <td width="50%">
  106. <b>Before tab content:</b><br><br>
  107. <div id="start" class="goog-tab-bar goog-tab-bar-start">
  108. <div class="goog-tab">Hello</div>
  109. <div class="goog-tab">Settings</div>
  110. <div class="goog-tab goog-tab-selected">More</div>
  111. <div class="goog-tab goog-tab-disabled">Advanced</div>
  112. </div>
  113. <div id="start_content" class="goog-tab-content">
  114. Use the keyboard or the mouse to switch tabs.
  115. </div>
  116. <!-- Use goog-tab-bar-clear to separate the tabs from the content. -->
  117. <div class="goog-tab-bar-clear"></div>
  118. <label>
  119. Show/hide the first tab
  120. <input type="checkbox" id="show_start" checked>
  121. </label>
  122. <label>
  123. Enable/disable the fourth tab
  124. <input type="checkbox" id="enable_start">
  125. </label>
  126. </td>
  127. <td width="50%">
  128. <b>After tab content:</b><br><br>
  129. <div id="end" class="goog-tab-bar goog-tab-bar-end">
  130. <div class="goog-tab">Hello</div>
  131. <div class="goog-tab">Settings</div>
  132. <div class="goog-tab">More</div>
  133. <div class="goog-tab goog-tab-disabled">Advanced</div>
  134. </div>
  135. <div id="end_content" class="goog-tab-content">
  136. Use the keyboard or the mouse to switch tabs.
  137. </div>
  138. <!-- Use goog-tab-bar-clear to separate the tabs from the content. -->
  139. <div class="goog-tab-bar-clear"></div>
  140. <label>
  141. Show/hide the first tab
  142. <input type="checkbox" id="show_end" checked>
  143. </label>
  144. <label>
  145. Enable/disable the fourth tab
  146. <input type="checkbox" id="enable_end">
  147. </label>
  148. </td>
  149. </tr>
  150. <tr valign="top">
  151. <td width="50%">
  152. <b>Above tab content (rounded corners):</b><br><br>
  153. <div id="top_round" class="goog-tab-bar goog-tab-bar-top">
  154. <div class="goog-rounded-tab">Hello</div>
  155. <div class="goog-rounded-tab goog-rounded-tab-selected">Settings
  156. </div>
  157. <div class="goog-rounded-tab">More</div>
  158. <div class="goog-rounded-tab goog-rounded-tab-disabled">Advanced
  159. </div>
  160. </div>
  161. <!-- Use goog-tab-bar-clear to separate the tabs from the content. -->
  162. <div class="goog-tab-bar-clear"></div>
  163. <div id="top_round_content" class="goog-tab-content"
  164. style="border-width:4px">
  165. Use the keyboard or the mouse to switch tabs.
  166. </div>
  167. <label>
  168. Show/hide the first tab
  169. <input type="checkbox" id="show_top_round" checked>
  170. </label>
  171. <label>
  172. Enable/disable the fourth tab
  173. <input type="checkbox" id="enable_top_round">
  174. </label>
  175. </td>
  176. <td width="50%">
  177. <b>Before tab content (rounded corners):</b><br><br>
  178. <div id="start_round" class="goog-tab-bar goog-tab-bar-start">
  179. <div class="goog-rounded-tab goog-rounded-tab-selected">Hello</div>
  180. <div class="goog-rounded-tab">Settings</div>
  181. <div class="goog-rounded-tab">More</div>
  182. <div class="goog-rounded-tab goog-rounded-tab-disabled">Advanced
  183. </div>
  184. </div>
  185. <div id="start_round_content" class="goog-tab-content"
  186. style="border-width:4px">
  187. Use the keyboard or the mouse to switch tabs.
  188. </div>
  189. <!-- Use goog-tab-bar-clear to separate the tabs from the content. -->
  190. <div class="goog-tab-bar-clear"></div>
  191. <label>
  192. Show/hide the first tab
  193. <input type="checkbox" id="show_start_round" checked>
  194. </label>
  195. <label>
  196. Enable/disable the fourth tab
  197. <input type="checkbox" id="enable_start_round">
  198. </label>
  199. </td>
  200. </tr>
  201. <tr>
  202. <td colspan="2">
  203. <!-- Event log. -->
  204. <fieldset class="goog-debug-panel">
  205. <legend>Event Log</legend>
  206. <div id="log"></div>
  207. </fieldset>
  208. </td>
  209. </tr>
  210. </tbody>
  211. </table>
  212. <br>
  213. <div id="perf"></div>
  214. <script>
  215. var timer = goog.now();
  216. // Set up a logger.
  217. goog.debug.LogManager.getRoot().setLevel(goog.log.Level.ALL);
  218. var logger = goog.log.getLogger('demo');
  219. var logconsole = new goog.debug.DivConsole(goog.dom.getElement('log'));
  220. logconsole.setCapturing(true);
  221. var EVENTS = goog.object.getValues(goog.ui.Component.EventType);
  222. goog.log.fine(logger, 'Listening for: ' + EVENTS.join(', ') + '.');
  223. function logEvent(e) {
  224. var source =
  225. typeof e.target.getCaption == 'function' && e.target.getCaption() ||
  226. e.target.getId();
  227. goog.log.info(logger, '"' + source + '" dispatched: ' + e.type);
  228. }
  229. var topTab = new goog.ui.TabBar();
  230. topTab.decorate(goog.dom.getElement('top'));
  231. var bottom = new goog.ui.TabBar();
  232. bottom.decorate(goog.dom.getElement('bottom'));
  233. var start = new goog.ui.TabBar();
  234. start.decorate(goog.dom.getElement('start'));
  235. var end = new goog.ui.TabBar();
  236. end.decorate(goog.dom.getElement('end'));
  237. var topRound = new goog.ui.TabBar();
  238. topRound.decorate(goog.dom.getElement('top_round'));
  239. var startRound = new goog.ui.TabBar();
  240. startRound.decorate(goog.dom.getElement('start_round'));
  241. goog.array.forEach([topTab, bottom, start, end, topRound, startRound],
  242. function(tabBar) {
  243. // Log all events.
  244. goog.events.listen(tabBar, EVENTS, logEvent);
  245. // Handle SELECT events dispatched by tabs.
  246. goog.events.listen(tabBar, goog.ui.Component.EventType.SELECT,
  247. function(e) {
  248. var tabSelected = e.target;
  249. var contentElement = goog.dom.getElement(tabBar.getId() +
  250. '_content');
  251. goog.dom.setTextContent(contentElement,
  252. 'You selected the "' + tabSelected.getCaption() + '" tab.');
  253. });
  254. // Hook up the "Show/hide first tab" checkbox.
  255. goog.events.listen(goog.dom.getElement('show_' + tabBar.getId()),
  256. goog.events.EventType.CLICK,
  257. function(e) {
  258. var checkbox = e.target;
  259. tabBar.getChildAt(0).setVisible(checkbox.checked);
  260. });
  261. // Hook up the "Enable/disable fourth tab" checkbox.
  262. goog.events.listen(goog.dom.getElement('enable_' + tabBar.getId()),
  263. goog.events.EventType.CLICK,
  264. function(e) {
  265. var checkbox = e.target;
  266. tabBar.getChildAt(3).setEnabled(checkbox.checked);
  267. });
  268. });
  269. goog.dom.setTextContent(goog.dom.getElement('perf'),
  270. (goog.now() - timer) + 'ms');
  271. </script>
  272. </body>
  273. </html>