diff --git a/background.html b/background.html index 4dc616e9..c2a798c5 100644 --- a/background.html +++ b/background.html @@ -363,6 +363,7 @@ + diff --git a/js/emoji_util.js b/js/emoji_util.js new file mode 100644 index 00000000..8224270b --- /dev/null +++ b/js/emoji_util.js @@ -0,0 +1,32 @@ +/* + * vim: ts=4:sw=4:expandtab + */ + +;(function() { + 'use strict'; + + window.emoji_util = window.emoji_util || {}; + + // Map from single unicode emoji strings to "colon" strings + var unicode_emoji_map; + var initialized = false; + + function initialize() { + if (initialized) { + return; + } + initialized = true; + unicode_emoji_map = {}; + $.each(emoji.data, function(_, data) { + if (data[0] && data[0][0] && data[3] && data[3].length > 0) { + unicode_emoji_map[data[0][0]] = data[3][0]; + } + }); + } + + window.emoji_util.get_colon_from_unicode = function(emoji_string) { + initialize(); + return unicode_emoji_map[emoji_string]; + }; + +})(); diff --git a/js/views/message_view.js b/js/views/message_view.js index fb9968d2..f9a104ea 100644 --- a/js/views/message_view.js +++ b/js/views/message_view.js @@ -87,7 +87,19 @@ this.renderControl(); - twemoji.parse(this.el, { base: '/images/twemoji/', size: 16 }); + twemoji.parse(this.el, { + attributes: function(icon, variant) { + var colon = emoji_util.get_colon_from_unicode(icon); + console.log("colon: ", colon); + if (colon) { + return {title: ":" + colon + ":"}; + } else { + return {}; + } + }, + base: '/images/twemoji/', + size: 16 + }); var content = this.$('.content'); var escaped = content.html();