Rater Js
rater-js is a star rating widget for the browser.
Main features:
- Unlimited number of stars.
- Svg as background image makes it look good in any size.
- Custom css. Use your own image as star.
Try Rater JS Demo →
Installation
npm install rater-js --save
Usage
rater-js can be used with amd, commonjs or without any module loader using global scope.
In your html create an element that acts as the placeholder for the widget.
<div id="rater"></div>
Global scope
Directly reference the js from the module
<script src="node-modules/rater-js/index.js"></script>
The widget will be available globally as "raterJs" on the window object.
Node/Browserify
Just require the module.
var rater = require("rater-js");
Lastly we can use the widget like this:
var myRater = rater({element: document.querySelector("#rater"), rateCallback: function rateCallback(rating, done) {
myDataService.rate(rate).then(function(avgRating) {
myRater.setRating(avgRating);
myRater.disable();
done();
}, function(error) {
done();
});
}});
Css will be injected at runtime, but you can override the css to get the look you want.
//change the whole image used as the star. Make sure to set starSize in options if not 16px.
//first image is for the 'off' mode
.star-rating {
background: url("myStar_off.svg") !important;
}
//add style for 'on' mode
.star-rating .star-value{
background: url("myStar_on.svg") !important;
}
Configuration
{
element: HtmlElement,
rateCallback: Function,
max: "Number of stars",
starSize: "Width and height of the star image in pixels",
disableText: "Text",
ratingText: "Text {rating} {maxRating}",
isBusyText: "Text",
readOnly: true/false
}
Methods
disable():
enable():
setRating(rating:number):
getRating():