Last active
February 13, 2019 15:42
-
-
Save mdipierro/f221957e002baa014c9a 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('input.rating,input[name*="rating"]').each(function(){ | |
var span = jQuery('<span style="white-space:nowrap"><span class="rate0">◎</span><span class="rate1">☆</span><span class="rate2">☆</span><span class="rate3">☆</span><span class="rate4">☆</span><span class="rate5">☆</span></span>'); | |
var self = jQuery(this).hide().after(span); | |
var fill_stars = function() { | |
var k = parseInt(self.val()) || 0; | |
for(var i=1; i<6; i++) span.find('.rate'+i).html((i<=k)?'★':'☆'); | |
}; | |
for(var k=0; k<6; k++) (function(k){ | |
span.find('.rate'+k).mouseover(function(){ | |
for(var i=1; i<6; i++) span.find('.rate'+i).html((i<=k)?'★':'☆'); | |
}).click(function(){self.val(k);fill_stars();}); | |
})(k); | |
span.mouseout(fill_stars); | |
fill_stars(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have been very unsatisfied with existing star rating plugins. First, they are too complex. Second, they require dedicated fonts/images while all the necessary symbols are already in unicode. So I made this.
Just download it as star.rating.js and include it:
and all the fields with a name containing the word "rating" or input fields having a class "rating" will be represented by a star 1-5 widget.