Skip to content

Instantly share code, notes, and snippets.

@prethiee
Created April 26, 2019 14:51
Show Gist options
  • Save prethiee/8ef296f6eef73a901fd2ee36927b59e4 to your computer and use it in GitHub Desktop.
Save prethiee/8ef296f6eef73a901fd2ee36927b59e4 to your computer and use it in GitHub Desktop.
Code to calculate the five-star rating average and display them
/**
* 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