toolbar.html 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  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.Toolbar</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.Button');
  22. goog.require('goog.ui.ButtonSide');
  23. goog.require('goog.ui.Component.EventType');
  24. goog.require('goog.ui.Component.State');
  25. goog.require('goog.ui.Menu');
  26. goog.require('goog.ui.MenuItem');
  27. goog.require('goog.ui.Option');
  28. goog.require('goog.ui.SelectionModel');
  29. goog.require('goog.ui.Separator');
  30. goog.require('goog.ui.Toolbar');
  31. goog.require('goog.ui.ToolbarButton');
  32. goog.require('goog.ui.ToolbarMenuButton');
  33. goog.require('goog.ui.ToolbarRenderer');
  34. goog.require('goog.ui.ToolbarSelect');
  35. goog.require('goog.ui.ToolbarSeparator');
  36. goog.require('goog.ui.ToolbarToggleButton');
  37. goog.require('goog.dom.TagName');
  38. </script>
  39. <link rel="stylesheet" href="css/demo.css">
  40. <link rel="stylesheet" href="../css/menu.css">
  41. <link rel="stylesheet" href="../css/menuitem.css">
  42. <link rel="stylesheet" href="../css/menuseparator.css">
  43. <link rel="stylesheet" href="../css/toolbar.css">
  44. <style>
  45. /*
  46. * Sample toolbar styles.
  47. */
  48. /* Base class for all icon elements. */
  49. .icon {
  50. height: 16px;
  51. width: 16px;
  52. background-image: url(../images/toolbar_icons.gif);
  53. background-repeat: no-repeat;
  54. vertical-align: middle;
  55. }
  56. /* Font select. */
  57. .goog-edit-font .goog-toolbar-menu-button-caption {
  58. color: #246;
  59. width: 15ex;
  60. overflow: hidden;
  61. }
  62. /* Font select options. */
  63. .goog-edit-font-normal {
  64. font-family: Arial, sans-serif;
  65. }
  66. .goog-edit-font-times {
  67. font-family: Times, serif;
  68. }
  69. .goog-edit-font-courier {
  70. font-family: "Courier New", Courier, monospace;
  71. }
  72. .goog-edit-font-georgia {
  73. font-family: Georgia, serif;
  74. }
  75. .goog-edit-font-trebuchet {
  76. font-family: "Trebuchet MS", sans-serif;
  77. }
  78. .goog-edit-font-verdana {
  79. font-family: Verdana, sans-serif;
  80. }
  81. /* Font size. */
  82. .goog-edit-font-size .goog-toolbar-menu-button-caption {
  83. color: #246;
  84. width: 5ex;
  85. }
  86. /* Bold. */
  87. .goog-edit-bold {
  88. background-position: 0;
  89. }
  90. /* Italic. */
  91. .goog-edit-italic {
  92. background-position: -16px;
  93. }
  94. /* Underline. */
  95. .goog-edit-underline {
  96. background-position: -32px;
  97. }
  98. /* Color. */
  99. .goog-edit-color {
  100. background-position: -48px;
  101. }
  102. /* Background color. */
  103. .goog-edit-background {
  104. background-position: -64px;
  105. }
  106. /* Menu buttons. */
  107. .goog-edit-style,
  108. .goog-edit-insert,
  109. .goog-edit-link,
  110. .goog-edit-spellcheck {
  111. font-weight: bold;
  112. color: #246;
  113. }
  114. /* Link. */
  115. .goog-edit-link {
  116. color: #009;
  117. text-decoration: underline;
  118. }
  119. /* Insert menu. */
  120. .goog-edit-insert-icon {
  121. background-position: -80px;
  122. vertical-align: bottom;
  123. }
  124. .goog-edit-insert-caption {
  125. padding: 0 2px;
  126. vertical-align: bottom;
  127. }
  128. /* List style menu. */
  129. .goog-edit-list-style {
  130. background-position: -96px;
  131. }
  132. /* Text alignment buttons. */
  133. .goog-edit-align-left {
  134. background-position: -128px;
  135. }
  136. .goog-edit-align-center {
  137. background-position: -144px;
  138. }
  139. .goog-edit-align-right {
  140. background-position: -160px;
  141. }
  142. /*
  143. * Menu styles, overriding those in menus.css to make these menus a little
  144. * more like the CCC editor UI design.
  145. */
  146. .goog-menu {
  147. position: absolute;
  148. margin: 0;
  149. border-width: 1px;
  150. border-style: solid;
  151. border-color: #ccc #999 #999 #ccc;
  152. padding: 0;
  153. font: normal 10pt Arial, sans-serif;
  154. color: #000;
  155. background-color: #fff;
  156. cursor: default;
  157. outline: none;
  158. }
  159. .goog-menuitem {
  160. margin: 0;
  161. border: 0;
  162. padding: 4px 32px 4px 4px;
  163. color: #000;
  164. background-color: #fff;
  165. list-style: none;
  166. }
  167. .goog-menuitem-disabled {
  168. color: #999;
  169. }
  170. .goog-menuitem-highlight {
  171. background-color: #e8eef7 !important;
  172. }
  173. .goog-menuseparator {
  174. position: relative;
  175. margin: 2px 0;
  176. border-top: 1px solid #999;
  177. padding: 0;
  178. outline: none;
  179. }
  180. </style>
  181. </head>
  182. <body>
  183. <h2>goog.ui.Toolbar</h2>
  184. <fieldset>
  185. <legend>These toolbars were created programmatically:</legend>
  186. <label>
  187. Show toolbar:
  188. <input id="t1_show" type="checkbox" checked>
  189. </label>
  190. &nbsp;
  191. <label>
  192. Enable toolbar:
  193. <input id="t1_enable" type="checkbox" checked>
  194. </label>
  195. &nbsp;
  196. <label>
  197. Enable last button:
  198. <input id="toggleButton_enable" type="checkbox" checked>
  199. </label>
  200. <br>
  201. <br>
  202. <div id="t1"></div>
  203. <br>
  204. <div id="perf1" class="perf"></div>
  205. <br>
  206. <label>
  207. Show right-to-left toolbar:
  208. <input id="t1rtl_show" type="checkbox" checked>
  209. </label>
  210. &nbsp;
  211. <label>
  212. Enable right-to-left toolbar:
  213. <input id="t1rtl_enable" type="checkbox" checked>
  214. </label>
  215. &nbsp;
  216. <label>
  217. Enable last button:
  218. <input id="rtlToggleButton_enable" type="checkbox" checked>
  219. </label>
  220. <br>
  221. <br>
  222. <div id="t1rtl" dir="rtl"></div>
  223. <br>
  224. <div id="perf1rtl" class="perf"></div>
  225. </fieldset>
  226. <br>
  227. <br>
  228. <fieldset>
  229. <legend>This toolbar was created by decorating a bunch of DIVs:</legend>
  230. <label>
  231. Show toolbar:
  232. <input id="t2_show" type="checkbox" checked>
  233. </label>
  234. &nbsp;
  235. <label>
  236. Enable toolbar:
  237. <input id="t2_enable" type="checkbox">
  238. </label>
  239. &nbsp;
  240. <label>
  241. Enable menu button:
  242. <input id="menuButton_enable" type="checkbox" checked>
  243. </label>
  244. <br>
  245. <br>
  246. <div id="t2" class="goog-toolbar goog-toolbar-disabled">
  247. <div class="goog-toolbar-button">Button</div>
  248. <div class="goog-toolbar-button">
  249. <b><i>Fancy</i></b> <u>Button</u>
  250. </div>
  251. <hr>
  252. <div class="goog-toolbar-button goog-toolbar-button-disabled">
  253. Disabled Button
  254. </div>
  255. <div id="menuButton" class="goog-toolbar-menu-button">
  256. Menu Button
  257. <div id="decoratedMenu" class="goog-menu">
  258. <div class="goog-menuitem">Foo</div>
  259. <div class="goog-menuitem">Bar</div>
  260. <hr>
  261. <div class="goog-menuitem goog-menuitem-disabled">Cake</div>
  262. </div>
  263. </div>
  264. <hr>
  265. <div class="goog-toolbar-toggle-button goog-toolbar-button-checked">
  266. Toggle Button
  267. </div>
  268. <div class="goog-toolbar-toggle-button">
  269. <div class="icon goog-edit-underline"></div>
  270. </div>
  271. </div>
  272. <br>
  273. <div id="perf2" class="perf"></div>
  274. <br>
  275. <label>
  276. Show right-to-left toolbar:
  277. <input id="t2rtl_show" type="checkbox" checked>
  278. </label>
  279. &nbsp;
  280. <label>
  281. Enable right-to-left toolbar:
  282. <input id="t2rtl_enable" type="checkbox">
  283. </label>
  284. &nbsp;
  285. <label>
  286. Enable menu button:
  287. <input id="rtlMenuButton_enable" type="checkbox" checked>
  288. </label>
  289. <br>
  290. <br>
  291. <div id="t2rtl" class="goog-toolbar goog-toolbar-disabled" dir="rtl">
  292. <div class="goog-toolbar-button">Button</div>
  293. <div class="goog-toolbar-button">
  294. <div><b><i>Fancy</i></b> <u>Button</u></div>
  295. </div>
  296. <hr>
  297. <div class="goog-toolbar-button goog-toolbar-button-disabled">
  298. Disabled Button
  299. </div>
  300. <div id="rtlMenuButton" class="goog-toolbar-menu-button">
  301. Menu Button
  302. <div id="rtlDecoratedMenu" class="goog-menu" dir="rtl">
  303. <div class="goog-menuitem">Foo</div>
  304. <div class="goog-menuitem">Bar</div>
  305. <div class="goog-menuitem"><span>????... </span>
  306. <span style="font-size:90%; text-align: left;">Ctrl+P</span></div>
  307. <div class="goog-menuitem">???? ?-HTML (????? ZIP)</div>
  308. <hr>
  309. <div class="goog-menuitem goog-menuitem-disabled">Cake</div>
  310. </div>
  311. </div>
  312. <hr>
  313. <div class="goog-toolbar-toggle-button goog-toolbar-button-checked">
  314. Toggle Button
  315. </div>
  316. <div class="goog-toolbar-toggle-button">
  317. <!-- For reasons unknown, on FF2, we need an &nbsp; for BiDi. -->
  318. <div class="icon goog-edit-underline">&nbsp;</div>
  319. </div>
  320. </div>
  321. <br>
  322. <div id="perf2rtl" class="perf"></div>
  323. </fieldset>
  324. <br>
  325. <br>
  326. <fieldset>
  327. <legend>This is starting to look like an editor toolbar:</legend>
  328. <label>
  329. Show toolbar:
  330. <input id="t3_show" type="checkbox" checked>
  331. </label>
  332. &nbsp;
  333. <label>
  334. Enable toolbar:
  335. <input id="t3_enable" type="checkbox" checked>
  336. </label>
  337. &nbsp;
  338. <label>
  339. Enable font dropdown:
  340. <input id="font_enable" type="checkbox" checked>
  341. </label>
  342. &nbsp;
  343. <label>
  344. Show font size dropdown:
  345. <input id="fontSize_show" type="checkbox" checked>
  346. </label>
  347. <br>
  348. <br>
  349. <div id="t3" class="goog-toolbar">
  350. <div id="font" title="Font" class="goog-toolbar-select goog-edit-font">
  351. Select font
  352. <div id="fontMenu" class="goog-menu">
  353. <div class="goog-option goog-edit-font-normal">Normal</div>
  354. <div class="goog-option goog-edit-font-times">Times</div>
  355. <div class="goog-option goog-edit-font-courier">Courier New</div>
  356. <div class="goog-option goog-edit-font-georgia">Georgia</div>
  357. <div class="goog-option goog-edit-font-trebuchet">Trebuchet</div>
  358. <div class="goog-option goog-edit-font-verdana">Verdana</div>
  359. </div>
  360. </div>
  361. <div id="fontSize" title="Font size"
  362. class="goog-toolbar-select goog-edit-font-size">
  363. Size
  364. <div id="fontSizeMenu" class="goog-menu">
  365. <div class="goog-option">7pt</div>
  366. <div class="goog-option">10pt</div>
  367. <div class="goog-option">14pt</div>
  368. <div class="goog-option">18pt</div>
  369. <div class="goog-option">24pt</div>
  370. <div class="goog-option">36pt</div>
  371. </div>
  372. </div>
  373. <div id="bold" title="Bold" class="goog-toolbar-toggle-button">
  374. <div class="icon goog-edit-bold"></div>
  375. </div>
  376. <div id="italic" title="Italic"
  377. class="goog-toolbar-toggle-button goog-toolbar-button-checked">
  378. <div class="icon goog-edit-italic"></div>
  379. </div>
  380. <div id="underline" title="Underline" class="goog-toolbar-toggle-button">
  381. <div class="icon goog-edit-underline"></div>
  382. </div>
  383. <div id="color" title="Text color" class="goog-toolbar-menu-button">
  384. <div class="icon goog-edit-color"></div>
  385. <div id="colorMenu" class="goog-menu">
  386. <div class="goog-menuitem" style="color:#800;">Red</div>
  387. <div class="goog-menuitem" style="color:#080;">Green</div>
  388. <div class="goog-menuitem" style="color:#008;">Blue</div>
  389. </div>
  390. </div>
  391. <div id="bgColor" title="Background color"
  392. class="goog-toolbar-menu-button">
  393. <div class="icon goog-edit-background"></div>
  394. <div id="bgColorMenu" class="goog-menu">
  395. <div class="goog-menuitem" style="color:#800;">Red</div>
  396. <div class="goog-menuitem" style="color:#080;">Green</div>
  397. <div class="goog-menuitem" style="color:#008;">Blue</div>
  398. </div>
  399. </div>
  400. <div id="style" title="Style" class="goog-toolbar-menu-button">
  401. <div class="goog-edit-style">Style</div>
  402. <div id="styleMenu" class="goog-menu">
  403. <div class="goog-menuitem">Clear formatting</div>
  404. <hr>
  405. <div class="goog-menuitem">Normal paragraph text</div>
  406. <div class="goog-menuitem">Minor heading (H3)</div>
  407. <div class="goog-menuitem">Sub-heading (H2)</div>
  408. <div class="goog-menuitem">Heading (H1)</div>
  409. <hr>
  410. <div class="goog-menuitem">Indent more</div>
  411. <div class="goog-menuitem">Indent less</div>
  412. <div class="goog-menuitem goog-menuitem-disabled">Blockquote</div>
  413. </div>
  414. </div>
  415. <hr>
  416. <div id="insert" title="Insert" class="goog-toolbar-menu-button">
  417. <div class="goog-edit-insert">
  418. <span class="icon goog-inline-block goog-edit-insert-icon">&nbsp;</span>
  419. <span class="goog-inline-block goog-edit-insert-caption">Insert</span>
  420. </div>
  421. <div id="insertMenu" class="goog-menu">
  422. <div class="goog-menuitem">Picture</div>
  423. <div class="goog-menuitem">Drawing</div>
  424. <div class="goog-menuitem">Other...</div>
  425. </div>
  426. </div>
  427. <hr>
  428. <div id="link" title="Create link" class="goog-toolbar-button">
  429. <div class="goog-edit-link">Link</div>
  430. </div>
  431. <hr>
  432. <div id="listStyle" title="List style"
  433. class="goog-toolbar-menu-button goog-toolbar-menu-button-disabled">
  434. <div class="icon goog-edit-list-style"></div>
  435. </div>
  436. <hr>
  437. <div id="alignLeft" title="Left" class="goog-toolbar-toggle-button goog-toolbar-button-collapse-right">
  438. <div class="icon goog-edit-align-left"></div>
  439. </div>
  440. <div id="alignCenter" title="Center"
  441. class="goog-toolbar-toggle-button goog-toolbar-button-collapse-left goog-toolbar-button-collapse-right">
  442. <div class="icon goog-edit-align-center"></div>
  443. </div>
  444. <div id="alignRight" title="Right" class="goog-toolbar-toggle-button goog-toolbar-button-collapse-left">
  445. <div class="icon goog-edit-align-right"></div>
  446. </div>
  447. <hr>
  448. <div id="spellcheck" title="Check spelling"
  449. class="goog-toolbar-menu-button goog-toolbar-menu-button-disabled">
  450. <div class="goog-edit-spellcheck">Check spelling</div>
  451. </div>
  452. </div>
  453. <br>
  454. <div id="perf3" class="perf"></div>
  455. </fieldset>
  456. <br>
  457. <br>
  458. <!-- Event log. -->
  459. <fieldset class="goog-debug-panel">
  460. <legend>Event Log</legend>
  461. <div class="hint">
  462. <b style="color: #800;">Warning!</b> On Gecko, the event log may cause
  463. the page to flicker when mousing over toolbar items. This is a Gecko
  464. issue triggered by scrolling in the event log.
  465. <br><br>
  466. Enable logging: <input id="enable_log" type="checkbox" checked>
  467. </div>
  468. <br>
  469. <div id="log"></div>
  470. </fieldset>
  471. <script>
  472. var timer;
  473. // Set up a logger.
  474. goog.debug.LogManager.getRoot().setLevel(goog.log.Level.ALL);
  475. var logger = goog.log.getLogger('demo');
  476. var logconsole = new goog.debug.DivConsole(goog.dom.getElement('log'));
  477. logconsole.setCapturing(true);
  478. var EVENTS = goog.object.getValues(goog.ui.Component.EventType);
  479. goog.log.fine(logger, 'Listening for: ' + EVENTS.join(', ') + '.');
  480. function logEvent(e) {
  481. var caption = e.target.getId();
  482. if (typeof e.target.getCaption == 'function' && e.target.getCaption()) {
  483. caption += ' (' + e.target.getCaption() + ')';
  484. }
  485. goog.log.info(logger, '"' + caption + '" dispatched: ' + e.type);
  486. }
  487. function showPerf(id, start) {
  488. goog.dom.setTextContent(goog.dom.getElement(id),
  489. (goog.now() - start) + 'ms');
  490. }
  491. goog.events.listen(goog.dom.getElement('enable_log'),
  492. goog.events.EventType.CLICK,
  493. function(e) {
  494. goog.style.setElementShown(goog.dom.getElement('log'), e.target.checked);
  495. logconsole.setCapturing(e.target.checked);
  496. });
  497. function handleShow(e) {
  498. var t = goog.now();
  499. var box = e.target;
  500. this.setVisible(box.checked);
  501. var caption = this.getId();
  502. if (typeof this.getCaption == 'function' && this.getCaption()) {
  503. caption += ' (' + this.getCaption() + ')';
  504. }
  505. goog.log.info(logger, (this.isVisible() ? 'Showed' : 'Hid') + ' ' + caption
  506. + ' in ' + (goog.now() - t) + 'ms');
  507. }
  508. function handleEnable(e) {
  509. if (typeof this.isParentDisabled_ == 'function' &&
  510. this.isParentDisabled_()) {
  511. goog.log.warning(logger, 'Can\'t enable/disable control if parent is disabled!');
  512. return false;
  513. }
  514. var t = goog.now();
  515. var box = e.target;
  516. this.setEnabled(box.checked);
  517. var caption = this.getId();
  518. if (typeof this.getCaption == 'function' && this.getCaption()) {
  519. caption += ' (' + this.getCaption() + ')';
  520. }
  521. goog.log.info(logger, (this.isEnabled() ? 'Enabled' : 'Disabled') + ' ' + caption
  522. + ' in ' + (goog.now() - t) + 'ms');
  523. return true;
  524. }
  525. // Create first toolbar programmatically.
  526. timer = goog.now();
  527. var t1 = new goog.ui.Toolbar();
  528. t1.addChild(new goog.ui.ToolbarButton('Button'), true);
  529. t1.getChildAt(0).setTooltip('This is a tooltip for a button');
  530. t1.addChild(new goog.ui.ToolbarButton('AnotherButton'), true);
  531. t1.addChild(new goog.ui.ToolbarSeparator(), true);
  532. t1.addChild(new goog.ui.ToolbarButton('Disabled'), true);
  533. t1.getChildAt(3).setEnabled(false);
  534. t1.addChild(new goog.ui.ToolbarButton('YetAnotherButton'), true);
  535. var toggleButton = new goog.ui.ToolbarToggleButton(goog.dom.createDom(goog.dom.TagName.DIV,
  536. 'icon goog-edit-bold'));
  537. toggleButton.setChecked(true);
  538. t1.addChild(toggleButton, true);
  539. var btnLeft = new goog.ui.ToolbarButton('Left');
  540. btnLeft.setCollapsed(goog.ui.ButtonSide.END);
  541. t1.addChild(btnLeft, true);
  542. var btnCenter = new goog.ui.ToolbarButton('Center');
  543. btnCenter.setCollapsed(goog.ui.ButtonSide.END | goog.ui.ButtonSide.START);
  544. t1.addChild(btnCenter, true);
  545. var btnRight = new goog.ui.ToolbarButton('Right');
  546. btnRight.setCollapsed(goog.ui.ButtonSide.START);
  547. t1.addChild(btnRight, true);
  548. t1.render(goog.dom.getElement('t1'));
  549. showPerf('perf1', timer);
  550. goog.events.listen(t1, EVENTS, logEvent);
  551. // Hook up checkboxes.
  552. goog.events.listen(goog.dom.getElement('t1_show'),
  553. goog.events.EventType.CLICK, handleShow, false, t1);
  554. goog.events.listen(goog.dom.getElement('t1_enable'),
  555. goog.events.EventType.CLICK, handleEnable, false, t1);
  556. goog.events.listen(goog.dom.getElement('toggleButton_enable'),
  557. goog.events.EventType.CLICK, handleEnable, false, toggleButton);
  558. // Create right-to-left toolbar programmatically.
  559. timer = goog.now();
  560. var t1rtl = new goog.ui.Toolbar();
  561. t1rtl.addChild(new goog.ui.ToolbarButton('Button'), true);
  562. t1rtl.getChildAt(0).setTooltip('This is a tooltip for a button');
  563. t1rtl.addChild(new goog.ui.ToolbarButton('AnotherButton'), true);
  564. t1rtl.addChild(new goog.ui.ToolbarSeparator(), true);
  565. t1rtl.addChild(new goog.ui.ToolbarButton('Disabled'), true);
  566. t1rtl.getChildAt(3).setEnabled(false);
  567. t1rtl.addChild(new goog.ui.ToolbarButton('YetAnotherButton'), true);
  568. // For reasons unknown, on FF2, we have to inject an &nbsp; character into
  569. // the icon div for RTL positioning to work. FF2 BiDi sucks!
  570. var rtlToggleButton = new goog.ui.ToolbarToggleButton(goog.dom.createDom(
  571. goog.dom.TagName.DIV, 'icon goog-edit-bold', '\u00A0'));
  572. rtlToggleButton.setChecked(true);
  573. t1rtl.addChild(rtlToggleButton, true);
  574. var btnLeftRtl = new goog.ui.ToolbarButton('Left');
  575. t1rtl.addChild(btnLeftRtl, true);
  576. var btnCenterRtl = new goog.ui.ToolbarButton('Center');
  577. t1rtl.addChild(btnCenterRtl, true);
  578. var btnRightRtl = new goog.ui.ToolbarButton('Right');
  579. t1rtl.addChild(btnRightRtl, true);
  580. t1rtl.render(goog.dom.getElement('t1rtl'));
  581. showPerf('perf1rtl', timer);
  582. goog.events.listen(t1rtl, EVENTS, logEvent);
  583. // The setCollapsed method needs to be called after the toolbar is rendered
  584. // for it to pick up the directionality of the toolbar.
  585. btnLeftRtl.setCollapsed(goog.ui.ButtonSide.END);
  586. btnCenterRtl.setCollapsed(
  587. goog.ui.ButtonSide.END | goog.ui.ButtonSide.START);
  588. btnRightRtl.setCollapsed(goog.ui.ButtonSide.START);
  589. // Hook up checkboxes.
  590. goog.events.listen(goog.dom.getElement('t1rtl_show'),
  591. goog.events.EventType.CLICK, handleShow, false, t1rtl);
  592. goog.events.listen(goog.dom.getElement('t1rtl_enable'),
  593. goog.events.EventType.CLICK, handleEnable, false, t1rtl);
  594. goog.events.listen(goog.dom.getElement('rtlToggleButton_enable'),
  595. goog.events.EventType.CLICK, handleEnable, false, rtlToggleButton);
  596. // Decorate the second toolbar.
  597. timer = goog.now();
  598. var t2 = new goog.ui.Toolbar();
  599. t2.decorate(goog.dom.getElement('t2'));
  600. showPerf('perf2', timer);
  601. goog.events.listen(t2, EVENTS, logEvent);
  602. // Hook up checkboxes.
  603. goog.events.listen(goog.dom.getElement('t2_show'),
  604. goog.events.EventType.CLICK, handleShow, false, t2);
  605. goog.events.listen(goog.dom.getElement('t2_enable'),
  606. goog.events.EventType.CLICK, handleEnable, false, t2);
  607. goog.events.listen(goog.dom.getElement('menuButton_enable'),
  608. goog.events.EventType.CLICK, handleEnable, false,
  609. t2.getChild('menuButton'));
  610. // Decorate the second toolbar.
  611. timer = goog.now();
  612. var t2rtl = new goog.ui.Toolbar();
  613. t2rtl.decorate(goog.dom.getElement('t2rtl'));
  614. showPerf('perf2rtl', timer);
  615. goog.events.listen(t2rtl, EVENTS, logEvent);
  616. // Hook up checkboxes.
  617. goog.events.listen(goog.dom.getElement('t2rtl_show'),
  618. goog.events.EventType.CLICK, handleShow, false, t2rtl);
  619. goog.events.listen(goog.dom.getElement('t2rtl_enable'),
  620. goog.events.EventType.CLICK, handleEnable, false, t2rtl);
  621. goog.events.listen(goog.dom.getElement('rtlMenuButton_enable'),
  622. goog.events.EventType.CLICK, handleEnable, false,
  623. t2rtl.getChild('rtlMenuButton'));
  624. // Decorate the third toolbar.
  625. timer = goog.now();
  626. var t3 = new goog.ui.Toolbar();
  627. t3.decorate(goog.dom.getElement('t3'));
  628. showPerf('perf3', timer);
  629. goog.events.listen(t3, EVENTS, logEvent);
  630. // Have the alignment buttons be controlled by a selection model.
  631. var selectionModel = new goog.ui.SelectionModel();
  632. selectionModel.setSelectionHandler(function(button, select) {
  633. if (button) {
  634. button.setChecked(select);
  635. }
  636. });
  637. goog.array.forEach(['alignLeft', 'alignCenter', 'alignRight'],
  638. function(id) {
  639. var button = t3.getChild(id);
  640. // Let the selection model control the button's checked state.
  641. button.setAutoStates(goog.ui.Component.State.CHECKED, false);
  642. selectionModel.addItem(button);
  643. goog.events.listen(button, goog.ui.Component.EventType.ACTION,
  644. function(e) {
  645. selectionModel.setSelectedItem(e.target);
  646. });
  647. });
  648. // Hook up checkboxes.
  649. goog.events.listen(goog.dom.getElement('t3_show'),
  650. goog.events.EventType.CLICK, handleShow, false, t3);
  651. goog.events.listen(goog.dom.getElement('t3_enable'),
  652. goog.events.EventType.CLICK, handleEnable, false, t3);
  653. goog.events.listen(goog.dom.getElement('font_enable'),
  654. goog.events.EventType.CLICK, handleEnable, false,
  655. t3.getChild('font'));
  656. goog.events.listen(goog.dom.getElement('fontSize_show'),
  657. goog.events.EventType.CLICK, handleShow, false,
  658. t3.getChild('fontSize'));
  659. </script>
  660. </body>
  661. </html>