Upgrade emoji support (#1482)
* Upgrade emoji deps and move to node_modules Add support for Emoji 3.0 and switch from bower to yarn for managing emoji dependencies. // FREEBIE * Delete old emoji deps // FREEBIE * Don't copy emoji on windows It is no longer necessary since the symlinked image dir is gone. // FREEBIE * Update emoji test // FREEBIE * Fix emoji tests; remove all overrides of emoji-js functions FREEBIE
This commit is contained in:
parent
c6d461c579
commit
4449a5f110
1633 changed files with 222 additions and 4645 deletions
|
@ -7,16 +7,6 @@
|
|||
window.emoji_util = window.emoji_util || {};
|
||||
|
||||
// EmojiConverter overrides
|
||||
EmojiConvertor.prototype.init_env = function() {
|
||||
if (this.inits.env) {
|
||||
return;
|
||||
}
|
||||
this.inits.env = 1;
|
||||
this.include_title = true;
|
||||
this.img_sets.apple.path = 'images/emoji/apple/';
|
||||
this.replace_mode = 'img';
|
||||
};
|
||||
|
||||
EmojiConvertor.prototype.getCountOfAllMatches = function(str, regex) {
|
||||
var match = regex.exec(str);
|
||||
var count = 0;
|
||||
|
@ -64,68 +54,46 @@
|
|||
}
|
||||
};
|
||||
|
||||
// A stripped-down version of the original: https://github.com/WhisperSystems/Signal-Desktop/blob/aed573562018462fbacd8f2f715e9daeddcde0dd/components/emojijs/lib/emoji.js#L323-L396
|
||||
// One primary change - we inject the second parameter as an additional class
|
||||
EmojiConvertor.prototype.replacement = function(idx, sizeClass, actual, wrapper, variation) {
|
||||
var self = this;
|
||||
var img_set = self.img_set;
|
||||
|
||||
var extra = '';
|
||||
var variation_idx = 0;
|
||||
if (typeof variation === 'object') {
|
||||
extra = self.replacement(variation.idx, null, variation.actual, variation.wrapper);
|
||||
variation_idx = idx + '-' + variation.idx;
|
||||
var imgClass = /(<img [^>]+ class="emoji)(")/g;
|
||||
EmojiConvertor.prototype.addClass = function(text, sizeClass) {
|
||||
if (!sizeClass) {
|
||||
return text;
|
||||
}
|
||||
|
||||
var img = self.data[idx][7] || self.img_sets[img_set].path + idx + '.png' + self.img_suffix;
|
||||
var title = self.include_title ? ' title="' + (actual || self.data[idx][3][0]) + '"' : '';
|
||||
|
||||
if (variation_idx && self.variations_data[variation_idx] && self.variations_data[variation_idx][2] && !self.data[idx][7]) {
|
||||
if (self.variations_data[variation_idx][2] & self.img_sets[self.img_set].mask) {
|
||||
img = self.img_sets[self.img_set].path + variation_idx + '.png';
|
||||
extra = '';
|
||||
}
|
||||
}
|
||||
|
||||
return '<img src="' + img + '" class="emoji' + (sizeClass ? ' ' + sizeClass : '') + '"' + title + '/>';
|
||||
};
|
||||
|
||||
// Modeled after the original: https://github.com/WhisperSystems/Signal-Desktop/blob/aed573562018462fbacd8f2f715e9daeddcde0dd/components/emojijs/lib/emoji.js#L265-L286
|
||||
EmojiConvertor.prototype.replace_unified = function(str) {
|
||||
var self = this;
|
||||
self.init_unified();
|
||||
|
||||
var sizeClass = self.getSizeClass(str);
|
||||
|
||||
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, sizeClass, null, null, {
|
||||
idx : idx,
|
||||
actual : p2,
|
||||
wrapper : ':'
|
||||
});
|
||||
}
|
||||
// wrap names in :'s
|
||||
return self.replacement(val, sizeClass, ':' + self.data[val][3][0] + ':');
|
||||
return text.replace(imgClass, function(match, before, after) {
|
||||
return before + ' ' + sizeClass + after;
|
||||
});
|
||||
};
|
||||
|
||||
var imgTitle = /(<img [^>]+ class="emoji[^>]+ title=")([^:">]+)(")/g;
|
||||
EmojiConvertor.prototype.ensureTitlesHaveColons = function(text) {
|
||||
return text.replace(imgTitle, function(match, before, title, after) {
|
||||
return before + ':' + title + ':' + after;
|
||||
});
|
||||
};
|
||||
|
||||
EmojiConvertor.prototype.signalReplace = function(str) {
|
||||
var sizeClass = this.getSizeClass(str);
|
||||
|
||||
var text = this.replace_unified(str);
|
||||
text = this.addClass(text, sizeClass);
|
||||
|
||||
return this.ensureTitlesHaveColons(text);
|
||||
};
|
||||
|
||||
window.emoji = new EmojiConvertor();
|
||||
emoji.init_colons();
|
||||
emoji.img_sets.apple.path = 'node_modules/emoji-datasource-apple/img/apple/64/';
|
||||
emoji.include_title = true;
|
||||
emoji.replace_mode = 'img';
|
||||
emoji.supports_css = false; // needed to avoid spans with background-image
|
||||
|
||||
window.emoji_util.parse = function($el) {
|
||||
if (!$el || !$el.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
$el.html(emoji.replace_unified($el.html()));
|
||||
$el.html(emoji.signalReplace($el.html()));
|
||||
};
|
||||
|
||||
})();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue