samplecomponent.html 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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.Component</title>
  10. <meta charset="utf-8">
  11. <script src="../base.js"></script>
  12. <script>
  13. goog.require('goog.ui.Component');
  14. goog.require('goog.Timer');
  15. </script>
  16. <script src="../demos/samplecomponent.js"></script>
  17. <script>
  18. function initPage() {
  19. // Shows default initial label
  20. var box1 = new goog.demos.SampleComponent();
  21. box1.render(goog.dom.getElement('target1'));
  22. // Shows label taken from DIV text
  23. var box2 = new goog.demos.SampleComponent();
  24. box2.decorate(goog.dom.getElement('target2'));
  25. // Shows initial Label + setting label
  26. var box3 = new goog.demos.SampleComponent('Counting...');
  27. box3.decorate(goog.dom.getElement('target3'));
  28. var t = new goog.Timer(2000);
  29. var value = 0;
  30. goog.events.listen(t, goog.Timer.TICK, function (e) {
  31. box3.setLabelText((++value).toString());
  32. });
  33. t.start();
  34. }
  35. goog.events.listen(window, goog.events.EventType.LOAD, initPage);
  36. </script>
  37. <link rel="stylesheet" href="css/demo.css">
  38. <style>
  39. .goog-sample-component {
  40. height: 1em;
  41. padding: 1em;
  42. color: white;
  43. text-align: center;
  44. font-size: 150%;
  45. }
  46. </style>
  47. </head>
  48. <body>
  49. <h1>goog.ui.Component</h1>
  50. <!-- This div will have a Sample Component added to its contents. -->
  51. <div id="target1">
  52. <p>Click on this big, colored box:</p>
  53. </div>
  54. <hr />
  55. <div>
  56. <p>Or this box:</p>
  57. <!-- This div will have its contents decorated by a Sample Component. -->
  58. <div style="width: 50%" id="target2">Label from decorated DIV.</div>
  59. </div>
  60. <hr />
  61. <p>This box's label keeps changing:</p>
  62. <!-- This div will also have its contents decorated by a Sample Component. -->
  63. <div style="width: 50%; float: right;" id="target3"></div>
  64. </body>
  65. </html>