ratings.html 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
  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>Ratings Widget</title>
  10. <script type="text/javascript" src="../base.js"></script>
  11. <script type="text/javascript">
  12. goog.require('goog.events');
  13. goog.require('goog.ui.Ratings');
  14. </script>
  15. <style class="text/css">
  16. /* NOTE(pupius): Horrible class names needed to get around IE6 not supporting
  17. the ".foo.bar" selector */
  18. #test {
  19. height: 20px;
  20. }
  21. label {
  22. padding-left: 5px;
  23. font: normal 13px/20px arial;
  24. color: #999;
  25. }
  26. .goog-ratings {
  27. display: block;
  28. float: left;
  29. height: 20px;
  30. height: 20px;
  31. }
  32. .goog-ratings-star {
  33. display: block;
  34. float: left;
  35. padding-left: 13px;
  36. height: 19px;
  37. cursor: pointer;
  38. background-image: url('../images/ratingstars.gif');
  39. background-repeat: no-repeat;
  40. }
  41. .goog-ratings-star.goog-ratings-disabled {
  42. opacity: 0.7;
  43. }
  44. .goog-ratings-firststar-off {
  45. padding-left: 20px;
  46. background-position: 0px 0px;
  47. }
  48. .goog-ratings-firststar-on {
  49. padding-left: 20px;
  50. background-position: 0px -20px;
  51. }
  52. .goog-ratings-midstar-off {
  53. background-position: 0px -40px;
  54. }
  55. .goog-ratings-midstar-on {
  56. background-position: 0px -60px;
  57. }
  58. .goog-ratings-laststar-off {
  59. padding-left: 18px;
  60. background-position: 0px -80px;
  61. }
  62. .goog-ratings-laststar-on {
  63. padding-left: 18px;
  64. background-position: 0px -100px;
  65. }
  66. </style>
  67. </head>
  68. <body>
  69. <div id="test1">
  70. <select name="sel">
  71. <option>Awful</option>
  72. <option>Bad</option>
  73. <option selected>Ok</option>
  74. <option>Good</option>
  75. <option>Excellent</option>
  76. </select>
  77. <label id="lab" for="sel">Rate this...</label>
  78. </div>
  79. <div id="test2" style="height: 40px;"></div>
  80. <div id="test3" style="height: 40px;"></div>
  81. <div id="test4" style="height: 40px;"></div>
  82. <script type="text/javascript">
  83. var rw1 = new goog.ui.Ratings();
  84. var defaultText = 'Rate this...';
  85. goog.events.listen(rw1, 'change', function(e) {
  86. defaultText = e.target.getValue() || 'Rate this...';
  87. document.getElementById('lab').innerHTML = defaultText;
  88. });
  89. goog.events.listen(rw1, 'highlightchange', function(e) {
  90. document.getElementById('lab').innerHTML =
  91. e.target.getHighlightedValue() || defaultText;
  92. });
  93. rw1.decorate(document.getElementById('test1'));
  94. var rw2 = new goog.ui.Ratings();
  95. rw2.setRatings([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
  96. rw2.render(document.getElementById('test2'));
  97. rw2.setSelectedIndex(3);
  98. setTimeout(function() { rw2.setSelectedIndex(8); }, 500);
  99. setTimeout(function() { rw2.setSelectedIndex(5); }, 750);
  100. setTimeout(function() { rw2.exitDocument(); }, 1000);
  101. setTimeout(function() { rw2.setSelectedIndex(1); }, 1250);
  102. setTimeout(function() { rw2.render(document.getElementById('test3')); }, 1500);
  103. setTimeout(function() { rw2.setSelectedIndex(4); }, 1750);
  104. setTimeout(function() { rw2.setSelectedIndex(8); }, 2000);
  105. setTimeout(function() { rw2.setEnabled(false); }, 3000);
  106. setTimeout(function() { rw2.exitDocument(); }, 4000);
  107. setTimeout(function() { rw2.render(document.getElementById('test4')); }, 5000);
  108. setTimeout(function() { rw2.setEnabled(true); } , 6000);
  109. setTimeout(function() { rw2.exitDocument(); }, 7000);
  110. </script>
  111. </body>
  112. </html>