4.3.0 • Published 10 days ago

raty-js v4.3.0

Weekly downloads
2,782
License
MIT
Repository
github
Last release
10 days ago

Raty - A Star Rating Plugin.

Tests NPM Version Maintainability Sponsor

Rating for Rails?

It's Rating: https://github.com/wbotelhos/rating :star:

Help

  • Check the Tutorial to learn about all available features.
  • If you're migrating from v3 to v4 check the Upgrade document.

Usage with Image

  • raty.js
  • star-off.png
  • star-on.png
<script src="raty.js"></script>

<div data-raty></div>
const raty = new Raty(document.querySelector('[data-raty]'));

raty.init();

Usage with Font

<link rel="stylesheet" href="raty.css">

<script src="raty.js"></script>

<div data-raty></div>
new Raty(document.querySelector('[data-raty]'), { starType: 'i' });

Options

PropertyDefaultDescription
cancelButtonfalseCreates a cancel button to cancel the rating.
cancelClass'raty-cancel'Name of cancel's class.
cancelHint'Cancel this rating!'The cancel's button hint.
cancelOff'cancel-off.png'Icon used on active cancel.
cancelOn'cancel-on.png'Icon used inactive cancel.
cancelPlace'left'Cancel's button position.
clickundefinedCallback executed on rating click.
halffalseEnables half star selection.
halfShowtrueEnables half star display.
hints['bad', 'poor', 'regular', 'good', 'gorgeous']Hints used on each star.
iconRangeundefinedObject list with position and icon on and off to do a mixed icons
iconRangeSamefalseAll icons prior to selection will be the same as the selection.
mouseoutundefinedCallback executed on mouseout.
mouseoverundefinedCallback executed on mouseover.
noRatedMsg'Not rated yet!'Hint for non rated elements when it's readOnly.
number5The number of stars that will be presented.
numberMax20Max number of stars star the option number will create.
pathundefinedA global path where the icon will be found.
precisionfalseEnables the selection of a precise score.
readOnlyfalseTurns the rating read-only.
round{ down: .25, full: .6, up: .76 }Includes value attributes to do the score rounding math.
scoreundefinedInitial rating.
scoreName'score'Name of the hidden field that holds the score value.
singlefalseEnables single star selection.
spacetruePuts space between the icons.
starHalf'star-half.png'The name of the half star image.
starOff'star-off.png'Name of the star image off.
starOn'star-on.png'Name of the star image on.
targetundefinedElement selector where the score will be displayed.
targetFormat'{score}'Template to interpolate the score in.
targetKeepfalseIf the last rating value will be kept on mouseout.
targetScoreundefinedScore field target avoiding hidden field creation
targetText''Default text in a target.
targetType'hint'Choose if target will receive a hint or the score number
starType'img'Element used to represent a star.

Functions

To call some function, first, save the Raty instance on a variable and then call the functions:

var raty = new Raty(document.querySelector('[data-raty]'));
FunctionDescription
raty.score()Get the current score.
raty.score(number)Set a score.
raty.click(number)Click on a star.
raty.readOnly(boolean)Change the read-only state.
raty.cancel(boolean)Cancel the rating. The last param force the click callback.
raty.move(number)Move the mouse to the given score point position.

Build

gulp 'amd'
gulp 'umd'
gulp 'commonjs'
gulp 'systemjs'
gulp 'es6'
gulp 'es5'
gulp 'es5-test'
4.3.0

10 days ago

4.2.0

9 months ago

4.1.0

2 years ago

4.0.0

2 years ago

3.1.1

3 years ago

3.1.0

3 years ago

3.0.0

4 years ago

2.9.0

6 years ago

2.8.0

7 years ago

2.7.1

8 years ago

2.7.0

8 years ago