Created
September 23, 2013 08:41
-
-
Save thibaultcha/6667985 to your computer and use it in GitHub Desktop.
Converts strings as ':heart:' to <span> elements with the equivalent emoji image in background. See http://www.emoji-cheat-sheet.com/
This file contains hidden or 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
function emojify (domElement, ressource, size) { | |
var element = document.getElementById(domElement) | |
var matching = element.innerHTML.match(/:[a-z0-9+_-]+:/g) | |
for (var i = matching.length - 1; i >= 0; i--) { | |
element.innerHTML = element.innerHTML.replace(matching[i], '<span style="display:inline-block;background-image:url('+ressource+matching[i].slice(1, matching[i].length - 1)+'.png);background-size:'+size+'px;height:'+size+'px;width:'+size+'px;vertical-align:-10%;"></span>') | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment