npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

star-rating-svg

v3.5.0

Published

A star rating plugin based on svg

Downloads

4,097

Readme

A basic, yet flexible star rate jQuery plugin, using SVG.

###Features:

  • Doesn't use images
  • Customize size
  • Customize colors
  • Use half or full stars
  • Choose the number of stars to be displayed
  • Define gradient color of selected stars
  • Specify a border/stroke thickness and color
  • Specify initial rating via options or markup data attribute
  • Execute callback after rating (ex. to notify a server)
  • onHover and onLeave events
  • Locked / Read-only mode
  • Unload option

demo

For a working demo, see: http://nashio.github.io/star-rating-svg/demo

Usage

  1. Include jQuery:

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
  2. Include plugin's code:

    <script src="jquery.star-rating-svg.js"></script>
  3. Include plugin's css:

    <link rel="stylesheet" type="text/css" href="star-rating-svg.css">
  4. Add the markup

    <div class="my-rating"></div>
  5. Call the plugin:

    $(".my-rating").starRating({
        starSize: 25,
        callback: function(currentRating, $el){
            // make a server call here
        }
    });

Options

| option | default | description | |---|---|---| | totalStars | 5 | Amount of stars to show | | initialRating | 0 | Initial rating applied on load | | starSize | 40 | width in pixels of each star | | useFullStars | false | rate using whole stars, if enabled, it doesn't use half-steps | | emptyColor | lightgray | Color assigned to an empty star | | hoverColor | orange | Color assigned to hovered star | | activeColor | gold | Color assigned to active rated star | | useGradient | true | Active stars will use gradient coloring | | | | To use this option you need to populate the object [starGradient] | | starGradient | {start: '#FEF7CD', end: '#FF9511'} | Define the star and end colors for the gradient | | readOnly | false | If false any interaction is disabled | | disableAfterRate | true | Removes further events once a rate is selected | | strokeWidth | 0 | Defines the thickness of the border, 0 is disabled | | strokeColor | black | Defines the color for the border |

Methods

| method | arguments | description | |---|---|---| | unload |   | Destroys the instance and removes events attached to it | | setRating | 0 to max stars (int), round (Boolean) | Manually sets the rating | | getRating |   | Gets the current rating from instance |

// unload example
$('your-selector').starRating('unload')
// set rating example
$('your-selector').starRating('setRating', 2.5)
// set rating and round
$('your-selector').starRating('setRating', 2.8, true) // 3.0
// get rating example
$('your-selector').starRating('getRating')

Callbacks

| name | arguments | description | |---|---|---| | callback | rating, DOM element | Executes when selecting a rate |

$('your-selector').starRating({
    callback: function(currentRating, $el){
    	// do something after rating
    }
});

Events

| method | description | |---|---| | onHover | executes a callback on mouseover | | onLeave | executes a callback on mouseout |

$('your-selector').starRating({
    onHover: function(currentIndex, currentRating, $el){
			// do something on mouseover
    },
    onLeave: function(currentIndex, currentRating, $el){
			// do something after mouseout
    }
});

Files

Code example

demo/index.html/

Source file

src/

Minified version

dist/

Changelog

1.0.1

  • Fixes Firefox hover issues

1.0.0

  • Adds set rating, and get rating
  • Adds onHover event
  • Adds onLeave event

0.9.4

  • Fixes support for enabling full stars

0.9.3

  • Returns element on callback
  • Fixed typos

0.8.2

  • Fixed bugs related to rendering in retina

0.8.0

  • Added readonly mode

License

The MIT License (MIT)