"use strict"; ;(function() { var root = this; var previous_emoji = root.EmojiConvertor; /** * @global * @namespace */ var emoji = function(){ var self = this; /** * The set of images to use for graphical emoji. * * @memberof emoji * @type {string} */ self.img_set = 'apple'; /** * Configuration details for different image sets. This includes a path to a directory containing the * individual images (`path`) and a URL to sprite sheets (`sheet`). All of these images can be found * in the [emoji-data repository]{@link https://github.com/iamcal/emoji-data}. Using a CDN for these * is not a bad idea. * * @memberof emoji * @type {object} */ self.img_sets = { 'apple' : {'path' : '/emoji-data/img-apple-64/' , 'sheet' : '/emoji-data/sheet_apple_64.png', 'mask' : 1 }, 'google' : {'path' : '/emoji-data/img-google-64/' , 'sheet' : '/emoji-data/sheet_google_64.png', 'mask' : 2 }, 'twitter' : {'path' : '/emoji-data/img-twitter-64/' , 'sheet' : '/emoji-data/sheet_twitter_64.png', 'mask' : 4 }, 'emojione' : {'path' : '/emoji-data/img-emojione-64/', 'sheet' : '/emoji-data/sheet_emojione_64.png', 'mask' : 8 } }; /** * Use a CSS class instead of specifying a sprite or background image for * the span representing the emoticon. This requires a CSS sheet with * emoticon data-uris. * * @memberof emoji * @type bool * @todo document how to build the CSS stylesheet self requires. */ self.use_css_imgs = false; /** * Instead of replacing emoticons with the appropriate representations, * replace them with their colon string representation. * @memberof emoji * @type bool */ self.colons_mode = false; self.text_mode = false; /** * If true, sets the "title" property on the span or image that gets * inserted for the emoticon. * @memberof emoji * @type bool */ self.include_title = false; /** * If the platform supports native emoticons, use those instead * of the fallbacks. * @memberof emoji * @type bool */ self.allow_native = true; /** * Set to true to use CSS sprites instead of individual images on * platforms that support it. * * @memberof emoji * @type bool */ self.use_sheet = false; /** * * Set to true to avoid black & white native Windows emoji being used. * * @memberof emoji * @type bool */ self.avoid_ms_emoji = true; /** * * Set to true to allow :CAPITALIZATION: * * @memberof emoji * @type bool */ self.allow_caps = false; /** * * Suffix to allow for individual image cache busting * * @memberof emoji * @type string */ self.img_suffix = ''; // Keeps track of what has been initialized. /** @private */ self.inits = {}; self.map = {}; // discover the environment settings self.init_env(); return self; } emoji.prototype.noConflict = function(){ root.EmojiConvertor = previous_emoji; return emoji; } /** * @memberof emoji * @param {string} str A string potentially containing ascii emoticons * (ie. `:)`) * * @returns {string} A new string with all emoticons in `str` * replaced by a representatation that's supported by the current * environtment. */ emoji.prototype.replace_emoticons = function(str){ var self = this; var colonized = self.replace_emoticons_with_colons(str); return self.replace_colons(colonized); }; /** * @memberof emoji * @param {string} str A string potentially containing ascii emoticons * (ie. `:)`) * * @returns {string} A new string with all emoticons in `str` * replaced by their colon string representations (ie. `:smile:`) */ emoji.prototype.replace_emoticons_with_colons = function(str){ var self = this; self.init_emoticons(); var _prev_offset = 0; var emoticons_with_parens = []; var str_replaced = str.replace(self.rx_emoticons, function(m, $1, emoticon, offset){ var prev_offset = _prev_offset; _prev_offset = offset + m.length; var has_open_paren = emoticon.indexOf('(') !== -1; var has_close_paren = emoticon.indexOf(')') !== -1; /* * Track paren-having emoticons for fixing later */ if ((has_open_paren || has_close_paren) && emoticons_with_parens.indexOf(emoticon) == -1) { emoticons_with_parens.push(emoticon); } /* * Look for preceding open paren for emoticons that contain a close paren * This prevents matching "8)" inside "(around 7 - 8)" */ if (has_close_paren && !has_open_paren) { var piece = str.substring(prev_offset, offset); if (piece.indexOf('(') !== -1 && piece.indexOf(')') === -1) return m; } /* * See if we're in a numbered list * This prevents matching "8)" inside "7) foo\n8) bar" */ if (m === '\n8)') { var before_match = str.substring(0, offset); if (/\n?(6\)|7\))/.test(before_match)) return m; } var val = self.data[self.map.emoticons[emoticon]][3][0]; return val ? $1+':'+val+':' : m; }); /* * Come back and fix emoticons we ignored because they were inside parens. * It's useful to do self at the end so we don't get tripped up by other, * normal emoticons */ if (emoticons_with_parens.length) { var escaped_emoticons = emoticons_with_parens.map(self.escape_rx); var parenthetical_rx = new RegExp('(\\(.+)('+escaped_emoticons.join('|')+')(.+\\))', 'g'); str_replaced = str_replaced.replace(parenthetical_rx, function(m, $1, emoticon, $2) { var val = self.data[self.map.emoticons[emoticon]][3][0]; return val ? $1+':'+val+':'+$2 : m; }); } return str_replaced; }; /** * @memberof emoji * @param {string} str A string potentially containing colon string * representations of emoticons (ie. `:smile:`) * * @returns {string} A new string with all colon string emoticons replaced * with the appropriate representation. */ emoji.prototype.replace_colons = function(str){ var self = this; self.init_colons(); return str.replace(self.rx_colons, function(m){ var idx = m.substr(1, m.length-2); if (self.allow_caps) idx = idx.toLowerCase(); // special case - an emoji with a skintone modified if (idx.indexOf('::skin-tone-') > -1){ var skin_tone = idx.substr(-1, 1); var skin_idx = 'skin-tone-'+skin_tone; var skin_val = self.map.colons[skin_idx]; idx = idx.substr(0, idx.length - 13); var val = self.map.colons[idx]; if (val){ return self.replacement(val, idx, ':', { 'idx' : skin_val, 'actual' : skin_idx, 'wrapper' : ':' }); }else{ return ':' + idx + ':' + self.replacement(skin_val, skin_idx, ':'); } }else{ var val = self.map.colons[idx]; return val ? self.replacement(val, idx, ':') : m; } }); }; /** * @memberof emoji * @param {string} str A string potentially containing unified unicode * emoticons. (ie. 😄) * * @returns {string} A new string with all unicode emoticons replaced with * the appropriate representation for the current environment. */ emoji.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 : '' }); } return self.replacement(val); }); }; emoji.prototype.addAliases = function(map){ var self = this; self.init_colons(); for (var i in map){ self.map.colons[i] = map[i]; } }; emoji.prototype.removeAliases = function(list){ var self = this; for (var i=0; i'+text+''+extra; }else if (self.use_css_imgs){ return ''+text+''+extra; }else{ return ''+text+''+extra; } } return ''+extra; }; // Initializes the text emoticon data /** @private */ emoji.prototype.init_emoticons = function(){ var self = this; if (self.inits.emoticons) return; self.init_colons(); // we require this for the emoticons map self.inits.emoticons = 1; var a = []; self.map.emoticons = {}; for (var i in self.emoticons_data){ // because we never see some characters in our text except as entities, we must do some replacing var emoticon = i.replace(/\&/g, '&').replace(/\/g, '>'); if (!self.map.colons[self.emoticons_data[i]]) continue; self.map.emoticons[emoticon] = self.map.colons[self.emoticons_data[i]]; a.push(self.escape_rx(emoticon)); } self.rx_emoticons = new RegExp(('(^|\\s)('+a.join('|')+')(?=$|[\\s|\\?\\.,!])'), 'g'); }; // Initializes the colon string data /** @private */ emoji.prototype.init_colons = function(){ var self = this; if (self.inits.colons) return; self.inits.colons = 1; self.rx_colons = new RegExp('\:[a-zA-Z0-9-_+]+\:(\:skin-tone-[2-6]\:)?', 'g'); self.map.colons = {}; for (var i in self.data){ for (var j=0; j":"laughing", ":->":"laughing", ";)":"wink", ";-)":"wink", "8)":"sunglasses", ":|":"neutral_face", ":-|":"neutral_face", ":\\":"confused", ":-\\":"confused", ":\/":"confused", ":-\/":"confused", ":p":"stuck_out_tongue", ":-p":"stuck_out_tongue", ":P":"stuck_out_tongue", ":-P":"stuck_out_tongue", ":b":"stuck_out_tongue", ":-b":"stuck_out_tongue", ";p":"stuck_out_tongue_winking_eye", ";-p":"stuck_out_tongue_winking_eye", ";b":"stuck_out_tongue_winking_eye", ";-b":"stuck_out_tongue_winking_eye", ";P":"stuck_out_tongue_winking_eye", ";-P":"stuck_out_tongue_winking_eye", "):":"disappointed", ":(":"disappointed", ":-(":"disappointed", ">:(":"angry", ">:-(":"angry", ":'(":"cry", "D:":"anguished", ":o":"open_mouth", ":-o":"open_mouth", ":O":"open_mouth", ":-O":"open_mouth", ":)":"slightly_smiling_face", "(:":"slightly_smiling_face", ":-)":"slightly_smiling_face" }; /** @private */ emoji.prototype.variations_data = { "261d-1f3fb":[1,11,13], "261d-1f3fc":[1,12,13], "261d-1f3fd":[1,13,13], "261d-1f3fe":[1,14,13], "261d-1f3ff":[1,15,13], "26f9-1f3fb":[2,39,13], "26f9-1f3fc":[2,40,13], "26f9-1f3fd":[3,0,13], "26f9-1f3fe":[3,1,13], "26f9-1f3ff":[3,2,13], "270a-1f3fb":[3,10,13], "270a-1f3fc":[3,11,13], "270a-1f3fd":[3,12,13], "270a-1f3fe":[3,13,13], "270a-1f3ff":[3,14,13], "270b-1f3fb":[3,16,13], "270b-1f3fc":[3,17,13], "270b-1f3fd":[3,18,13], "270b-1f3fe":[3,19,13], "270b-1f3ff":[3,20,13], "270c-1f3fb":[3,22,13], "270c-1f3fc":[3,23,13], "270c-1f3fd":[3,24,13], "270c-1f3fe":[3,25,13], "270c-1f3ff":[3,26,13], "270d-1f3fb":[3,28,13], "270d-1f3fc":[3,29,13], "270d-1f3fd":[3,30,13], "270d-1f3fe":[3,31,13], "270d-1f3ff":[3,32,13], "1f385-1f3fb":[8,30,13], "1f385-1f3fc":[8,31,13], "1f385-1f3fd":[8,32,13], "1f385-1f3fe":[8,33,13], "1f385-1f3ff":[8,34,13], "1f3c3-1f3fb":[10,10,13], "1f3c3-1f3fc":[10,11,13], "1f3c3-1f3fd":[10,12,13], "1f3c3-1f3fe":[10,13,13], "1f3c3-1f3ff":[10,14,13], "1f3c4-1f3fb":[10,16,13], "1f3c4-1f3fc":[10,17,13], "1f3c4-1f3fd":[10,18,13], "1f3c4-1f3fe":[10,19,13], "1f3c4-1f3ff":[10,20,13], "1f3ca-1f3fb":[10,27,13], "1f3ca-1f3fc":[10,28,13], "1f3ca-1f3fd":[10,29,13], "1f3ca-1f3fe":[10,30,13], "1f3ca-1f3ff":[10,31,13], "1f3cb-1f3fb":[10,33,13], "1f3cb-1f3fc":[10,34,13], "1f3cb-1f3fd":[10,35,13], "1f3cb-1f3fe":[10,36,13], "1f3cb-1f3ff":[10,37,13], "1f442-1f3fb":[13,31,13], "1f442-1f3fc":[13,32,13], "1f442-1f3fd":[13,33,13], "1f442-1f3fe":[13,34,13], "1f442-1f3ff":[13,35,13], "1f443-1f3fb":[13,37,13], "1f443-1f3fc":[13,38,13], "1f443-1f3fd":[13,39,13], "1f443-1f3fe":[13,40,13], "1f443-1f3ff":[14,0,13], "1f446-1f3fb":[14,4,13], "1f446-1f3fc":[14,5,13], "1f446-1f3fd":[14,6,13], "1f446-1f3fe":[14,7,13], "1f446-1f3ff":[14,8,13], "1f447-1f3fb":[14,10,13], "1f447-1f3fc":[14,11,13], "1f447-1f3fd":[14,12,13], "1f447-1f3fe":[14,13,13], "1f447-1f3ff":[14,14,13], "1f448-1f3fb":[14,16,13], "1f448-1f3fc":[14,17,13], "1f448-1f3fd":[14,18,13], "1f448-1f3fe":[14,19,13], "1f448-1f3ff":[14,20,13], "1f449-1f3fb":[14,22,13], "1f449-1f3fc":[14,23,13], "1f449-1f3fd":[14,24,13], "1f449-1f3fe":[14,25,13], "1f449-1f3ff":[14,26,13], "1f44a-1f3fb":[14,28,13], "1f44a-1f3fc":[14,29,13], "1f44a-1f3fd":[14,30,13], "1f44a-1f3fe":[14,31,13], "1f44a-1f3ff":[14,32,13], "1f44b-1f3fb":[14,34,13], "1f44b-1f3fc":[14,35,13], "1f44b-1f3fd":[14,36,13], "1f44b-1f3fe":[14,37,13], "1f44b-1f3ff":[14,38,13], "1f44c-1f3fb":[14,40,13], "1f44c-1f3fc":[15,0,13], "1f44c-1f3fd":[15,1,13], "1f44c-1f3fe":[15,2,13], "1f44c-1f3ff":[15,3,13], "1f44d-1f3fb":[15,5,13], "1f44d-1f3fc":[15,6,13], "1f44d-1f3fd":[15,7,13], "1f44d-1f3fe":[15,8,13], "1f44d-1f3ff":[15,9,13], "1f44e-1f3fb":[15,11,13], "1f44e-1f3fc":[15,12,13], "1f44e-1f3fd":[15,13,13], "1f44e-1f3fe":[15,14,13], "1f44e-1f3ff":[15,15,13], "1f44f-1f3fb":[15,17,13], "1f44f-1f3fc":[15,18,13], "1f44f-1f3fd":[15,19,13], "1f44f-1f3fe":[15,20,13], "1f44f-1f3ff":[15,21,13], "1f450-1f3fb":[15,23,13], "1f450-1f3fc":[15,24,13], "1f450-1f3fd":[15,25,13], "1f450-1f3fe":[15,26,13], "1f450-1f3ff":[15,27,13], "1f466-1f3fb":[16,9,13], "1f466-1f3fc":[16,10,13], "1f466-1f3fd":[16,11,13], "1f466-1f3fe":[16,12,13], "1f466-1f3ff":[16,13,13], "1f467-1f3fb":[16,15,13], "1f467-1f3fc":[16,16,13], "1f467-1f3fd":[16,17,13], "1f467-1f3fe":[16,18,13], "1f467-1f3ff":[16,19,13], "1f468-1f3fb":[16,21,13], "1f468-1f3fc":[16,22,13], "1f468-1f3fd":[16,23,13], "1f468-1f3fe":[16,24,13], "1f468-1f3ff":[16,25,13], "1f469-1f3fb":[16,27,13], "1f469-1f3fc":[16,28,13], "1f469-1f3fd":[16,29,13], "1f469-1f3fe":[16,30,13], "1f469-1f3ff":[16,31,13], "1f46e-1f3fb":[16,37,13], "1f46e-1f3fc":[16,38,13], "1f46e-1f3fd":[16,39,13], "1f46e-1f3fe":[16,40,13], "1f46e-1f3ff":[17,0,13], "1f470-1f3fb":[17,3,13], "1f470-1f3fc":[17,4,13], "1f470-1f3fd":[17,5,13], "1f470-1f3fe":[17,6,13], "1f470-1f3ff":[17,7,13], "1f471-1f3fb":[17,9,13], "1f471-1f3fc":[17,10,13], "1f471-1f3fd":[17,11,13], "1f471-1f3fe":[17,12,13], "1f471-1f3ff":[17,13,13], "1f472-1f3fb":[17,15,13], "1f472-1f3fc":[17,16,13], "1f472-1f3fd":[17,17,13], "1f472-1f3fe":[17,18,13], "1f472-1f3ff":[17,19,13], "1f473-1f3fb":[17,21,13], "1f473-1f3fc":[17,22,13], "1f473-1f3fd":[17,23,13], "1f473-1f3fe":[17,24,13], "1f473-1f3ff":[17,25,13], "1f474-1f3fb":[17,27,13], "1f474-1f3fc":[17,28,13], "1f474-1f3fd":[17,29,13], "1f474-1f3fe":[17,30,13], "1f474-1f3ff":[17,31,13], "1f475-1f3fb":[17,33,13], "1f475-1f3fc":[17,34,13], "1f475-1f3fd":[17,35,13], "1f475-1f3fe":[17,36,13], "1f475-1f3ff":[17,37,13], "1f476-1f3fb":[17,39,13], "1f476-1f3fc":[17,40,13], "1f476-1f3fd":[18,0,13], "1f476-1f3fe":[18,1,13], "1f476-1f3ff":[18,2,13], "1f477-1f3fb":[18,4,13], "1f477-1f3fc":[18,5,13], "1f477-1f3fd":[18,6,13], "1f477-1f3fe":[18,7,13], "1f477-1f3ff":[18,8,13], "1f478-1f3fb":[18,10,13], "1f478-1f3fc":[18,11,13], "1f478-1f3fd":[18,12,13], "1f478-1f3fe":[18,13,13], "1f478-1f3ff":[18,14,13], "1f47c-1f3fb":[18,19,13], "1f47c-1f3fc":[18,20,13], "1f47c-1f3fd":[18,21,13], "1f47c-1f3fe":[18,22,13], "1f47c-1f3ff":[18,23,13], "1f481-1f3fb":[18,29,13], "1f481-1f3fc":[18,30,13], "1f481-1f3fd":[18,31,13], "1f481-1f3fe":[18,32,13], "1f481-1f3ff":[18,33,13], "1f482-1f3fb":[18,35,13], "1f482-1f3fc":[18,36,13], "1f482-1f3fd":[18,37,13], "1f482-1f3fe":[18,38,13], "1f482-1f3ff":[18,39,13], "1f483-1f3fb":[19,0,13], "1f483-1f3fc":[19,1,13], "1f483-1f3fd":[19,2,13], "1f483-1f3fe":[19,3,13], "1f483-1f3ff":[19,4,13], "1f485-1f3fb":[19,7,13], "1f485-1f3fc":[19,8,13], "1f485-1f3fd":[19,9,13], "1f485-1f3fe":[19,10,13], "1f485-1f3ff":[19,11,13], "1f486-1f3fb":[19,13,13], "1f486-1f3fc":[19,14,13], "1f486-1f3fd":[19,15,13], "1f486-1f3fe":[19,16,13], "1f486-1f3ff":[19,17,13], "1f487-1f3fb":[19,19,13], "1f487-1f3fc":[19,20,13], "1f487-1f3fd":[19,21,13], "1f487-1f3fe":[19,22,13], "1f487-1f3ff":[19,23,13], "1f4aa-1f3fb":[20,18,13], "1f4aa-1f3fc":[20,19,13], "1f4aa-1f3fd":[20,20,13], "1f4aa-1f3fe":[20,21,13], "1f4aa-1f3ff":[20,22,13], "1f575-1f3fb":[24,40,9], "1f575-1f3fc":[25,0,9], "1f575-1f3fd":[25,1,9], "1f575-1f3fe":[25,2,9], "1f575-1f3ff":[25,3,9], "1f590-1f3fb":[25,14,13], "1f590-1f3fc":[25,15,13], "1f590-1f3fd":[25,16,13], "1f590-1f3fe":[25,17,13], "1f590-1f3ff":[25,18,13], "1f595-1f3fb":[25,20,13], "1f595-1f3fc":[25,21,13], "1f595-1f3fd":[25,22,13], "1f595-1f3fe":[25,23,13], "1f595-1f3ff":[25,24,13], "1f596-1f3fb":[25,26,13], "1f596-1f3fc":[25,27,13], "1f596-1f3fd":[25,28,13], "1f596-1f3fe":[25,29,13], "1f596-1f3ff":[25,30,13], "1f645-1f3fb":[28,3,13], "1f645-1f3fc":[28,4,13], "1f645-1f3fd":[28,5,13], "1f645-1f3fe":[28,6,13], "1f645-1f3ff":[28,7,13], "1f646-1f3fb":[28,9,13], "1f646-1f3fc":[28,10,13], "1f646-1f3fd":[28,11,13], "1f646-1f3fe":[28,12,13], "1f646-1f3ff":[28,13,13], "1f647-1f3fb":[28,15,13], "1f647-1f3fc":[28,16,13], "1f647-1f3fd":[28,17,13], "1f647-1f3fe":[28,18,13], "1f647-1f3ff":[28,19,13], "1f64b-1f3fb":[28,24,13], "1f64b-1f3fc":[28,25,13], "1f64b-1f3fd":[28,26,13], "1f64b-1f3fe":[28,27,13], "1f64b-1f3ff":[28,28,13], "1f64c-1f3fb":[28,30,13], "1f64c-1f3fc":[28,31,13], "1f64c-1f3fd":[28,32,13], "1f64c-1f3fe":[28,33,13], "1f64c-1f3ff":[28,34,13], "1f64d-1f3fb":[28,36,13], "1f64d-1f3fc":[28,37,13], "1f64d-1f3fd":[28,38,13], "1f64d-1f3fe":[28,39,13], "1f64d-1f3ff":[28,40,13], "1f64e-1f3fb":[29,1,13], "1f64e-1f3fc":[29,2,13], "1f64e-1f3fd":[29,3,13], "1f64e-1f3fe":[29,4,13], "1f64e-1f3ff":[29,5,13], "1f64f-1f3fb":[29,7,13], "1f64f-1f3fc":[29,8,13], "1f64f-1f3fd":[29,9,13], "1f64f-1f3fe":[29,10,13], "1f64f-1f3ff":[29,11,13], "1f6a3-1f3fb":[30,7,13], "1f6a3-1f3fc":[30,8,13], "1f6a3-1f3fd":[30,9,13], "1f6a3-1f3fe":[30,10,13], "1f6a3-1f3ff":[30,11,13], "1f6b4-1f3fb":[30,29,13], "1f6b4-1f3fc":[30,30,13], "1f6b4-1f3fd":[30,31,13], "1f6b4-1f3fe":[30,32,13], "1f6b4-1f3ff":[30,33,13], "1f6b5-1f3fb":[30,35,13], "1f6b5-1f3fc":[30,36,13], "1f6b5-1f3fd":[30,37,13], "1f6b5-1f3fe":[30,38,13], "1f6b5-1f3ff":[30,39,13], "1f6b6-1f3fb":[31,0,13], "1f6b6-1f3fc":[31,1,13], "1f6b6-1f3fd":[31,2,13], "1f6b6-1f3fe":[31,3,13], "1f6b6-1f3ff":[31,4,13], "1f6c0-1f3fb":[31,15,13], "1f6c0-1f3fc":[31,16,13], "1f6c0-1f3fd":[31,17,13], "1f6c0-1f3fe":[31,18,13], "1f6c0-1f3ff":[31,19,13], "1f918-1f3fb":[32,10,13], "1f918-1f3fc":[32,11,13], "1f918-1f3fd":[32,12,13], "1f918-1f3fe":[32,13,13], "1f918-1f3ff":[32,14,13] }; // export if (typeof exports !== 'undefined'){ if (typeof module !== 'undefined' && module.exports){ exports = module.exports = emoji; } exports.EmojiConvertor = emoji; }else if (typeof define === 'function' && define.amd){ define(function() { return emoji; }) }else{ root.EmojiConvertor = emoji; } }).call(function(){ return this || (typeof window !== 'undefined' ? window : global); }());