Created
April 26, 2019 14:51
-
-
Save prethiee/8ef296f6eef73a901fd2ee36927b59e4 to your computer and use it in GitHub Desktop.
Code to calculate the five-star rating average and display them
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
/** | |
* Star Rating Average | |
*/ | |
$(document).ready(function() { | |
if ($("select[name=vote]").hasClass("ajax-processed")) { | |
var avgStar = $("#fivestar-custom-widget").find(".star-summary.star-summary-avaerage-count").find(".average-rating").find("span").text(); | |
$("#star-custom-widget").find(".star-widget.clearfix.star-widget-5").addClass(".star-widget-static"); | |
var starNumber = avgStar * 10; | |
var starColor = starNumber % 10; | |
if (starColor != null) { | |
var percent = starColor * 10; | |
var clrPercent = percent + '%'; | |
var splitRes = avgStar.split("."); | |
var fullColor = splitRes[0]; | |
$("div[class^='star star-']:eq(" + fullColor + ")").find('a').addClass("on"); | |
$("div[class^='star star-']:eq(" + fullColor + ")").find('a').css('width', clrPercent); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment