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