Socket
Socket
Sign inDemoInstall

rater-js

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rater-js

Star rating widget for the browser.


Version published
Weekly downloads
1.7K
decreased by-24.81%
Maintainers
1
Weekly downloads
 
Created
Source

Rater Js

rater-js Logo

NPM version License Downloads

rater-js is a star rating widget for the browser.

Main features:

  • Unlimited number of stars.
  • 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

<!--Add js before end body tag-->
<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) {
                //make async call to server however you want
                //in this example we have a 'service' that rate and returns the average rating
                myDataService.rate(rate).then(function(avgRating) {
                    //update the avarage rating with the one we get from the server
                    myRater.setAvgRating(avgRating);
                     //we could disable the rater to prevent another rating
                     //if we dont want the user to be able to change their mind
                    myRater.disable();
                    //dont forget to call done
                    done();
                }, function(error) {
                        //handle the error
                        //dont forget to call done
                        done();
                });
	}});

Css will be injected at runtime, but you can override the css to get the look you want.

//make the stars red
.star-rating .star-value {
        background-color: red !important;
}

//change the whole image used as the star. Make sure to set starWidth in options if not 18px.
.star-rating .star-bg{
        background: url("myStar.svg") !important;
}

Configuration

{
        element: HtmlElement, //required
        rateCallback: Function,
        max: "Number of stars",
        starWidth: "Width of the star image in pixels",
        disableText: "Text",
        ratingText: "Text {rating}",
        isBusyText: "Text", //displayed while user is rating but done not called yet
        readOnly: true/false
}

Methods

disable(): //Disable the widget
enable(): //Enable the widget
setAvgRating(rating:number): //Set the average rating
getAvgRating(): //Get the average rating
getMyRating(): //Get the rating the user submitted
setMyRating(rating:number): //Set the rating the user submitted

Keywords

FAQs

Package last updated on 23 Mar 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc