jQuery Raty - A Star Rating Plugin (current version: 1.0.0)
buy me a coffee

jQuery Raty is a plugin that generates a customizable star rating automatically.
With default options:
$('#default').raty();

<div id="default"></div>
Started with a score and read only value:
$('#fixed').raty({
  readOnly:  true,
  start:     2
});

<div id="fixed"></div>
A hint for no rated elements when it's read-only:
$('#anyone').raty({
  readOnly:   true,
  noRatedMsg: 'anyone rated this product yet!'
});

<div id="anyone"></div>
With a custom score name and a number of stars:
$('#number').raty({
  scoreName:  'entity.score',
  number:     10
});

<div id="number"></div>
Using onClick function:
$('#click').raty({
  onClick: function(score) {
    alert('score: ' + score);
  }
});

<div id="click"></div>

- The argument score is the selected value;
- In the function you can mension the star element itself using "this".
Displaying half star:
$('#half').raty({
  start:     3.3,
  showHalf:  true
});

<div id="half"></div>

The interval can be:
- Rounded down: [x.00 ... x.25]
- Half star:    [x.26 ... x.75]
- Rounded up:   [x.76 ... x.99]
With a default cancel button:
$('#cancel').raty({
  showCancel: true
});

<div id="cancel"></div>

- The score for the click on cancel button is 0 (zero).
With a custom cancel button:
$('#cancel-custom').raty({
  cancelHint:   'remove my rating!',
  cancelPlace:  'right',
  showCancel:   true
  onClick: function(score) {
    alert('score: ' + score);
  }
});

<div id="cancel-custom"></div>
With a custom hint and icons:
$('#icon').raty({
  hintList:  ['a', '', null, 'd', '5'],
  starOn:    'medal-on.png',
  starOff:   'medal-off.png'
});

<div id="icon"></div>
With a range of custom icons:
$('#range').raty({
  iconRange: [['face-a.png', 2], ['face-b.png', 3], ['face-c.png', 4], ['face-d.png', 5]],
  starOff:   'face-off.png'
});

<div id="range"></div>

- It's a array of array where each inner array represents a custom icon;
- The second parameter is until where this icon will be displayed;
- The sequence of the range interval should be in a ascending order.
With a group of elements:
$('.group').raty();

<div class="group"></div>
<div class="group"></div>
<div class="group"></div>

- The ID is optional and must be unique;
- If you don't pass a ID for the element, then it will be created.
Using directed actions with public functions:
love:
happy:

your last rate:
$('.target').raty({
  showHalf:   true,
  onClick: function(score) {
    $.fn.raty.start(0, '.target');
    $.fn.raty.start(score, '#result');
  }
});

<div class="target"></div>
<div class="target"></div>

<div id="result"></div>

- All public functions have a optional second parameter to specify which container will be executed;
- You can pass a ID or a class to be the target of the action;
- If the ID or class are not specified, then the last element Raty will be takes.
Default options:
cancelHint:   'cancel this rating!'
The hint information.
cancelOff:    'cancel-off.png'
Name of the cancel image off.
cancelOn:     'cancel-on.png'
Name of the cancel image on.
cancelPlace:  'left'
Position of the cancel button.
hintList:     ['bad', 'poor', 'regular', 'good', 'gorgeous']
List of names that will be used as a hint on each star.
iconRange:    []
Path where are the images of the stars.
noRatedMsg:   'not rated yet'
A hint for no rated elements when it's read-only.
number:       5
Number of stars that will be presented.
path:         'img/'
A range of custom icons that you can set.
readOnly:     false
If the stars will be read-only.
scoreName:    'score'
Name of the hidden field that holds the score value.
showCancel:   false
If will be showed a button to cancel the rating.
showHalf:     false
If will show half star if come a float number as score.
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.
start:        0
Number of stars to be selected.
onClick:      null
Function that returns the selected value.
Public functions:
$.fn.raty.start(3);
Starting the rating with 3 stars later.
$.fn.raty.readOnly(true);
Adjusts the rating for read-only later.
$.fn.raty.click(2);
Click in the star number 2 later.

Polly po-cket