Skip to content

Instantly share code, notes, and snippets.

@isotrope
Last active August 29, 2015 14:04
Show Gist options
  • Save isotrope/de90b8c499f58ddd4230 to your computer and use it in GitHub Desktop.
Save isotrope/de90b8c499f58ddd4230 to your computer and use it in GitHub Desktop.
Grabs all the .fa and tries to extract the Unicode character for the :before pseudo-class
// Grabs all the .fa and tries to extract the Unicode character for the :before pseudo-class
// Based on http://fontawesome.io/icons/
// Inspired by c.bavota https://github.com/cbavota
// window.getComputedStyle trickery thanks to http://stackoverflow.com/a/21709814/636709
// Unicode conversion via http://stackoverflow.com/a/21014576/636709
var strAll = '$font_awesome_icons = array(' + "\n";
$('.fontawesome-icon-list').find('.fa').each(function () {
var $this = $(this),
arrClasses = this.className.split(/\s+/),
unicodeValue = window.getComputedStyle(this, ':before')
.getPropertyValue('content')[1].toUnicode();
strAll += "\t'" + arrClasses[1] + "' => '" + unicodeValue + "',\n";
});
strAll += ');';
console.log(strAll);
String.prototype.toUnicode = function () {
var result = "";
for (var i = 0; i < this.length; i++) {
result += "\\u" + ("000" + this[i].charCodeAt(0).toString(16)).substr(-4);
}
return result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment