Last active
August 29, 2015 14:04
-
-
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
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
// 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