Giter VIP home page Giter VIP logo

raty's Introduction

Raty - A Star Rating Plugin.

Tests NPM Version Maintainability Sponsor

Rating for Rails?

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

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>
new Raty(document.querySelector('[data-raty]'));

Usage with Font

  • raty.css
  • raty.[eot|svg|ttf|woff]
  • raty.js
<link rel="stylesheet" href="raty.css">

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

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

Options

Property Default Description
cancelButton false Creates 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.
click undefined Callback executed on rating click.
half false Enables half star selection.
halfShow true Enables half star display.
hints ['bad', 'poor', 'regular', 'good', 'gorgeous'] Hints used on each star.
iconRange undefined Object list with position and icon on and off to do a mixed icons
iconRangeSame false All icons prior to selection will be the same as the selection.
mouseout undefined Callback executed on mouseout.
mouseover undefined Callback executed on mouseover.
noRatedMsg 'Not rated yet!' Hint for non rated elements when it's readOnly.
number 5 The number of stars that will be presented.
numberMax 20 Max number of stars star the option number will create.
path undefined A global path where the icon will be found.
precision false Enables the selection of a precise score.
readOnly false Turns the rating read-only.
round { down: .25, full: .6, up: .76 } Includes value attributes to do the score rounding math.
score undefined Initial rating.
scoreName 'score' Name of the hidden field that holds the score value.
single false Enables single star selection.
space true Puts 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.
target undefined Element selector where the score will be displayed.
targetFormat '{score}' Template to interpolate the score in.
targetKeep false If the last rating value will be kept on mouseout.
targetScore undefined Score 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]'));
Function Description
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.

raty's People

Contributors

andersonba avatar aprimadi avatar danielfariati avatar danielpsf avatar debadutta98 avatar dentarg avatar eblanshey avatar ecabuk avatar eriwen avatar eskimoblood avatar fono09 avatar fsouza avatar fyzu avatar gabrielbenz avatar gnikyt avatar havvg avatar henrikhannemose avatar hpgihan avatar jaskaran-techno avatar juriejan avatar muratguzel avatar nazarhussain avatar nimmer avatar olegki avatar rmbl avatar stecb avatar tfantina avatar wbotelhos avatar yadhu avatar yskkin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

raty's Issues

If multiple "ratings on pages", only first displays

Realised that if there are multiple ratings on a page, and you are using start value of double eg 3.3 instead of integer, only the first rating component dsiplays. the remaining components are not displayed.

A little debugging showed this line to be the culprit

hint = (options.number <= options.hintList.length && options.hintList[start - 1] !== null) ? options.hintList[start - 1] : start;

Line number 198 in version 0.6 release.

Commenting out that and providing dummy hints fixed the issue but obviously, the hints on the displayed widget were wrong
Commenting out that and providing some dummy hints f

Add option to only show the selected star

Add an option to only show the selected rating icon. Add a flag option to use the following fillStar function:

function fillStar(id, score, opt) {
    var qtyStar = $('img.' + id).length,
        item    = 0,
        range   = 0,
        star,
        starOn;

    for (var i = 1; i <= qtyStar; i++) {
        star = $('img#' + id + '-' + i);


        if(i != score)
        {
            star.attr('src', opt.path + opt.starOff);
        }

        if (i == score)
        {
            star.attr('src', opt.path + opt.iconRange[i-1][0]);
        }

    }
};

Raty not working in bootstrap popover

Hi,
I've added raty in bootstrap popover. It is not working in bootstrap popover windows but outside it works. Here is a js fiddle. Am I missing something?

EDIT: Here is a rating code. Inside popover I am not able to click on ratings.

   $('.ratings').raty({
    click: function(score, evt) {
        alert(score);
    }
    });

Thanks

Raty problems with multiple instances?

Hi, when I do multiple instances of raty, it seems like Raty adds a half star even though it's a solid rating (4.0/3.0/2.0).

$(function(){
$('.star').each(function(el){
            $(this).raty({
                readOnly:true,
                path: 'media/template/js/raty/img',
                start: $(this).attr('data-rating'))
            });
});
});
<div class="detail_item star" data-rating='{{ r.rating }}'>
</div>
{{ r.rating }}

Here's an image: http://i.imgur.com/EXXlY.png (the score next to the stars is the string sent to Raty)

I've tried different things, like parseFloat(), Number(), String(), stripping the text, replacing the ".0" with "", ...but this problem still stays.

Any ideas? Thanks !

$.fn.raty.start(3) for multiply stars containers

Great plugin!

I have 2 stars containers:

<div class="rating_block">
<span>Idea</span><div class="rating design"
    data-id="11"
    data-rating="4.8"
></div>

<span>Design</span><div class="rating idea" 
    data-id="12"
    data-rating="3.4"
></div>

