css3button.html 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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>
  10. goog.ui.Css3ButtonRenderer Demo
  11. </title>
  12. <script type="text/javascript" src="../base.js"></script>
  13. <script type="text/javascript">
  14. goog.require('goog.array');
  15. goog.require('goog.debug.DivConsole');
  16. goog.require('goog.debug.LogManager');
  17. goog.require('goog.events');
  18. goog.require('goog.log');
  19. goog.require('goog.object');
  20. goog.require('goog.ui.Css3ButtonRenderer');
  21. goog.require('goog.ui.CustomButton');
  22. goog.require('goog.ui.ToggleButton');
  23. goog.require('goog.ui.decorate');
  24. </script>
  25. <link rel="stylesheet" type="text/css" href="css/demo.css">
  26. <link rel="stylesheet" type="text/css" href="../css/common.css">
  27. <link rel="stylesheet" type="text/css" href="../css/css3button.css">
  28. </head>
  29. <body>
  30. <h2>Demo of goog.ui.Css3ButtonRenderer</h2>
  31. <fieldset>
  32. <legend>
  33. These buttons were rendered using
  34. <strong>goog.ui.Css3ButtonRenderer</strong>:
  35. </legend>
  36. <br/>
  37. These buttons were created programmatically:<br/>
  38. <div id="cb1"></div>
  39. <br/>
  40. These buttons were created by decorating some DIVs, and they dispatch
  41. state transition events (watch the event log):<br/>
  42. <div id="cb2">
  43. <div id="foo" class="goog-css3-button" title="Title specified in HTML">
  44. Decorated <b>Button</b>, yay!
  45. </div><div id="bar" class="goog-css3-button goog-css3-button-disabled"
  46. title="Initialized to DISABLED in HTML...">Decorated Disabled
  47. </div><div id="fee" class="goog-css3-button">Another Button</div><div id="btn1"
  48. class="goog-css3-button goog-css3-button-collapse-right">
  49. Archive
  50. </div><div id="btn2"
  51. class="goog-css3-button goog-css3-button-collapse-right goog-css3-button-collapse-left">
  52. Delete
  53. </div><div id="btn3"
  54. class="goog-css3-button goog-css3-button-collapse-left">
  55. Report Spam
  56. </div>
  57. </div>
  58. <br/>
  59. Use these <strong>ToggleButton</strong>s to hide/show and enable/disable
  60. the middle button:<br/>
  61. <div id="toggleEnable" class="goog-css3-toggle-button"
  62. title="Click here to enable/disable the button above">Enable</div>
  63. <div id="hideShow"
  64. class="goog-css3-toggle-button goog-css3-button-checked"
  65. title="Click here to hide/show the button above">Show</div>
  66. <br/><br/>
  67. Combined toggle buttons<br/>
  68. <div id="btn4" class="goog-css3-toggle-button goog-css3-button-collapse-right">
  69. Bold
  70. </div><div id="btn5" class="goog-css3-toggle-button goog-css3-button-collapse-right goog-css3-button-collapse-left">
  71. Italics
  72. </div><div id="btn6" class="goog-css3-toggle-button goog-css3-button-collapse-left goog-css3-button-checked">
  73. Underlined
  74. </div>
  75. </fieldset>
  76. <br/>
  77. <div id="perf"></div>
  78. <!-- Event log. -->
  79. <fieldset class="goog-debug-panel">
  80. <legend>Event Log</legend>
  81. <div id="log"></div>
  82. </fieldset>
  83. <script type="text/javascript">
  84. var timer = goog.now();
  85. // Set up a logger.
  86. goog.debug.LogManager.getRoot().setLevel(goog.log.Level.ALL);
  87. var logger = goog.log.getLogger('demo');
  88. var logconsole = new goog.debug.DivConsole(goog.dom.getElement('log'));
  89. logconsole.setCapturing(true);
  90. var EVENTS = goog.object.getValues(goog.ui.Component.EventType);
  91. goog.log.fine(logger, 'Listening for: ' + EVENTS.join(', ') + '.');
  92. function logEvent(e) {
  93. goog.log.info(logger, '"' + e.target.getCaption() + '" dispatched: ' + e.type);
  94. }
  95. // Create some buttons using CustomButton with the
  96. // Css3ButtonRenderer renderer.
  97. var disabledButton;
  98. var customButtons = [
  99. new goog.ui.CustomButton('Button',
  100. goog.ui.Css3ButtonRenderer.getInstance()),
  101. new goog.ui.CustomButton('Another Button',
  102. goog.ui.Css3ButtonRenderer.getInstance()),
  103. disabledButton = new goog.ui.CustomButton('Disabled Button',
  104. goog.ui.Css3ButtonRenderer.getInstance()),
  105. new goog.ui.CustomButton('Yet Another Button',
  106. goog.ui.Css3ButtonRenderer.getInstance())
  107. ];
  108. disabledButton.setEnabled(false);
  109. goog.array.forEach(customButtons, function(b) {
  110. b.render(goog.dom.getElement('cb1'));
  111. goog.events.listen(b, goog.ui.Component.EventType.ACTION,
  112. function(e) {
  113. var newCaption = window.prompt('Enter new caption for button:');
  114. b.setCaption(newCaption || 'Empty');
  115. });
  116. goog.events.listen(b, EVENTS, logEvent);
  117. });
  118. // Decorate some buttons.
  119. var cb2 = [];
  120. var decoratedButtons = goog.array.map([
  121. 'foo', 'bar', 'fee', 'btn1', 'btn2', 'btn3', 'btn4', 'btn5', 'btn6'
  122. ], goog.dom.getElement);
  123. goog.array.forEach(decoratedButtons, function(element) {
  124. // Since the elements to be decorated each have the correct "marker" CSS
  125. // class ("goog-css3-custom-button"), we can use the renderer
  126. // registry to get the appropriate control instance to decorate them.
  127. var button = goog.ui.decorate(element);
  128. button.setDispatchTransitionEvents(goog.ui.Component.State.ALL, true);
  129. cb2.push(button);
  130. goog.events.listen(button, EVENTS, logEvent);
  131. });
  132. // Decorate toggle buttons.
  133. var toggleEnableElem = goog.dom.getElement('toggleEnable');
  134. var toggleEnable = goog.ui.decorate(toggleEnableElem);
  135. toggleEnable.setDispatchTransitionEvents(goog.ui.Component.State.ALL, true);
  136. goog.events.listen(toggleEnable, EVENTS, logEvent);
  137. goog.events.listen(toggleEnable, goog.ui.Component.EventType.ACTION,
  138. function(e) {
  139. cb2[1].setEnabled(e.target.isChecked());
  140. });
  141. var hideShowElem = goog.dom.getElement('hideShow');
  142. var hideShow = new goog.ui.decorate(hideShowElem);
  143. hideShow.setDispatchTransitionEvents(goog.ui.Component.State.ALL, true);
  144. goog.events.listen(hideShow, EVENTS, logEvent);
  145. goog.events.listen(hideShow, goog.ui.Component.EventType.ACTION,
  146. function(e) {
  147. cb2[1].setVisible(e.target.isChecked());
  148. });
  149. goog.dom.setTextContent(goog.dom.getElement('perf'),
  150. (goog.now() - timer) +'ms');
  151. </script>
  152. </body>
  153. </html>