From 1c891427525f7850e44754a2f394f25a4535d045 Mon Sep 17 00:00:00 2001 From: lilia Date: Thu, 1 Sep 2016 12:21:23 -0700 Subject: [PATCH] Customize emoji conversion Use image tags with :emoji: in a title attribute for an optimal copy/paste ux. // FREEBIE --- js/emoji_util.js | 32 +++++++++++++++++++++++++------- stylesheets/_global.scss | 7 ------- stylesheets/manifest.css | 6 ------ 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/js/emoji_util.js b/js/emoji_util.js index d27efa9ec52..b9718338e57 100644 --- a/js/emoji_util.js +++ b/js/emoji_util.js @@ -6,20 +6,38 @@ 'use strict'; window.emoji_util = window.emoji_util || {}; - // The default version of this function has issues initing from the - // background page. Since we only support one environment, we can - // preconfigure it here. + // EmojiConverter overrides EmojiConvertor.prototype.init_env = function() { if (this.inits.env) { return; } - this.inits.env = 1; + this.inits.env = 1; this.include_title = true; this.img_sets.apple.path = 'images/emoji/apple/'; - - this.img_path = 'images/emoji/unicode/'; this.replace_mode = 'img'; - this.supports_css = true; + }; + EmojiConvertor.prototype.replace_unified = function(str) { + var self = this; + self.init_unified(); + return str.replace(self.rx_unified, function(m, p1, p2) { + var val = self.map.unified[p1]; + if (!val) { return m; } + var idx = null; + if (p2 == '\uD83C\uDFFB') { idx = '1f3fb'; } + if (p2 == '\uD83C\uDFFC') { idx = '1f3fc'; } + if (p2 == '\uD83C\uDFFD') { idx = '1f3fd'; } + if (p2 == '\uD83C\uDFFE') { idx = '1f3fe'; } + if (p2 == '\uD83C\uDFFF') { idx = '1f3ff'; } + if (idx) { + return self.replacement(val, null, null, { + idx : idx, + actual : p2, + wrapper : ':' + }); + } + // wrap names in :'s + return self.replacement(val, ':' + self.data[val][3][0] + ':'); + }); }; window.emoji = new EmojiConvertor(); emoji.init_colons(); diff --git a/stylesheets/_global.scss b/stylesheets/_global.scss index 01700196009..ed443646693 100644 --- a/stylesheets/_global.scss +++ b/stylesheets/_global.scss @@ -183,13 +183,6 @@ button.back { outline: solid 1px #2090ea; } -img.emoji { - height: 1em; - width: 1em; - margin: 0 .05em 0 .1em; - vertical-align: -0.1em; -} - $avatar-size: 44px; .avatar { diff --git a/stylesheets/manifest.css b/stylesheets/manifest.css index 7736b959bbe..dc28950a62d 100644 --- a/stylesheets/manifest.css +++ b/stylesheets/manifest.css @@ -180,12 +180,6 @@ button.back { .dropoff { outline: solid 1px #2090ea; } -img.emoji { - height: 1em; - width: 1em; - margin: 0 .05em 0 .1em; - vertical-align: -0.1em; } - .avatar { display: inline-block; height: 44px;