I start raty with this code:
$('.rating').each(function(){
var id = $(this).data("id");
var rating = $(this).data("rating");
$(this).raty({
start: rating,
showHalf: true,
path: '/pics/',
onClick: function(score) {
alert('score: ' + id + ' ' + score);
$.fn.raty.start( Math.random()*5 );
}
});
});

And every time i click star in the first container stars are changed in last one.

May be additional argument can help? For example this function can be looking this:
$.fn.raty.start(2,'.idea'); - second argument is [optional] and will "filter" set of containers to required.

[email protected]

Problem with star images larger than 16px

If I try to use star images larger than 16px in width, all stars won't fit in one line.
I think problem occurs because width of 20px (img width 16px + margin of 2px or something similar) is hard-coded.

This line causes the problem (and similar line two rows before): $global.css('width', options.number * 20);

I think that width should be removed totally, user can set it if he needs it.

using doomhz / jQuery-Image-Cache to prevent repeated server fetching.

I wrote a setSource(icon) function in my fork which I used to set the icon sources to localStorage rather than url path in order to prevent raty from repeatedly fecthing stars from the server. However, I was not clever enough to set self.opt.XX in my function so my hack of using $.fn.raty.defaults.xx is inelegant and not changable through a settings JSON.

If someone would please look at this and advise how to init self.opt in setSource function: I think this change might be worthy of pull request.

note: I separately load icon images into localStorage with doomhz/jQuery-Image-Cache.

Create round option

Round option will give flexibility to choose the exact point of rounding using half star.

The following values are inclusives:

round: { down: .25, full: .6, up: .76 }

Between 25 and 76 is half star, but if halfShow option is disabled, then full will adjust the star to next full star.

Add inactive icon parameter to the iconRange option

For now you can choose the active icons on each star, but you cannot choose the inactives icons.

It would be a good idea to add the parameter that indicates the inactive icon on the option iconRage.
And if this option does not be passed, then it will be the default starOff option value.

iconRange: [ [1, 'first-on.png', 'first-off.png'] ]

Or something more verbose like:

iconRange: [ { value: 1, on: 'first-on.png', off: 'first-off.png' } ]

Utilização de tag IMG

Existe previsão de usar o plugin, sem empregar a tag IMG? Pois é interessante poder alterar a aparencia do plugin atraves de CSS, ao invés de o plugin usar tags IMG que obrigam o endereço ser mapeado a cada página e cada subnivel de pastas.

Need to Set Custom Rating Values

Hi,

I need to be able to get/set ratings on a scale of 1-10 using only 5 Stars. So if 2 1/2 stars are selected that would = 5. If 4 full stars are selected that would = 8, etc...

I couldnt find anywhere in the documentation if this is allowed.

Is this possible?

2 questions plz

Hi, and thank you so much for this nice plugin!
I have please 2 questions if you don't mind:
1- is it possible to set a score directly in the div of stars?? for example

2- I'll have to use the rating with a small text area, how can i check if a rating has been set before submitting the form??

thank you so much for your help
Regards

Raty sometimes adds multiple elements with the same id attribute, sometimes causing it to fill in the wrong number of stars

Sometimes, Raty will put multiple images on the page with the same id attribute. One can "trick" it into showing the wrong number of stars like so:

<!DOCTYPE html>
<html><head>
<title>Raty test</title>
</head>
<body>
<div class="container">
  <div class="stars">2</div>
</div>
<div class="container">
  <div class="stars">5</div>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script src="jquery.raty.js"></script>
<script>
$(function() {
  $(".container .stars").each(function() {
    $(this).raty({
      start: $(this).text(),
      readOnly: true,
      path: "http://www.wbotelhos.com/raty/img/"
    });
  });
});
</script>
</body></html>

The first container is supposed to have only 2 stars, but all 5 are filled in. I would come up with a jsFiddle for this issue but I don't have a copy of Raty to link to. The copy on your demo page (http://www.wbotelhos.com/raty/js/jquery.raty.js), despite having the same version number, is different, and does not have this bug.

Separate hover star?

I don't see it but is there an option to have the hover star different than the starOn option? I guess you would need a hoverOn, hoverHalf option. Thoughts?

Setting 'single' parameter to true doesn't work if the score parameter is set as well

This is the code I tried to make a simple animation with stars. What it does is to select only one star in a row.

var x = 1;
var i = setInterval(function() {
    $('.starRating').raty({
        single: true,
        score: x
    });
    x++;
    if ( x > 5 )
        clearInterval(i);
}, 200);

but it doesn't select only one star, but all the start before and including x. Any ideas?

Default target massage

I'm using target for "Your score: ".
Problem is onmouseOut - it deletes everything.
Using targetKeep make no sense because it displays start value - not user's score.
Can You make other variable? target's onmouseout default value, please ??:)

Can't load raty on divs generated by a $.ajax function

Hi,

