container.html 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  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.Container</title>
  10. <script src="../base.js"></script>
  11. <script>
  12. goog.require('goog.array');
  13. goog.require('goog.debug.DivConsole');
  14. goog.require('goog.debug.LogManager');
  15. goog.require('goog.dom');
  16. goog.require('goog.events');
  17. goog.require('goog.events.EventType');
  18. goog.require('goog.log');
  19. goog.require('goog.object');
  20. goog.require('goog.style');
  21. goog.require('goog.ui.Container');
  22. goog.require('goog.ui.ContainerScroller');
  23. goog.require('goog.ui.Control');
  24. goog.require('goog.ui.CustomButton');
  25. goog.require('goog.ui.Menu');
  26. goog.require('goog.ui.MenuButton');
  27. goog.require('goog.ui.Option');
  28. goog.require('goog.ui.Select');
  29. goog.require('goog.ui.Separator');
  30. goog.require('goog.ui.ToggleButton');
  31. goog.require('goog.dom.TagName');
  32. </script>
  33. <link rel="stylesheet" href="css/demo.css">
  34. <link rel="stylesheet" href="../css/button.css">
  35. <link rel="stylesheet" href="../css/menubutton.css">
  36. <style>
  37. /* Demo styles for goog.ui.Control. */
  38. .goog-control {
  39. position: relative;
  40. margin: 2px;
  41. border: 2px solid #036;
  42. padding: 2px;
  43. font: normal 9pt "Trebuchet MS", Tahoma, Arial, sans-serif;
  44. color: #036;
  45. background-color:#69c;
  46. cursor: pointer;
  47. outline: none !important;
  48. }
  49. .goog-control-disabled {
  50. border-color: #888;
  51. color: #888;
  52. background-color: #ccc;
  53. }
  54. .goog-control-hover {
  55. border-color: #369;
  56. color: #369;
  57. background-color: #9cf;
  58. }
  59. .goog-control-active,
  60. .goog-control-selected,
  61. .goog-control-checked {
  62. border-color: #9cf;
  63. color: #9cf;
  64. background-color: #369;
  65. }
  66. .goog-control-focused {
  67. border-color: orange;
  68. }
  69. /* Demo styles for goog.ui.Container */
  70. .goog-container {
  71. position: relative;
  72. margin: 0;
  73. border: 0;
  74. padding: 0;
  75. background-color: #eee;
  76. outline: none !important;
  77. zoom: 1; /* The container element must have layout on IE. */
  78. }
  79. .goog-container-vertical {
  80. width: 25ex;
  81. border: 1px solid #888;
  82. }
  83. .goog-container-horizontal {
  84. border-bottom: 1px solid #d5d5d5;
  85. background: #fafafa url(../images/toolbar-bg.png) repeat-x bottom left;
  86. }
  87. /* Additional demo styles. */
  88. .goog-month .goog-menu-button-caption {
  89. width: 18ex;
  90. }
  91. .goog-year .goog-menu-button-caption {
  92. width: 6ex;
  93. }
  94. .goog-edit-font .goog-menu-button-caption {
  95. width: 15ex;
  96. }
  97. .goog-edit-font-size .goog-menu-button-caption {
  98. width: 5ex;
  99. }
  100. .goog-edit-bold {
  101. width: 14px;
  102. background: url(../images/toolbar_icons.gif) no-repeat -1px;
  103. }
  104. .goog-edit-italic {
  105. width: 14px;
  106. background: url(../images/toolbar_icons.gif) no-repeat -17px;
  107. }
  108. .goog-edit-underline {
  109. width: 14px;
  110. background: url(../images/toolbar_icons.gif) no-repeat -33px;
  111. }
  112. #tb4_highlight_links span {
  113. border: 1px solid #888;
  114. cursor: pointer;
  115. padding: 2px 4px;
  116. }
  117. </style>
  118. </head>
  119. <body>
  120. <h2>goog.ui.Container</h2>
  121. <p><b>goog.ui.Container</b> is a base class for menus and toolbars.</p>
  122. <fieldset>
  123. <legend>These containers were created programmatically:</legend>
  124. <table border="0" cellpadding="8" cellspacing="0" width="100%">
  125. <tbody>
  126. <tr valign="top">
  127. <td width="50%" id="vc">
  128. Vertical container example:
  129. </td>
  130. <td width="50%" id="hc">
  131. Horizontal container example:
  132. </td>
  133. </tr>
  134. <tr valign="top">
  135. <td>
  136. <label>
  137. Show vertical container:
  138. <input type="checkbox" id="show_vc" checked>
  139. </label>
  140. &nbsp;
  141. <label>
  142. Enable vertical container:
  143. <input type="checkbox" id="enable_vc" checked>
  144. </label>
  145. <br>
  146. <label>
  147. Show Porthos:
  148. <input type="checkbox" id="show_porthos" checked>
  149. </label>
  150. &nbsp;
  151. <label>
  152. Enable Porthos:
  153. <input type="checkbox" id="enable_porthos">
  154. </label>
  155. <br>
  156. <label>
  157. Enable transition events:
  158. <input type="checkbox" id="enable_vc_events" checked>
  159. </label>
  160. </td>
  161. <td>
  162. <label>
  163. Show horizontal container:
  164. <input type="checkbox" id="show_hc" checked>
  165. </label>
  166. &nbsp;
  167. <label>
  168. Enable horizontal container:
  169. <input type="checkbox" id="enable_hc" checked>
  170. </label>
  171. <br>
  172. <label>
  173. Show Doc:
  174. <input type="checkbox" id="show_doc" checked>
  175. </label>
  176. &nbsp;
  177. <label>
  178. Enable Doc:
  179. <input type="checkbox" id="enable_doc">
  180. </label>
  181. <br>
  182. <label>
  183. Enable transition events:
  184. <input type="checkbox" id="enable_hc_events" checked>
  185. </label>
  186. </td>
  187. </tr>
  188. </tbody>
  189. </table>
  190. <span class="hint">Try enabling and disabling containers with &amp; without
  191. state transition events, and compare performance!</span>
  192. </fieldset>
  193. <br>
  194. <br>
  195. <fieldset>
  196. <legend>Non-focusable container with focusable controls:</legend>
  197. In this case, the container itself isn't focusable, but each control is:<br>
  198. <div id="nfc"></div>
  199. </fieldset>
  200. <br>
  201. <br>
  202. <fieldset>
  203. <legend>Another horizontal container:</legend>
  204. <label>
  205. This is starting to look useful... Enable toolbar:
  206. <input type="checkbox" id="enable_tb" checked>
  207. </label>
  208. <div id="tb"></div>
  209. </fieldset>
  210. <br>
  211. <br>
  212. <fieldset>
  213. <legend>A decorated container:</legend>
  214. <label>
  215. It's much easier to decorate than to create programmatically...
  216. Enable decorated toolbar:
  217. <input type="checkbox" id="enable_tb2">
  218. </label>
  219. <div id="tb2" class="goog-container-horizontal goog-container-disabled">
  220. <div id="month" class="goog-month goog-select">
  221. Select month
  222. <div class="goog-menu">
  223. <div class="goog-option">January</div>
  224. <div class="goog-option">February</div>
  225. <div class="goog-option">March</div>
  226. <div class="goog-option">April</div>
  227. <div class="goog-option">May</div>
  228. <div class="goog-option">June</div>
  229. <div class="goog-option">July</div>
  230. <div class="goog-option">August</div>
  231. <div class="goog-option">September</div>
  232. <div class="goog-option">October</div>
  233. <div class="goog-option">November</div>
  234. <div class="goog-option">December</div>
  235. </div>
  236. </div>
  237. <div id="year" class="goog-year goog-select">
  238. Year
  239. <div class="goog-menu">
  240. <div class="goog-option">2001</div>
  241. <div class="goog-option">2002</div>
  242. <div class="goog-option">2003</div>
  243. <div class="goog-option">2004</div>
  244. <div class="goog-option">2005</div>
  245. <div class="goog-option">2006</div>
  246. <div class="goog-option">2007</div>
  247. <div class="goog-option">2008</div>
  248. <div class="goog-option">2009</div>
  249. <div class="goog-option">2010</div>
  250. </div>
  251. </div>
  252. <div id="foo" class="goog-toggle-button">
  253. Toggle Button
  254. </div>
  255. <div id="bar" class="goog-toggle-button">
  256. <div><b><i>Fancy</i></b> Toggle Button</div>
  257. </div>
  258. <div id="fee" class="goog-toggle-button">
  259. Another Button
  260. </div>
  261. </div>
  262. </fieldset>
  263. <br>
  264. <br>
  265. <fieldset>
  266. <legend>The same container, right-to-left:</legend>
  267. <label>
  268. Show right-to-left toolbar:
  269. <input type="checkbox" id="show_tb3" checked>
  270. </label>
  271. <label>
  272. Enable right-to-left toolbar:
  273. <input type="checkbox" id="enable_tb3">
  274. </label>
  275. <div id="tb3" class="goog-container-horizontal goog-container-disabled"
  276. dir="rtl">
  277. <div class="goog-month goog-select">
  278. Select month
  279. <div class="goog-menu" dir="rtl">
  280. <div class="goog-option">January</div>
  281. <div class="goog-option">February</div>
  282. <div class="goog-option">March</div>
  283. <div class="goog-option">April</div>
  284. <div class="goog-option">May</div>
  285. <div class="goog-option">June</div>
  286. <div class="goog-option">July</div>
  287. <div class="goog-option">August</div>
  288. <div class="goog-option">September</div>
  289. <div class="goog-option">October</div>
  290. <div class="goog-option">November</div>
  291. <div class="goog-option">December</div>
  292. </div>
  293. </div>
  294. <div class="goog-year goog-select" dir="rtl">
  295. Year
  296. <div class="goog-menu">
  297. <div class="goog-option">2001</div>
  298. <div class="goog-option">2002</div>
  299. <div class="goog-option">2003</div>
  300. <div class="goog-option">2004</div>
  301. <div class="goog-option">2005</div>
  302. <div class="goog-option">2006</div>
  303. <div class="goog-option">2007</div>
  304. <div class="goog-option">2008</div>
  305. <div class="goog-option">2009</div>
  306. <div class="goog-option">2010</div>
  307. </div>
  308. </div>
  309. <div class="goog-toggle-button">
  310. Toggle Button
  311. </div>
  312. <div class="goog-toggle-button">
  313. <div><b><i>Fancy</i></b> Toggle Button</div>
  314. </div>
  315. <div class="goog-toggle-button">
  316. Another Button
  317. </div>
  318. </div>
  319. </fieldset>
  320. <br>
  321. <br>
  322. <fieldset>
  323. <legend>A scrolling container:</legend>
  324. <label>
  325. This container scrolls so that the highlighted item is visible.
  326. Here's a mix of block items and inline block items, which both work.
  327. </label>
  328. <p>
  329. Put focus in the text box and use the arrow keys:
  330. <input id="tb4_key_target">
  331. </p>
  332. <p>
  333. Or quick jump to item:
  334. <span id="tb4_highlight_links">
  335. <span>0</span> <span>1</span> <span>2</span> <span>3</span>
  336. <span>4</span> <span>5</span> <span>6</span> <span>7</span>
  337. <span>8</span> <span>9</span> <span>10</span> <span>11</span>
  338. <span>12</span> <span>13</span> <span>14</span> <span>15</span>
  339. </span>
  340. </p>
  341. <div id="tb4" class="goog-container-vertical"
  342. style="height: 100px; overflow-y: scroll">
  343. <div class="goog-month goog-menuitem">menuitem 0</div>
  344. <div class="goog-month goog-menuitem">menuitem 1</div>
  345. <div class="goog-month goog-menuitem">menuitem 2</div>
  346. <div class="goog-month goog-menuitem">menuitem 3</div>
  347. <div class="goog-month goog-toggle-button">tog 4</div>
  348. <div class="goog-month goog-toggle-button">tog 5</div>
  349. <div class="goog-month goog-toggle-button">tog 6</div>
  350. <div class="goog-month goog-toggle-button">toggley 7</div>
  351. <div class="goog-month goog-toggle-button">toggley 8</div>
  352. <div class="goog-month goog-toggle-button">toggley 9</div>
  353. <div class="goog-month goog-toggle-button">toggley 10</div>
  354. <div class="goog-month goog-toggle-button">toggley 11</div>
  355. <div class="goog-month goog-toggle-button">toggley 12</div>
  356. <div class="goog-month goog-toggle-button">toggley 13</div>
  357. <div class="goog-month goog-menuitem">menuitem 14</div>
  358. <div class="goog-month goog-menuitem">menuitem 15</div>
  359. </div>
  360. </fieldset>
  361. <br>
  362. <br>
  363. <!-- Event log. -->
  364. <fieldset class="goog-debug-panel">
  365. <legend>Event Log</legend>
  366. <div id="log"></div>
  367. </fieldset>
  368. <div id="perf"></div>
  369. <script>
  370. var timer = goog.now();
  371. // Set up a logger.
  372. goog.debug.LogManager.getRoot().setLevel(goog.log.Level.ALL);
  373. var logger = goog.log.getLogger('demo');
  374. var logconsole = new goog.debug.DivConsole(goog.dom.getElement('log'));
  375. logconsole.setCapturing(true);
  376. var EVENTS = goog.object.getValues(goog.ui.Component.EventType);
  377. goog.log.fine(logger, 'Listening for: ' + EVENTS.join(', ') + '.');
  378. function logEvent(e) {
  379. var source =
  380. typeof e.target.getCaption == 'function' && e.target.getCaption() ||
  381. e.target.getId();
  382. goog.log.info(logger, '"' + source + '" dispatched: ' + e.type);
  383. }
  384. // Programmatically create a vertical container.
  385. var vc = new goog.ui.Container();
  386. vc.setId('Vertical Container');
  387. goog.array.forEach(
  388. ['Athos', 'Porthos', 'Aramis', 'd\'Artagnan'],
  389. function(item) {
  390. var c = new goog.ui.Control(item);
  391. c.setId(item);
  392. // For demo purposes, have controls dispatch transition events.
  393. c.setDispatchTransitionEvents(goog.ui.Component.State.ALL, true);
  394. vc.addChild(c, true);
  395. });
  396. vc.addChildAt(new goog.ui.Separator(), 3, true);
  397. vc.getChild('Porthos').setEnabled(false);
  398. vc.render(goog.dom.getElement('vc'));
  399. goog.events.listen(vc, EVENTS, logEvent);
  400. // Hook up checkboxes.
  401. goog.events.listen(goog.dom.getElement('show_vc'),
  402. goog.events.EventType.CLICK,
  403. function(e) {
  404. var t = goog.now();
  405. vc.setVisible(e.target.checked);
  406. goog.log.info(logger, (e.target.checked ? 'Showed' : 'Hid') +
  407. ' vertical container in ' + (goog.now() - t) + 'ms');
  408. });
  409. goog.events.listen(goog.dom.getElement('enable_vc'),
  410. goog.events.EventType.CLICK,
  411. function(e) {
  412. var t = goog.now();
  413. vc.setEnabled(e.target.checked);
  414. // If the container as a whole is disabled, you can't enable/disable
  415. // child controls.
  416. goog.dom.getElement('enable_porthos').disabled = !vc.isEnabled();
  417. goog.log.info(logger, (e.target.checked ? 'Enabled' : 'Disabled') +
  418. ' vertical container in ' + (goog.now() - t) + 'ms');
  419. });
  420. goog.events.listen(goog.dom.getElement('show_porthos'),
  421. goog.events.EventType.CLICK,
  422. function(e) {
  423. vc.getChild('Porthos').setVisible(e.target.checked);
  424. });
  425. goog.events.listen(goog.dom.getElement('enable_porthos'),
  426. goog.events.EventType.CLICK,
  427. function(e) {
  428. vc.getChild('Porthos').setEnabled(e.target.checked);
  429. });
  430. goog.events.listen(goog.dom.getElement('enable_vc_events'),
  431. goog.events.EventType.CLICK,
  432. function(e) {
  433. vc.forEachChild(function(c) {
  434. if (e.target.checked) {
  435. // Enable all transition events.
  436. c.setDispatchTransitionEvents(goog.ui.Component.State.ALL, true);
  437. } else {
  438. // Disable all transition events (except for HOVER, which is used
  439. // by containers internally).
  440. c.setDispatchTransitionEvents(goog.ui.Component.State.ALL, false);
  441. c.setDispatchTransitionEvents(goog.ui.Component.State.HOVER,
  442. true);
  443. }
  444. });
  445. goog.log.info(logger, (e.target.checked ? 'Enabled' : 'Disabled') +
  446. ' state transition events for this container\'s children');
  447. });
  448. // Programmatically create a horizontal container.
  449. var hc = new goog.ui.Container(goog.ui.Container.Orientation.HORIZONTAL);
  450. hc.setId('Horizontal Container');
  451. // Pre-render the container, just to do something different.
  452. hc.render(goog.dom.getElement('hc'));
  453. goog.array.forEach(
  454. ['Happy', 'Sleepy', 'Doc', 'Bashful', 'Sneezy', 'Grumpy', 'Dopey'],
  455. function(item) {
  456. var c = new goog.ui.Control(item);
  457. c.addClassName('goog-inline-block');
  458. c.setId(item);
  459. // For demo purposes, have controls dispatch transition events.
  460. c.setDispatchTransitionEvents(goog.ui.Component.State.ALL, true);
  461. hc.addChild(c, true);
  462. });
  463. hc.getChild('Doc').setEnabled(false);
  464. goog.events.listen(hc, EVENTS, logEvent);
  465. // Hook up checkboxes.
  466. goog.events.listen(goog.dom.getElement('show_hc'),
  467. goog.events.EventType.CLICK,
  468. function(e) {
  469. var t = goog.now();
  470. hc.setVisible(e.target.checked);
  471. goog.log.info(logger, (e.target.checked ? 'Showed' : 'Hid') +
  472. ' horizontal container in ' + (goog.now() - t) + 'ms');
  473. });
  474. goog.events.listen(goog.dom.getElement('enable_hc'),
  475. goog.events.EventType.CLICK,
  476. function(e) {
  477. var t = goog.now();
  478. hc.setEnabled(e.target.checked);
  479. // If the container as a whole is disabled, you can't enable/disable
  480. // child controls.
  481. goog.dom.getElement('enable_doc').disabled = !hc.isEnabled();
  482. goog.log.info(logger, (e.target.checked ? 'Enabled' : 'Disabled') +
  483. ' horizontal container in ' + (goog.now() - t) + 'ms');
  484. });
  485. goog.events.listen(goog.dom.getElement('show_doc'),
  486. goog.events.EventType.CLICK,
  487. function(e) {
  488. hc.getChild('Doc').setVisible(e.target.checked);
  489. });
  490. goog.events.listen(goog.dom.getElement('enable_doc'),
  491. goog.events.EventType.CLICK,
  492. function(e) {
  493. hc.getChild('Doc').setEnabled(e.target.checked);
  494. });
  495. goog.events.listen(goog.dom.getElement('enable_hc_events'),
  496. goog.events.EventType.CLICK,
  497. function(e) {
  498. hc.forEachChild(function(c) {
  499. if (e.target.checked) {
  500. // Enable all transition events.
  501. c.setDispatchTransitionEvents(goog.ui.Component.State.ALL, true);
  502. } else {
  503. // Disable all transition events (except for HOVER, which is used
  504. // by containers internally).
  505. c.setDispatchTransitionEvents(goog.ui.Component.State.ALL, false);
  506. c.setDispatchTransitionEvents(goog.ui.Component.State.HOVER,
  507. true);
  508. }
  509. });
  510. goog.log.info(logger, (e.target.checked ? 'Enabled' : 'Disabled') +
  511. ' state transition events for this container\'s children');
  512. });
  513. // Programmatically create a non-focusable container.
  514. var nfc = new goog.ui.Container(goog.ui.Container.Orientation.HORIZONTAL);
  515. nfc.setId('NonFocusableContainer');
  516. nfc.setFocusable(false);
  517. goog.array.forEach(['Vicky', 'Cristina', 'Barcelona'], function(item) {
  518. var c = new goog.ui.Control(item);
  519. c.setId(item);
  520. c.addClassName('goog-inline-block');
  521. // For demo purposes, have controls dispatch transition events.
  522. c.setDispatchTransitionEvents(goog.ui.Component.State.ALL, true);
  523. nfc.addChild(c, /* opt_render */ true);
  524. // Since the container itself is non-focusable, we need to make each
  525. // child individually focusable; this has to happen *after* addChild().
  526. // See e.g. bug http://b/1359754.
  527. c.setSupportedState(goog.ui.Component.State.FOCUSED, true);
  528. });
  529. nfc.render(goog.dom.getElement('nfc'));
  530. goog.events.listen(nfc, EVENTS, logEvent);
  531. // Programmatically create a toolbar.
  532. var tb = new goog.ui.Container(goog.ui.Container.Orientation.HORIZONTAL);
  533. tb.setId('Toolbar');
  534. // Programmatically create & add toolbar items.
  535. var fontMenu = new goog.ui.Select('Select font');
  536. fontMenu.setId('Font Menu');
  537. fontMenu.setTooltip('Font');
  538. fontMenu.addItem(new goog.ui.Option('Arial', 'Arial, sans-serif'));
  539. fontMenu.addItem(new goog.ui.Option('Courier', 'Courier, monospace'));
  540. fontMenu.addItem(new goog.ui.Option('Times', 'Times, serif'));
  541. fontMenu.addClassName('goog-edit-font');
  542. tb.addChild(fontMenu, true);
  543. var sizeMenu = new goog.ui.Select(null);
  544. sizeMenu.setId('Font Size Menu');
  545. sizeMenu.setTooltip('Font Size');
  546. sizeMenu.addItem(new goog.ui.Option('8pt'));
  547. sizeMenu.addItem(new goog.ui.Option('10pt'));
  548. sizeMenu.addItem(new goog.ui.Option('12pt'));
  549. sizeMenu.addItem(new goog.ui.Option('16pt'));
  550. sizeMenu.setSelectedIndex(1);
  551. sizeMenu.addClassName('goog-edit-font-size');
  552. tb.addChild(sizeMenu, true);
  553. var boldButton = new goog.ui.ToggleButton(goog.dom.createDom(goog.dom.TagName.DIV,
  554. 'goog-edit-bold', '\u00A0'));
  555. boldButton.setId('Bold Button');
  556. boldButton.setTooltip('Bold');
  557. tb.addChild(boldButton, true);
  558. var italicButton = new goog.ui.ToggleButton(goog.dom.createDom(goog.dom.TagName.DIV,
  559. 'goog-edit-italic', '\u00A0'));
  560. italicButton.setId('Italic Button');
  561. italicButton.setTooltip('Italic');
  562. tb.addChild(italicButton, true);
  563. var underlineButton = new goog.ui.ToggleButton(goog.dom.createDom(goog.dom.TagName.DIV,
  564. 'goog-edit-underline', '\u00A0'));
  565. underlineButton.setId('Underline Button');
  566. underlineButton.setTooltip('Underline');
  567. tb.addChild(underlineButton, true);
  568. tb.render(goog.dom.getElement('tb'));
  569. goog.events.listen(tb, EVENTS, logEvent);
  570. // Hook up checkbox.
  571. goog.events.listen(goog.dom.getElement('enable_tb'),
  572. goog.events.EventType.CLICK,
  573. function(e) {
  574. var t = goog.now();
  575. tb.setEnabled(e.target.checked);
  576. goog.log.info(logger, (e.target.checked ? 'Enabled' : 'Disabled') +
  577. ' toolbar in ' + (goog.now() - t) + 'ms');
  578. });
  579. var tb2 = new goog.ui.Container();
  580. tb2.decorate(goog.dom.getElement('tb2'));
  581. goog.events.listen(tb2, EVENTS, logEvent);
  582. // Hook up checkbox.
  583. goog.events.listen(goog.dom.getElement('enable_tb2'),
  584. goog.events.EventType.CLICK,
  585. function(e) {
  586. var t = goog.now();
  587. tb2.setEnabled(e.target.checked);
  588. goog.log.info(logger, (e.target.checked ? 'Enabled' : 'Disabled') +
  589. ' toolbar in ' + (goog.now() - t) + 'ms');
  590. });
  591. // BiDi container example:
  592. var tb3 = new goog.ui.Container();
  593. tb3.decorate(goog.dom.getElement('tb3'));
  594. goog.events.listen(tb3, EVENTS, logEvent);
  595. // Hook up checkboxes.
  596. goog.events.listen(goog.dom.getElement('enable_tb3'),
  597. goog.events.EventType.CLICK,
  598. function(e) {
  599. var t = goog.now();
  600. tb3.setEnabled(e.target.checked);
  601. goog.log.info(logger, (e.target.checked ? 'Enabled' : 'Disabled') +
  602. ' toolbar in ' + (goog.now() - t) + 'ms');
  603. });
  604. goog.events.listen(goog.dom.getElement('show_tb3'),
  605. goog.events.EventType.CLICK,
  606. function(e) {
  607. var t = goog.now();
  608. tb3.setVisible(e.target.checked);
  609. goog.log.info(logger, (e.target.checked ? 'Showed' : 'Hid') +
  610. ' content element in ' + (goog.now() - t) + 'ms');
  611. });
  612. // Scrolling container.
  613. var tb4 = new goog.ui.Container();
  614. tb4.decorate(goog.dom.getElement('tb4'));
  615. tb4.setKeyEventTarget(goog.dom.getElement('tb4_key_target'));
  616. tb4.setFocusable(true);
  617. new goog.ui.ContainerScroller(tb4);
  618. goog.events.listen(goog.dom.getElement('tb4_highlight_links'),
  619. goog.events.EventType.CLICK,
  620. function(event) {
  621. var index = parseInt(event.target.innerHTML, 10);
  622. if (!isNaN(index)) {
  623. tb4.getChildAt(index).setHighlighted(true);
  624. }
  625. });
  626. goog.dom.setTextContent(goog.dom.getElement('perf'),
  627. (goog.now() - timer) + 'ms');
  628. </script>
  629. </body>
  630. </html>