|

Starbox allows you to easily create all kinds of rating boxes using just one PNG image
download:http://www.hotajax.org/download/otherjs/starbox.zip
demo:
How to use
Download and include Prototype 1.6 in your header. If you want to use effects, also add Scriptaculous 1.8. Make sure you are using the stable releases and not the release candidates or preview releases. After both are included, add Starbox
<script src="js/prototype.js" type="'text/javascript'">
</script>
<script src="js/scriptaculous.js?load=effects" type="'text/javascript'">
</script>
<script src="js/starbox.js" type="'text/javascript'">
</script>Add starbox.css to your header.
<link href="css/starbox.css" type="text/css" rel="stylesheet" /> %3Cscript%20src%3D%22js%2Fprototype.js%22%20type%3D%22%27text%2Fjavascript%27%22%3E%0D%0A%3C%2Fscript%3E%0D%0A%3Cscript%20src%3D%22js%2Fscriptaculous.js%3Fload%3Deffects%22%20type%3D%22%27text%2Fjavascript%27%22%3E%0D%0A%3C%2Fscript%3E%20%0D%0A%3Cscript%20src%3D%22js%2Fstarbox.js%22%20type%3D%22%27text%2Fjavascript%27%22%3E%0D%0A%3C%2Fscript%3EAdd%20starbox.css%20to%20your%20header.%0D%0A%3Clink%20href%3D%22css%2Fstarbox.css%22%20type%3D%22text%2Fcss%22%20rel%3D%22stylesheet%22%20%2F%3E Make sure these images and your own stars are in the same directory as starbox.css default.png, bigstar.png, pointy.png, default_dotted_background.gif
After that creating a starbox is as easy as:
new Starbox(element, rating); new%20Starbox%28element%2C%20rating%29%3B
More advanced Starboxes can be made using a thirth parameter with options, a few examples:
new Starbox(element, rating, { stars: 10, buttons: 20, max: 10 });
new Starbox(element, rating, { onRate: yourAjaxSaveFunction, inverse: true });new%20Starbox%28element%2C%20rating%2C%20%7B%20stars%3A%2010%2C%20buttons%3A%2020%2C%20max%3A%2010%20%7D%29%3B%20%0A%0D%0Anew%20Starbox%28element%2C%20rating%2C%20%7B%20onRate%3A%20yourAjaxSaveFunction%2C%20inverse%3A%20true%20%7D%29%3B
This are all the options you can use:
new Starbox( element, // the id of your element
rating, // rating to start with
{
background: false, // or a css background to overwrite the one in class
buttons: 5, // the number of buttons (choices)
className : 'default', // or your own classname
color: false, // color of the colorbar
duration: 0.6, // duration of the effect across the bar, if used
effect: { mouseover: false, mouseout: true } // or your own
hoverClass: 'hover', // or your own classname
hoverColor: false, // color of the colorbar when hovered
identity: false, // used on the return info
indicator: false, // adds an indicator after the starbox using a string,
// #{average}, #{max} and #{total} can be used.
// example: '#{average}/#{max} out of #{total} votes'
inverse: false, // true, false
locked: false, // true, false
lockOnRate: true, // true, false
max: 5, // maximum rating, that of the last star
onRate: false, // or function(element, info){}
// info = { identity: identity,
// rating: rating,
// average: average,
// max: max,
// total: total
// }
overlay: 'default.png', // or other png in same folder as starbox.css
stars: 5, // the amount of stars
total : 0 // the amount of votes cast } );new%20Starbox%28%20%20%20%20element%2C%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20the%20id%20of%20your%20element%20%0A%0D%0Arating%2C%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20rating%20to%20start%20with%20%0D%0A%7B%20%0D%0Abackground%3A%20false%2C%20%20%20%20%20%20%2F%2F%20or%20a%20css%20background%20to%20overwrite%20the%20one%20in%20class%20%0D%0Abuttons%3A%205%2C%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20the%20number%20of%20buttons%20%28choices%29%20%0D%0AclassName%20%3A%20%27default%27%2C%20%20%2F%2F%20or%20your%20own%20classname%20%0D%0Acolor%3A%20false%2C%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20color%20of%20the%20colorbar%20%0D%0Aduration%3A%200.6%2C%20%20%20%20%20%20%20%20%20%20%2F%2F%20duration%20of%20the%20effect%20across%20the%20bar%2C%20if%20used%20%0D%0Aeffect%3A%20%7B%20mouseover%3A%20false%2C%20mouseout%3A%20true%20%7D%20%2F%2F%20or%20your%20own%20%0D%0AhoverClass%3A%20%27hover%27%2C%20%20%20%20%2F%2F%20or%20your%20own%20classname%20%0D%0AhoverColor%3A%20false%2C%20%20%20%20%20%20%2F%2F%20color%20of%20the%20colorbar%20when%20hovered%20%0D%0Aidentity%3A%20false%2C%20%20%20%20%20%20%20%20%2F%2F%20used%20on%20the%20return%20info%20%0D%0Aindicator%3A%20false%2C%20%20%20%20%20%20%20%2F%2F%20adds%20an%20indicator%20after%20the%20starbox%20using%20a%20string%2C%20%0D%0A%2F%2F%20%23%7Baverage%7D%2C%20%23%7Bmax%7D%20and%20%23%7Btotal%7D%20can%20be%20used.%20%0D%0A%2F%2F%20example%3A%20%27%23%7Baverage%7D%2F%23%7Bmax%7D%20out%20of%20%23%7Btotal%7D%20votes%27%20%0D%0Ainverse%3A%20false%2C%20%20%20%20%20%20%20%20%20%2F%2F%20true%2C%20false%20%0D%0Alocked%3A%20false%2C%20%20%20%20%20%20%20%20%20%20%2F%2F%20true%2C%20false%20%0D%0AlockOnRate%3A%20true%2C%20%20%20%20%20%20%20%2F%2F%20true%2C%20false%20%0D%0Amax%3A%205%2C%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20maximum%20rating%2C%20that%20of%20the%20last%20star%20%0D%0AonRate%3A%20false%2C%20%20%20%20%20%20%20%20%20%20%2F%2F%20or%20function%28element%2C%20info%29%7B%7D%20%0D%0A%2F%2F%20info%20%3D%20%7B%20identity%3A%20identity%2C%20%0D%0A%2F%2F%20%20%20%20%20%20%20%20%20%20rating%3A%20rating%2C%20%0D%0A%2F%2F%20%20%20%20%20%20%20%20%20%20average%3A%20average%2C%20%0D%0A%2F%2F%20%20%20%20%20%20%20%20%20%20max%3A%20max%2C%20%0D%0A%2F%2F%20%20%20%20%20%20%20%20%20%20total%3A%20total%20%0D%0A%2F%2F%20%20%20%20%20%20%20%20%7D%20%0D%0Aoverlay%3A%20%27default.png%27%2C%20%2F%2F%20or%20other%20png%20in%20same%20folder%20as%20starbox.css%20%0D%0Astars%3A%205%2C%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20the%20amount%20of%20stars%20%0D%0Atotal%20%3A%200%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20the%20amount%20of%20votes%20cast%20%20%20%20%7D%20%20%29%3B
Styling
You can style your starboxes with CSS, in starbox.css you can find a few examples on how to do this. Note that the only thing you can not set through CSS is the overlay image.
This is one of the examples from starbox.css:
.starbox .default { background: #cccccc; }
.starbox .default .colorbar { background: #1e90ff; }
.starbox .default .hover .colorbar { background: #ffcc1c; }.starbox%20.default%20%7B%20background%3A%20%23cccccc%3B%20%7D%20%0D%0A.starbox%20.default%20.colorbar%20%7B%20background%3A%20%231e90ff%3B%20%7D%20%0D%0A.starbox%20.default%20.hover%20.colorbar%20%7B%20background%3A%20%23ffcc1c%3B%20%7D
And to get a better idea of how Starbox can be styled, a view of it's structure:
<p><div class="starbox" id="yourId">
<div class="stars default"><!-- default or your className --> </p>
<p><div class="hover"><!-- has hover class on mouseover --> </p>
<p><div class="colorbar">
<div><!-- stars --></div></div></div></div> </p>
<p><div class="indicator"><!-- indicator text if used --></div></div> </p> %0D%0A%3Cp%3E%3Cdiv%20class%3D%22starbox%22%20id%3D%22yourId%22%3E%0D%0A%3Cdiv%20class%3D%22stars%20default%22%3E%3C%21--%20default%20or%20your%20className%20--%3E%20%3C%2Fp%3E%0D%0A%3Cp%3E%3Cdiv%20class%3D%22hover%22%3E%3C%21--%20has%20hover%20class%20on%20mouseover%20--%3E%20%3C%2Fp%3E%0D%0A%3Cp%3E%3Cdiv%20class%3D%22colorbar%22%3E%0D%0A%3Cdiv%3E%3C%21--%20stars%20--%3E%3C%2Fdiv%3E%3C%2Fdiv%3E%3C%2Fdiv%3E%3C%2Fdiv%3E%20%3C%2Fp%3E%0D%0A%3Cp%3E%3Cdiv%20class%3D%22indicator%22%3E%3C%21--%20indicator%20text%20if%20used%20--%3E%3C%2Fdiv%3E%3C%2Fdiv%3E%20%3C%2Fp%3E
|