I am using a $.ajax function to add new "comments" including raty divs on my page . But I can't apply the plugins on these new divs. Even if I run a "setRaty" function that executes something like $('.raty').raty({...}); the stars don't appear. Although, if I do $('.raty').html('test'); this runs correctly.
NB : the raty plugin works well with existing divs when the page is loaded.

Thank you for your help !

Jeremy

Can't get value?

Would be nice if there was an easy way to get the value of the raty object.

$('#big').raty() // creates 1-5

$('#big').val() // returns 1-5

No Method 'raty'

Looked at other issues but did not help. I've got the images and min.js file in my project.

Star images oversized when div generated with ajax

I'm having a really frustrating issue with the display of the rating. When I add the div statically it work just fine, but when it is inserted dynamically with ajax stars become oversized at around 100px in size. Setting width or height of the div doesn't resize the star itself. The stars also display vertically thought that might be because there is not enough space for oversized images.

It doesn't matter if I add "$('.rating').raty();" in .ready function or in the ajax success callback function.

I am also using jquery isotope plugin (layout animation) which might be delaying the availability of html elements in the dom but this is just guesswork and I've really no idea where to start looking.

Could you please take a look at the example here:

http://77.95.160.145/temp-test/movies.php (local server so might be slow)

You will see the rating display properly at the top of the page but when you click on the movie poster you will see the oversized stars.

Hints for halfstar-ratings

Hi,

First of nice plugin.

I've only found one little problem. When half-stars are enabled the hint looks a bit messy. What do I mean?

For example, if we have 5 stars, and the score is 2.5 (Average) the hint will show "Poor" as it considers it to be a 2 point rating. IMHO the tip should go in relation to the number of stars, therefore, 2.5 will fill partially the third star and therefore should read "Average".

Any option to get this to work?

adding mouseover function

I missed the possibility to handle a mouseover event to more more or something different than just showing a hint.

