Skip to content

Instantly share code, notes, and snippets.

@thibaultcha
Created September 23, 2013 08:41
Show Gist options
  • Save thibaultcha/6667985 to your computer and use it in GitHub Desktop.
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/
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