This script works with the SymbolSet semantic symbol font to utilize their star symbol to display ratings while keeping an even more accessible text in the markup for machines and humans on old browsers.
It works best in conjunction with Modernizr. It checks for Modernizr, and if it finds it, will stop the script from running in an outdated browser that doesn't support @font-face.
Reference the demo for an example of this script working with Schema.org microdata.
- Load format_symbolset_stars.js.
- Add your readable rating to any element. It must start with the number to be parsed, the extra text will be discarded.
- Add the class "ss-star_fade" or "ss-star_half" to that element depending on your desired output (see examples below).
- Call the function format_symbolset_stars() after the document is loaded.
The markup...
<span class="ss-star_fade">4 stars</span>
Is converted by the browser to...
<span class="ss-star_fade">star star star star <span class="unfilled">star </span></span>
The markup...
<span class="ss-star_half">4.5 stars</span>
Is converted by the browser to...
<span class="ss-star_half">star star star star halfstar</span>
This script was developed without any involvement from SymbolSet, but I hope they think it's great!
The demo is just to show how the script modifies the HTML, you'll need to purchase SymbolSet Standard and load it in yourself to get the full effect :-)
It uses the getElementsByClassName method, which is not available in IE8 and below.
If you've got some ideas on how to make this script better, email me at [email protected] or send me a pull request.
Links:
This script is released under the MIT License.