So i added it to the code. Would be great if you take it over to the base code:

  1. adding mouseover to $.fn.raty.defaults between iconRange and noRatedMsg so that it is still alphabetical ordered (around line 450):
    iconRange: undefined,
    mouseover: undefined,
    noRatedMsg: 'not rated yet',
  2. adding the call to opt.mouseover if it is defined (around line 185):
    adding following lines to the end of $stars.bind(action, function(evt) { starting in line 163
    if(opt.mouseover) {
    opt.mouseover.call(self[0], value, evt);
    }
  3. reset the call when the mouse leaves (around line 135):
    adding following lines to the end of self.mouseleave(function() {
    if(opt.mouseover) {
    opt.mouseover.call(self, $score.val());
    }

After doing the 3 changes above you can configure your raty a function like:
mouseover : function(score, evt) {
$("div[data-somthing='foo']").hide();
if(score) {
$("#text_" + score).show();
}
}

Note that you have to handle the case that score is undefined. That is the case when no star was selected.

Partial stars

Hi,

great piece of code, but one thing prevents me from using it: I need to rate with full stars, but I want to current rating to be displayed in stars with decimal. That means that 2.25 should show a quarter of star in its start value, no rounding. The only star rating code I saw capable of this is RateIt, however it can only display these partial stars in readonly mode. I need to combine both.

Thanks for considering my issue. Nice work so far!
Quentin

Problem when using image with full path (http://.../myimage.png

Hi everyone,

This morning I tried to use the raty plugin, with complete URLs for the images (http://.../myimage.png") . Even if you specify an empty value to the path parameter, you prefix the path with "/". So, if my URL is "http://localhost:80/myimage.png", in the generated HTML, we have "/http://localhost:80/myimage.png", and URL return a 404 error.

Maybe we can throw away the path parameter, if the url start with http:// ? or something else.

Manu

Half-star rating doesn't work when we programmatically set the rating's value

Hi. I'm using raty in an AJAX application, and I've stumbled upon the following issue: when the rating's value is assigned during the raty's initialization, the half-stars are displayed correctly. But if we set the rating via $('blah').raty('start', rating) call, it doesn't recognize the fractional values, e.g. 4.56 and so on, and will just display 4 full stars until the next page reload.

half stars without precision set int on target

When I enable half and disable precision the score contains correct values like 1.5, 3, 4.5 etc., but the target only receives integer values.

How can I enable it the way to have half stars and values?
I want to have half stars and values on the target of 0.5 increments.

update stars after ajax call issue

Hello,

I have a issue with raty.

I have two instances of the plugin applied to 2 divs.
One is for the global rating (average rating from all users that submitted a rating) and the other one is for the user rating of the displayed article.

I´m using ajax to store the rating of the user and then using the success function i want to update on the fly the global rating.
It´s all going ok except for one thing.
The target displays the average correctly, but the stars of the global ratings are not updated. They maintain the last value before the user submitted the vote). They correctly appear only if i refresh the page.

What am i doing wrong ?

I´m using the following code:

$('#artigo_rate_global').raty({
start: ,
target:'#target'
});
$('#artigo_rate_user').raty({
start: ,
target:'#target_user',
click: function(score){
var idr = $(this).attr("name");
var ida = ;
.ajax({
type: "post",
url: "rate.php",
dataType: "html",
data: {ida:ida, idr:idr, score:score},
//data: dataString,
success: function(data){
$('#target').html(data);
$('#artigo_rate_global').raty('start', data);
$('#artigo_rate_global').raty('readOnly', true);
$('#artigo_rate_user').raty('start', score);
$('#artigo_rate_user').raty('readOnly', true);
}
});
}
});

Create targetFormat option

It make possible to choose a template format to the target like:

targetFormat: 'your score is: {score}'

Don't confuse it with targetText that is a value setted on target when there is no score or targetKeep is false.

All ratings start as 3

Seems that all hidden inputs that raty() initializes start at 3 by default. Not sure if this is desired behavior. I expect it to start at 0 since that is default.

Allow score to be set back to 0

After I initialized it the element with raty, I should be able to reset the value to 0.

I tried:

$("#rating_selector").raty('set', {'score' : 0});

$("#rating_selector").raty('score', 0);

Both creates new rating.

Half-stars all over

If raty is being applied to multiple elements that do not have distinct 'id' attributes, the half stars show up all over the place. The quick fix is to simply assign arbitrary id's to the elements, but would be great if this weren't necessary. Thanks!

Current Raty will use last configuration when we have multilple Ratys in one page but would change one Raty's score dynamically

I love this plugin and I’m using 1.2.1 version, but I meet a problem when I need to refresh the start and score dynamically.

In my page, I have one readonly raty (says: Raty1, half=true) plugin and a non-readonly raty (says: Raty2, half=false).

When I click the Raty2 to vote, I will invoke a ajax action to do vote, after that, I will get average rating score from database and then update Raty1.

But when I use $.fn.raty.start(score, ‘#Raty1′) to refresh the Raty1. NOTE here, score is a float numeric, and half attribute is true for Raty1.

For example:
After executed $.fn.raty.start(2.66, ‘#Raty1′), the Raty1 will be reset to 2 stars!! Not 2 and half stars, and the hint will be reset to DEFAULT hint???

I don’t know whether it’s a bug?? Is it possible to fix?

BTW: I used following codes to create Raty1:
view source
print?
1 $('#Raty1").raty({
2 readOnly: true,
3 half: true,
4 hintList: [null],,
5 noRatedMsg: 'Not voted this idea yet!',
6 start: 2
7 });

5 noRatedMsg: 'Not voted this idea yet!',
6 start: 2
7 });

Probably not a real issue: hintList for halfstar-ratings

HI there,

thanks for this sweet thingy - we really like it :)

We are currently setting up a new multilingual project which requires us to localise the hintlist. When we were doing so, we realised that there is no chance to 'hintlist halfstar-ratings'. Are we right?!

We have an item which has a 0.5 rating but as soon as we move the cursor over raty the tooltip says: "not yet rated" or something like that. So question is, wether it's possible to 'hintlist halfstar-ratings also' or not?

Are we having the brainworms or is this 'feature' really missing?! Any hint or help is appreaciated.

Cheerio!

refresh or unbind plugin

Sometimes it's necessary to unbind a plugin to avoid overwriting functionality (to avoid duplicating them). This happens to me in an ajax based application. I just can't test if the divs already has raty attached. This, because the html actually is erased ib the app, but is generated once again via ajax. This conduces to a duplicated raty plugin (i just can't test if the plugin is active by searching for start images, see?).

So, maybe an unbind method, or maybe a refresh method like suggested in here: http://www.wbotelhos.com/2010/07/14/jquery-raty-a-star-rating-plugin/#comment-2288 would help.

Assigning .raty() to a class for use with multiple displays of rating stars for different 'objects' on a single page

For a project, I'm wanting to use .raty to show the rating set by a member for particluar object (event, restaurant, etc). I have four different methods: getReviewsByNameAscending, getReviewsByNameDescending, etc . . .

However, it seems as though I can only get raty to work correctly when I'm working with a SINGLE dom element (e.g. an ID or a CLASS that doesn't any siblings in the same class). What occurs when I use a class (and am applying .raty during an $each loop), is that all of the values for the for the rating are displayed (so, if there are four reviews, then you see four sets of stars for each review when there should (ideally) be only the set of stars related to that particular review.

Thoughts or ideas?

.raty is the CLEANEST solution out there for jquery rating. Period. Anyone reading this shouldn't be dissuaded by my issues from using it. I am trying to do something I dont think .raty was build for or can handle without some augmentation. Again, if you're looking for a easy, flexible jquery rating solution, .raty is it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.