Skip to content

Instantly share code, notes, and snippets.

Created January 14, 2014 23:02
Show Gist options
  • Save anonymous/8427663 to your computer and use it in GitHub Desktop.
Save anonymous/8427663 to your computer and use it in GitHub Desktop.
Gist created from Brackets
/*
* A simple plugin for easier star rating markup using FontAwesome.io
* https://github.com/auxiliary/enrate
*/
function enrate()
{
$("[class^=enrate-]").each(function(){
var parsed_data = this.className.split(' ')[0].match(/enrate-(\d)-([a-z])-(\d)/);
var num = parsed_data[1];
var has_half = parsed_data[2] == "h" ? true : false;
var total = parsed_data[3];
var replacement = "";
if (has_half == true)
{
total--;
}
for(var i = 0; i < num; i++)
{
replacement += "<i class='fa fa-star'></i>";
}
if (has_half == true)
{
replacement += "<i class='fa fa-star-half-o'></i>";
}
for(var i = 0; i < total - num; i++)
{
replacement += "<i class='fa fa-star-o'></i>";
}
$(this).replaceWith(replacement);
});
}
$(document).ready(function(){
enrate();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment