events.html 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. Copyright 2007 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>Graphics Basic events Demo Page</title>
  10. <style class="text/css">
  11. html, body {
  12. width: 100%;
  13. height: 100%;
  14. overflow:hidden;
  15. }
  16. #log {
  17. position: absolute;
  18. top: 0px;
  19. width: 50%;
  20. right: 0%;
  21. height: 100%;
  22. overflow: auto;
  23. border: 1px solid #cccccc;
  24. }
  25. #c {
  26. margin-bottom: 10px;
  27. font-size: small;
  28. }
  29. </style>
  30. <script type="text/javascript" src="../../base.js"></script>
  31. <script type="text/javascript">
  32. goog.require('goog.debug.DivConsole');
  33. goog.require('goog.events');
  34. goog.require('goog.events.EventType');
  35. goog.require('goog.graphics');
  36. goog.require('goog.log');
  37. </script>
  38. </head>
  39. <body>
  40. <div>
  41. <span id="shapes"></span>
  42. </div>
  43. <div>
  44. <span id="colors"></span>
  45. </div>
  46. <p>
  47. <a href="javascript:void(logconsole.clear())">Clear Log</a>
  48. </p>
  49. <div id="log"></div>
  50. <p> Try to mouse over, mouse out, or click the ellipse and the group of
  51. circles. The ellipse will be disposed in 10 sec.
  52. </p>
  53. <script type="text/javascript">
  54. // Set up a logger to track responses
  55. var log = goog.log.getLogger('Events');
  56. goog.debug.LogManager.getRoot().setLevel(goog.log.Level.ALL);
  57. var logconsole = new goog.debug.DivConsole(document.getElementById('log'));
  58. logconsole.setCapturing(true);
  59. // A helper function to handle events.
  60. function handleEvent(elementType) {
  61. return function(e) {
  62. log.info(elementType + ' ' + e.type + '.');
  63. }
  64. }
  65. // The events to catch.
  66. var events = [goog.events.EventType.MOUSEOVER,
  67. goog.events.EventType.MOUSEOUT,
  68. goog.events.EventType.CLICK]
  69. // Create an elipse.
  70. var graphics = goog.graphics.createGraphics(600, 200);
  71. var fill = new goog.graphics.SolidFill('yellow');
  72. var stroke = new goog.graphics.Stroke(2, 'green');
  73. var elipseElem = graphics.drawEllipse(300, 140, 80, 40, stroke, fill);
  74. goog.events.listen(elipseElem, events, handleEvent('Ellipse'));
  75. // Create a group of circles.
  76. stroke = new goog.graphics.Stroke(1, 'black');
  77. var group = graphics.createGroup();
  78. goog.events.listen(group, events, handleEvent('Group'));
  79. fill = new goog.graphics.SolidFill('blue');
  80. var blueCircle = graphics.drawCircle(500, 60, 40, stroke, fill, group);
  81. goog.events.listen(blueCircle, events, handleEvent('Blue-Circle'));
  82. fill = new goog.graphics.SolidFill("red", 0.5);
  83. var redCircle = graphics.drawCircle(500, 90, 40, stroke, fill, group);
  84. goog.events.listen(redCircle, events, handleEvent('Red-Circle'));
  85. fill = new goog.graphics.SolidFill('green', 0.2);
  86. var greenCircle = graphics.drawCircle(500, 120, 40, stroke, fill, group);
  87. goog.events.listen(greenCircle, events, handleEvent('Green-Circle'));
  88. graphics.render(document.getElementById('shapes'));
  89. goog.global.setTimeout(function() {elipseElem.dispose();}, 10000);
  90. </script>
  91. </body>
  92. </html>