Created
March 8, 2012 17:04
-
-
Save pnomolos/2002091 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery.fn.ratingSelector = function(){ | |
return $(this).each(function(){ | |
var stars_element = null, | |
rating_element = null; | |
stars_element = $(this).find('span.rating_stars'); | |
rating_element = $(this).find('input'); | |
if (stars_element.size() && rating_element.size()) | |
stars_element.click(function(ev){ | |
var stars_coords = stars_element.offset(); | |
var offset = ev.pageX - stars_coords.left; | |
var rating = Math.ceil(offset/(stars_element.width()/5)); | |
stars_element.attr('class', 'rating_stars rating_'+rating); | |
rating_element.val(rating); | |
}) | |
}) | |
} | |
$('#rating_selector').ratingSelector(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment