Giter VIP home page Giter VIP logo

Comments (10)

shadowfax avatar shadowfax commented on May 21, 2024

Ok...

Line 259 reads:
score = parseInt(this.score.val(), 10),

This rounds the score value the same way as Math.floor... I've changed this to

score = parseInt(Math.ceil(this.score.val()), 10),

...and now it shows the correct message.

from raty.

wbotelhos avatar wbotelhos commented on May 21, 2024

Hi shadowfax,

The hints are alt tag, then it is one per star.
We can't change the sequence, because Raty use it to calculate a lot of things.
I want to do a feature to show real hint like a pop up and let alt do it job: 1 2 3 4 5.

If you have some ideia of how to take off this dependency of the alt attribute let me know.

from raty.

shadowfax avatar shadowfax commented on May 21, 2024

That simple patch doesn't seem to mess up the calculations just fixes the tiny issue I talked about. For example, if you have a rating of 0.5 the actual code at GitHub will show "No ratings yet" but half a star is shown. This makes the user think there is an error with the rating system. With that small code change it will show "Terrible". Same thing happens for other half stars.

This doesn't affect the alt tag but the title tag.

For the other issue about half stars with hints I guess it could be as simple as creating an array for hints that is the double of the size (if we got 5 stars enter 10 hints)... Then, instead of converting it to an Int just round it up to the nearest half and multiply the value by 2... then substract one as always...

0.5 * 2 = 1 --> 1 -1 = 0
1 * 2 = 2 --> 2 - 1 = 1
1.5 * 2 = 3 --> 3-1 = 2
...
5*2 = 10 --> 10-1 = 9

And there you go, hints for half stars

Edit: Just make sure the length of the hints is equal to the number of stars * 2 and half stars are enabled before aplying this formulas. Rounding to the nearest half:

nearestHalf = Math.Round(score/0.5) * 0.5;

Maybe it's not a clean hack but certainlly works :)

If you wish to include a js tooltip I would go for an already existing JS library... if the library is there, then show the tooltip, if it's not there then do it as it has been done up until now. The tooltip code could be large and embedding it in raty code would make it useless from other code (ie. Form validation), however using an external library allows the developer to use the tooltips in other places... There could even be a callback for a mouseover event that way the developper may chose what tooltip he wants to use.

The callback method could make a cleaner solution for the hints issue.

If bandwidth is an issue it would also be nice to get sprites for the stars :)

from raty.

wbotelhos avatar wbotelhos commented on May 21, 2024

Good idea shadowfax,

Could you add some specs for that feature and do a pull request?
For minified use http://refresh-sf.com/yui and please, check the option: "Preserve unnecessary semicolons"

And remember that you cant change the original score, you must keep the score/title value into other variable, because the hidden field must keep the original value not the ceil.

from raty.

maddhacker24 avatar maddhacker24 commented on May 21, 2024

I am also in the need of displaying ratings for half stars. I use 5 stars but on a 1-10 scale. I multiply the score behind the scenes. It would be nice to display the number when a user is hovering over 2 1/2 stars. (5) on my scale.

Thanks for a great plugin!

from raty.

maddhacker24 avatar maddhacker24 commented on May 21, 2024

I implemented tooltips/hints for half ratings on my site by added the following lines.

fillStar function:
$star.attr({src: opt.path + icon, title: score*2});

showHalf function:
this.children('img').not('.raty-cancel').eq(Math.ceil(score) - 1).attr({src: opt.path + opt.starHalf, title: score*2});

I simply added the title tag and multiplied the score by 2 to fit my 1-10 scale. Thx!

from raty.

seiyria avatar seiyria commented on May 21, 2024

I also have a need for half-star ratings.. I guess I'll just grab a hack out of this thread though.

from raty.

wbotelhos avatar wbotelhos commented on May 21, 2024

Hi seiyria,

This issue still opend because will code it, but I'm kind busy for now with my startup.
But it will be out soon.

from raty.

wbotelhos avatar wbotelhos commented on May 21, 2024

The version 2.7.0, now supports it.

from raty.

intracer avatar intracer commented on May 21, 2024

It's good that it supports it, but it is good to be documented how it is used as well.

from raty.

Related Issues (20)

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.