Edit File by line
/home/barbar84/public_h.../wp-inclu.../js
File: twemoji.js
/*jslint indent: 2, browser: true, bitwise: true, plusplus: true */
[0] Fix | Delete
var twemoji = (function (
[1] Fix | Delete
/*! Copyright Twitter Inc. and other contributors. Licensed under MIT *//*
[2] Fix | Delete
https://github.com/twitter/twemoji/blob/gh-pages/LICENSE
[3] Fix | Delete
*/
[4] Fix | Delete
[5] Fix | Delete
// WARNING: this file is generated automatically via
[6] Fix | Delete
// `node scripts/build.js`
[7] Fix | Delete
// please update its `createTwemoji` function
[8] Fix | Delete
// at the bottom of the same file instead.
[9] Fix | Delete
[10] Fix | Delete
) {
[11] Fix | Delete
'use strict';
[12] Fix | Delete
[13] Fix | Delete
/*jshint maxparams:4 */
[14] Fix | Delete
[15] Fix | Delete
var
[16] Fix | Delete
// the exported module object
[17] Fix | Delete
twemoji = {
[18] Fix | Delete
[19] Fix | Delete
[20] Fix | Delete
/////////////////////////
[21] Fix | Delete
// properties //
[22] Fix | Delete
/////////////////////////
[23] Fix | Delete
[24] Fix | Delete
// default assets url, by default will be Twitter Inc. CDN
[25] Fix | Delete
base: 'https://twemoji.maxcdn.com/v/13.0.1/',
[26] Fix | Delete
[27] Fix | Delete
// default assets file extensions, by default '.png'
[28] Fix | Delete
ext: '.png',
[29] Fix | Delete
[30] Fix | Delete
// default assets/folder size, by default "72x72"
[31] Fix | Delete
// available via Twitter CDN: 72
[32] Fix | Delete
size: '72x72',
[33] Fix | Delete
[34] Fix | Delete
// default class name, by default 'emoji'
[35] Fix | Delete
className: 'emoji',
[36] Fix | Delete
[37] Fix | Delete
// basic utilities / helpers to convert code points
[38] Fix | Delete
// to JavaScript surrogates and vice versa
[39] Fix | Delete
convert: {
[40] Fix | Delete
[41] Fix | Delete
/**
[42] Fix | Delete
* Given an HEX codepoint, returns UTF16 surrogate pairs.
[43] Fix | Delete
*
[44] Fix | Delete
* @param string generic codepoint, i.e. '1F4A9'
[45] Fix | Delete
* @return string codepoint transformed into utf16 surrogates pair,
[46] Fix | Delete
* i.e. \uD83D\uDCA9
[47] Fix | Delete
*
[48] Fix | Delete
* @example
[49] Fix | Delete
* twemoji.convert.fromCodePoint('1f1e8');
[50] Fix | Delete
* // "\ud83c\udde8"
[51] Fix | Delete
*
[52] Fix | Delete
* '1f1e8-1f1f3'.split('-').map(twemoji.convert.fromCodePoint).join('')
[53] Fix | Delete
* // "\ud83c\udde8\ud83c\uddf3"
[54] Fix | Delete
*/
[55] Fix | Delete
fromCodePoint: fromCodePoint,
[56] Fix | Delete
[57] Fix | Delete
/**
[58] Fix | Delete
* Given UTF16 surrogate pairs, returns the equivalent HEX codepoint.
[59] Fix | Delete
*
[60] Fix | Delete
* @param string generic utf16 surrogates pair, i.e. \uD83D\uDCA9
[61] Fix | Delete
* @param string optional separator for double code points, default='-'
[62] Fix | Delete
* @return string utf16 transformed into codepoint, i.e. '1F4A9'
[63] Fix | Delete
*
[64] Fix | Delete
* @example
[65] Fix | Delete
* twemoji.convert.toCodePoint('\ud83c\udde8\ud83c\uddf3');
[66] Fix | Delete
* // "1f1e8-1f1f3"
[67] Fix | Delete
*
[68] Fix | Delete
* twemoji.convert.toCodePoint('\ud83c\udde8\ud83c\uddf3', '~');
[69] Fix | Delete
* // "1f1e8~1f1f3"
[70] Fix | Delete
*/
[71] Fix | Delete
toCodePoint: toCodePoint
[72] Fix | Delete
},
[73] Fix | Delete
[74] Fix | Delete
[75] Fix | Delete
/////////////////////////
[76] Fix | Delete
// methods //
[77] Fix | Delete
/////////////////////////
[78] Fix | Delete
[79] Fix | Delete
/**
[80] Fix | Delete
* User first: used to remove missing images
[81] Fix | Delete
* preserving the original text intent when
[82] Fix | Delete
* a fallback for network problems is desired.
[83] Fix | Delete
* Automatically added to Image nodes via DOM
[84] Fix | Delete
* It could be recycled for string operations via:
[85] Fix | Delete
* $('img.emoji').on('error', twemoji.onerror)
[86] Fix | Delete
*/
[87] Fix | Delete
onerror: function onerror() {
[88] Fix | Delete
if (this.parentNode) {
[89] Fix | Delete
this.parentNode.replaceChild(createText(this.alt, false), this);
[90] Fix | Delete
}
[91] Fix | Delete
},
[92] Fix | Delete
[93] Fix | Delete
/**
[94] Fix | Delete
* Main method/logic to generate either <img> tags or HTMLImage nodes.
[95] Fix | Delete
* "emojify" a generic text or DOM Element.
[96] Fix | Delete
*
[97] Fix | Delete
* @overloads
[98] Fix | Delete
*
[99] Fix | Delete
* String replacement for `innerHTML` or server side operations
[100] Fix | Delete
* twemoji.parse(string);
[101] Fix | Delete
* twemoji.parse(string, Function);
[102] Fix | Delete
* twemoji.parse(string, Object);
[103] Fix | Delete
*
[104] Fix | Delete
* HTMLElement tree parsing for safer operations over existing DOM
[105] Fix | Delete
* twemoji.parse(HTMLElement);
[106] Fix | Delete
* twemoji.parse(HTMLElement, Function);
[107] Fix | Delete
* twemoji.parse(HTMLElement, Object);
[108] Fix | Delete
*
[109] Fix | Delete
* @param string|HTMLElement the source to parse and enrich with emoji.
[110] Fix | Delete
*
[111] Fix | Delete
* string replace emoji matches with <img> tags.
[112] Fix | Delete
* Mainly used to inject emoji via `innerHTML`
[113] Fix | Delete
* It does **not** parse the string or validate it,
[114] Fix | Delete
* it simply replaces found emoji with a tag.
[115] Fix | Delete
* NOTE: be sure this won't affect security.
[116] Fix | Delete
*
[117] Fix | Delete
* HTMLElement walk through the DOM tree and find emoji
[118] Fix | Delete
* that are inside **text node only** (nodeType === 3)
[119] Fix | Delete
* Mainly used to put emoji in already generated DOM
[120] Fix | Delete
* without compromising surrounding nodes and
[121] Fix | Delete
* **avoiding** the usage of `innerHTML`.
[122] Fix | Delete
* NOTE: Using DOM elements instead of strings should
[123] Fix | Delete
* improve security without compromising too much
[124] Fix | Delete
* performance compared with a less safe `innerHTML`.
[125] Fix | Delete
*
[126] Fix | Delete
* @param Function|Object [optional]
[127] Fix | Delete
* either the callback that will be invoked or an object
[128] Fix | Delete
* with all properties to use per each found emoji.
[129] Fix | Delete
*
[130] Fix | Delete
* Function if specified, this will be invoked per each emoji
[131] Fix | Delete
* that has been found through the RegExp except
[132] Fix | Delete
* those follwed by the invariant \uFE0E ("as text").
[133] Fix | Delete
* Once invoked, parameters will be:
[134] Fix | Delete
*
[135] Fix | Delete
* iconId:string the lower case HEX code point
[136] Fix | Delete
* i.e. "1f4a9"
[137] Fix | Delete
*
[138] Fix | Delete
* options:Object all info for this parsing operation
[139] Fix | Delete
*
[140] Fix | Delete
* variant:char the optional \uFE0F ("as image")
[141] Fix | Delete
* variant, in case this info
[142] Fix | Delete
* is anyhow meaningful.
[143] Fix | Delete
* By default this is ignored.
[144] Fix | Delete
*
[145] Fix | Delete
* If such callback will return a falsy value instead
[146] Fix | Delete
* of a valid `src` to use for the image, nothing will
[147] Fix | Delete
* actually change for that specific emoji.
[148] Fix | Delete
*
[149] Fix | Delete
*
[150] Fix | Delete
* Object if specified, an object containing the following properties
[151] Fix | Delete
*
[152] Fix | Delete
* callback Function the callback to invoke per each found emoji.
[153] Fix | Delete
* base string the base url, by default twemoji.base
[154] Fix | Delete
* ext string the image extension, by default twemoji.ext
[155] Fix | Delete
* size string the assets size, by default twemoji.size
[156] Fix | Delete
*
[157] Fix | Delete
* @example
[158] Fix | Delete
*
[159] Fix | Delete
* twemoji.parse("I \u2764\uFE0F emoji!");
[160] Fix | Delete
* // I <img class="emoji" draggable="false" alt="❤️" src="/assets/2764.gif"/> emoji!
[161] Fix | Delete
*
[162] Fix | Delete
*
[163] Fix | Delete
* twemoji.parse("I \u2764\uFE0F emoji!", function(iconId, options) {
[164] Fix | Delete
* return '/assets/' + iconId + '.gif';
[165] Fix | Delete
* });
[166] Fix | Delete
* // I <img class="emoji" draggable="false" alt="❤️" src="/assets/2764.gif"/> emoji!
[167] Fix | Delete
*
[168] Fix | Delete
*
[169] Fix | Delete
* twemoji.parse("I \u2764\uFE0F emoji!", {
[170] Fix | Delete
* size: 72,
[171] Fix | Delete
* callback: function(iconId, options) {
[172] Fix | Delete
* return '/assets/' + options.size + '/' + iconId + options.ext;
[173] Fix | Delete
* }
[174] Fix | Delete
* });
[175] Fix | Delete
* // I <img class="emoji" draggable="false" alt="❤️" src="/assets/72x72/2764.png"/> emoji!
[176] Fix | Delete
*
[177] Fix | Delete
*/
[178] Fix | Delete
parse: parse,
[179] Fix | Delete
[180] Fix | Delete
/**
[181] Fix | Delete
* Given a string, invokes the callback argument
[182] Fix | Delete
* per each emoji found in such string.
[183] Fix | Delete
* This is the most raw version used by
[184] Fix | Delete
* the .parse(string) method itself.
[185] Fix | Delete
*
[186] Fix | Delete
* @param string generic string to parse
[187] Fix | Delete
* @param Function a generic callback that will be
[188] Fix | Delete
* invoked to replace the content.
[189] Fix | Delete
* This calback wil receive standard
[190] Fix | Delete
* String.prototype.replace(str, callback)
[191] Fix | Delete
* arguments such:
[192] Fix | Delete
* callback(
[193] Fix | Delete
* rawText, // the emoji match
[194] Fix | Delete
* );
[195] Fix | Delete
*
[196] Fix | Delete
* and others commonly received via replace.
[197] Fix | Delete
*/
[198] Fix | Delete
replace: replace,
[199] Fix | Delete
[200] Fix | Delete
/**
[201] Fix | Delete
* Simplify string tests against emoji.
[202] Fix | Delete
*
[203] Fix | Delete
* @param string some text that might contain emoji
[204] Fix | Delete
* @return boolean true if any emoji was found, false otherwise.
[205] Fix | Delete
*
[206] Fix | Delete
* @example
[207] Fix | Delete
*
[208] Fix | Delete
* if (twemoji.test(someContent)) {
[209] Fix | Delete
* console.log("emoji All The Things!");
[210] Fix | Delete
* }
[211] Fix | Delete
*/
[212] Fix | Delete
test: test
[213] Fix | Delete
},
[214] Fix | Delete
[215] Fix | Delete
// used to escape HTML special chars in attributes
[216] Fix | Delete
escaper = {
[217] Fix | Delete
'&': '&amp;',
[218] Fix | Delete
'<': '&lt;',
[219] Fix | Delete
'>': '&gt;',
[220] Fix | Delete
"'": '&#39;',
[221] Fix | Delete
'"': '&quot;'
[222] Fix | Delete
},
[223] Fix | Delete
[224] Fix | Delete
// RegExp based on emoji's official Unicode standards
[225] Fix | Delete
// http://www.unicode.org/Public/UNIDATA/EmojiSources.txt
[226] Fix | Delete
re = /(?:\ud83d\udc68\ud83c\udffb\u200d\ud83e\udd1d\u200d\ud83d\udc68\ud83c[\udffc-\udfff]|\ud83d\udc68\ud83c\udffc\u200d\ud83e\udd1d\u200d\ud83d\udc68\ud83c[\udffb\udffd-\udfff]|\ud83d\udc68\ud83c\udffd\u200d\ud83e\udd1d\u200d\ud83d\udc68\ud83c[\udffb\udffc\udffe\udfff]|\ud83d\udc68\ud83c\udffe\u200d\ud83e\udd1d\u200d\ud83d\udc68\ud83c[\udffb-\udffd\udfff]|\ud83d\udc68\ud83c\udfff\u200d\ud83e\udd1d\u200d\ud83d\udc68\ud83c[\udffb-\udffe]|\ud83d\udc69\ud83c\udffb\u200d\ud83e\udd1d\u200d\ud83d\udc68\ud83c[\udffc-\udfff]|\ud83d\udc69\ud83c\udffb\u200d\ud83e\udd1d\u200d\ud83d\udc69\ud83c[\udffc-\udfff]|\ud83d\udc69\ud83c\udffc\u200d\ud83e\udd1d\u200d\ud83d\udc68\ud83c[\udffb\udffd-\udfff]|\ud83d\udc69\ud83c\udffc\u200d\ud83e\udd1d\u200d\ud83d\udc69\ud83c[\udffb\udffd-\udfff]|\ud83d\udc69\ud83c\udffd\u200d\ud83e\udd1d\u200d\ud83d\udc68\ud83c[\udffb\udffc\udffe\udfff]|\ud83d\udc69\ud83c\udffd\u200d\ud83e\udd1d\u200d\ud83d\udc69\ud83c[\udffb\udffc\udffe\udfff]|\ud83d\udc69\ud83c\udffe\u200d\ud83e\udd1d\u200d\ud83d\udc68\ud83c[\udffb-\udffd\udfff]|\ud83d\udc69\ud83c\udffe\u200d\ud83e\udd1d\u200d\ud83d\udc69\ud83c[\udffb-\udffd\udfff]|\ud83d\udc69\ud83c\udfff\u200d\ud83e\udd1d\u200d\ud83d\udc68\ud83c[\udffb-\udffe]|\ud83d\udc69\ud83c\udfff\u200d\ud83e\udd1d\u200d\ud83d\udc69\ud83c[\udffb-\udffe]|\ud83e\uddd1\ud83c\udffb\u200d\ud83e\udd1d\u200d\ud83e\uddd1\ud83c[\udffb-\udfff]|\ud83e\uddd1\ud83c\udffc\u200d\ud83e\udd1d\u200d\ud83e\uddd1\ud83c[\udffb-\udfff]|\ud83e\uddd1\ud83c\udffd\u200d\ud83e\udd1d\u200d\ud83e\uddd1\ud83c[\udffb-\udfff]|\ud83e\uddd1\ud83c\udffe\u200d\ud83e\udd1d\u200d\ud83e\uddd1\ud83c[\udffb-\udfff]|\ud83e\uddd1\ud83c\udfff\u200d\ud83e\udd1d\u200d\ud83e\uddd1\ud83c[\udffb-\udfff]|\ud83e\uddd1\u200d\ud83e\udd1d\u200d\ud83e\uddd1|\ud83d\udc6b\ud83c[\udffb-\udfff]|\ud83d\udc6c\ud83c[\udffb-\udfff]|\ud83d\udc6d\ud83c[\udffb-\udfff]|\ud83d[\udc6b-\udc6d])|(?:\ud83d[\udc68\udc69]|\ud83e\uddd1)(?:\ud83c[\udffb-\udfff])?\u200d(?:\u2695\ufe0f|\u2696\ufe0f|\u2708\ufe0f|\ud83c[\udf3e\udf73\udf7c\udf84\udf93\udfa4\udfa8\udfeb\udfed]|\ud83d[\udcbb\udcbc\udd27\udd2c\ude80\ude92]|\ud83e[\uddaf-\uddb3\uddbc\uddbd])|(?:\ud83c[\udfcb\udfcc]|\ud83d[\udd74\udd75]|\u26f9)((?:\ud83c[\udffb-\udfff]|\ufe0f)\u200d[\u2640\u2642]\ufe0f)|(?:\ud83c[\udfc3\udfc4\udfca]|\ud83d[\udc6e\udc70\udc71\udc73\udc77\udc81\udc82\udc86\udc87\ude45-\ude47\ude4b\ude4d\ude4e\udea3\udeb4-\udeb6]|\ud83e[\udd26\udd35\udd37-\udd39\udd3d\udd3e\uddb8\uddb9\uddcd-\uddcf\uddd6-\udddd])(?:\ud83c[\udffb-\udfff])?\u200d[\u2640\u2642]\ufe0f|(?:\ud83d\udc68\u200d\u2764\ufe0f\u200d\ud83d\udc8b\u200d\ud83d\udc68|\ud83d\udc68\u200d\ud83d\udc68\u200d\ud83d\udc66\u200d\ud83d\udc66|\ud83d\udc68\u200d\ud83d\udc68\u200d\ud83d\udc67\u200d\ud83d[\udc66\udc67]|\ud83d\udc68\u200d\ud83d\udc69\u200d\ud83d\udc66\u200d\ud83d\udc66|\ud83d\udc68\u200d\ud83d\udc69\u200d\ud83d\udc67\u200d\ud83d[\udc66\udc67]|\ud83d\udc69\u200d\u2764\ufe0f\u200d\ud83d\udc8b\u200d\ud83d[\udc68\udc69]|\ud83d\udc69\u200d\ud83d\udc69\u200d\ud83d\udc66\u200d\ud83d\udc66|\ud83d\udc69\u200d\ud83d\udc69\u200d\ud83d\udc67\u200d\ud83d[\udc66\udc67]|\ud83d\udc68\u200d\u2764\ufe0f\u200d\ud83d\udc68|\ud83d\udc68\u200d\ud83d\udc66\u200d\ud83d\udc66|\ud83d\udc68\u200d\ud83d\udc67\u200d\ud83d[\udc66\udc67]|\ud83d\udc68\u200d\ud83d\udc68\u200d\ud83d[\udc66\udc67]|\ud83d\udc68\u200d\ud83d\udc69\u200d\ud83d[\udc66\udc67]|\ud83d\udc69\u200d\u2764\ufe0f\u200d\ud83d[\udc68\udc69]|\ud83d\udc69\u200d\ud83d\udc66\u200d\ud83d\udc66|\ud83d\udc69\u200d\ud83d\udc67\u200d\ud83d[\udc66\udc67]|\ud83d\udc69\u200d\ud83d\udc69\u200d\ud83d[\udc66\udc67]|\ud83c\udff3\ufe0f\u200d\u26a7\ufe0f|\ud83c\udff3\ufe0f\u200d\ud83c\udf08|\ud83c\udff4\u200d\u2620\ufe0f|\ud83d\udc15\u200d\ud83e\uddba|\ud83d\udc3b\u200d\u2744\ufe0f|\ud83d\udc41\u200d\ud83d\udde8|\ud83d\udc68\u200d\ud83d[\udc66\udc67]|\ud83d\udc69\u200d\ud83d[\udc66\udc67]|\ud83d\udc6f\u200d\u2640\ufe0f|\ud83d\udc6f\u200d\u2642\ufe0f|\ud83e\udd3c\u200d\u2640\ufe0f|\ud83e\udd3c\u200d\u2642\ufe0f|\ud83e\uddde\u200d\u2640\ufe0f|\ud83e\uddde\u200d\u2642\ufe0f|\ud83e\udddf\u200d\u2640\ufe0f|\ud83e\udddf\u200d\u2642\ufe0f|\ud83d\udc08\u200d\u2b1b)|[#*0-9]\ufe0f?\u20e3|(?:[©®\u2122\u265f]\ufe0f)|(?:\ud83c[\udc04\udd70\udd71\udd7e\udd7f\ude02\ude1a\ude2f\ude37\udf21\udf24-\udf2c\udf36\udf7d\udf96\udf97\udf99-\udf9b\udf9e\udf9f\udfcd\udfce\udfd4-\udfdf\udff3\udff5\udff7]|\ud83d[\udc3f\udc41\udcfd\udd49\udd4a\udd6f\udd70\udd73\udd76-\udd79\udd87\udd8a-\udd8d\udda5\udda8\uddb1\uddb2\uddbc\uddc2-\uddc4\uddd1-\uddd3\udddc-\uddde\udde1\udde3\udde8\uddef\uddf3\uddfa\udecb\udecd-\udecf\udee0-\udee5\udee9\udef0\udef3]|[\u203c\u2049\u2139\u2194-\u2199\u21a9\u21aa\u231a\u231b\u2328\u23cf\u23ed-\u23ef\u23f1\u23f2\u23f8-\u23fa\u24c2\u25aa\u25ab\u25b6\u25c0\u25fb-\u25fe\u2600-\u2604\u260e\u2611\u2614\u2615\u2618\u2620\u2622\u2623\u2626\u262a\u262e\u262f\u2638-\u263a\u2640\u2642\u2648-\u2653\u2660\u2663\u2665\u2666\u2668\u267b\u267f\u2692-\u2697\u2699\u269b\u269c\u26a0\u26a1\u26a7\u26aa\u26ab\u26b0\u26b1\u26bd\u26be\u26c4\u26c5\u26c8\u26cf\u26d1\u26d3\u26d4\u26e9\u26ea\u26f0-\u26f5\u26f8\u26fa\u26fd\u2702\u2708\u2709\u270f\u2712\u2714\u2716\u271d\u2721\u2733\u2734\u2744\u2747\u2757\u2763\u2764\u27a1\u2934\u2935\u2b05-\u2b07\u2b1b\u2b1c\u2b50\u2b55\u3030\u303d\u3297\u3299])(?:\ufe0f|(?!\ufe0e))|(?:(?:\ud83c[\udfcb\udfcc]|\ud83d[\udd74\udd75\udd90]|[\u261d\u26f7\u26f9\u270c\u270d])(?:\ufe0f|(?!\ufe0e))|(?:\ud83c[\udf85\udfc2-\udfc4\udfc7\udfca]|\ud83d[\udc42\udc43\udc46-\udc50\udc66-\udc69\udc6e\udc70-\udc78\udc7c\udc81-\udc83\udc85-\udc87\udcaa\udd7a\udd95\udd96\ude45-\ude47\ude4b-\ude4f\udea3\udeb4-\udeb6\udec0\udecc]|\ud83e[\udd0c\udd0f\udd18-\udd1c\udd1e\udd1f\udd26\udd30-\udd39\udd3d\udd3e\udd77\uddb5\uddb6\uddb8\uddb9\uddbb\uddcd-\uddcf\uddd1-\udddd]|[\u270a\u270b]))(?:\ud83c[\udffb-\udfff])?|(?:\ud83c\udff4\udb40\udc67\udb40\udc62\udb40\udc65\udb40\udc6e\udb40\udc67\udb40\udc7f|\ud83c\udff4\udb40\udc67\udb40\udc62\udb40\udc73\udb40\udc63\udb40\udc74\udb40\udc7f|\ud83c\udff4\udb40\udc67\udb40\udc62\udb40\udc77\udb40\udc6c\udb40\udc73\udb40\udc7f|\ud83c\udde6\ud83c[\udde8-\uddec\uddee\uddf1\uddf2\uddf4\uddf6-\uddfa\uddfc\uddfd\uddff]|\ud83c\udde7\ud83c[\udde6\udde7\udde9-\uddef\uddf1-\uddf4\uddf6-\uddf9\uddfb\uddfc\uddfe\uddff]|\ud83c\udde8\ud83c[\udde6\udde8\udde9\uddeb-\uddee\uddf0-\uddf5\uddf7\uddfa-\uddff]|\ud83c\udde9\ud83c[\uddea\uddec\uddef\uddf0\uddf2\uddf4\uddff]|\ud83c\uddea\ud83c[\udde6\udde8\uddea\uddec\udded\uddf7-\uddfa]|\ud83c\uddeb\ud83c[\uddee-\uddf0\uddf2\uddf4\uddf7]|\ud83c\uddec\ud83c[\udde6\udde7\udde9-\uddee\uddf1-\uddf3\uddf5-\uddfa\uddfc\uddfe]|\ud83c\udded\ud83c[\uddf0\uddf2\uddf3\uddf7\uddf9\uddfa]|\ud83c\uddee\ud83c[\udde8-\uddea\uddf1-\uddf4\uddf6-\uddf9]|\ud83c\uddef\ud83c[\uddea\uddf2\uddf4\uddf5]|\ud83c\uddf0\ud83c[\uddea\uddec-\uddee\uddf2\uddf3\uddf5\uddf7\uddfc\uddfe\uddff]|\ud83c\uddf1\ud83c[\udde6-\udde8\uddee\uddf0\uddf7-\uddfb\uddfe]|\ud83c\uddf2\ud83c[\udde6\udde8-\udded\uddf0-\uddff]|\ud83c\uddf3\ud83c[\udde6\udde8\uddea-\uddec\uddee\uddf1\uddf4\uddf5\uddf7\uddfa\uddff]|\ud83c\uddf4\ud83c\uddf2|\ud83c\uddf5\ud83c[\udde6\uddea-\udded\uddf0-\uddf3\uddf7-\uddf9\uddfc\uddfe]|\ud83c\uddf6\ud83c\udde6|\ud83c\uddf7\ud83c[\uddea\uddf4\uddf8\uddfa\uddfc]|\ud83c\uddf8\ud83c[\udde6-\uddea\uddec-\uddf4\uddf7-\uddf9\uddfb\uddfd-\uddff]|\ud83c\uddf9\ud83c[\udde6\udde8\udde9\uddeb-\udded\uddef-\uddf4\uddf7\uddf9\uddfb\uddfc\uddff]|\ud83c\uddfa\ud83c[\udde6\uddec\uddf2\uddf3\uddf8\uddfe\uddff]|\ud83c\uddfb\ud83c[\udde6\udde8\uddea\uddec\uddee\uddf3\uddfa]|\ud83c\uddfc\ud83c[\uddeb\uddf8]|\ud83c\uddfd\ud83c\uddf0|\ud83c\uddfe\ud83c[\uddea\uddf9]|\ud83c\uddff\ud83c[\udde6\uddf2\uddfc]|\ud83c[\udccf\udd8e\udd91-\udd9a\udde6-\uddff\ude01\ude32-\ude36\ude38-\ude3a\ude50\ude51\udf00-\udf20\udf2d-\udf35\udf37-\udf7c\udf7e-\udf84\udf86-\udf93\udfa0-\udfc1\udfc5\udfc6\udfc8\udfc9\udfcf-\udfd3\udfe0-\udff0\udff4\udff8-\udfff]|\ud83d[\udc00-\udc3e\udc40\udc44\udc45\udc51-\udc65\udc6a\udc6f\udc79-\udc7b\udc7d-\udc80\udc84\udc88-\udca9\udcab-\udcfc\udcff-\udd3d\udd4b-\udd4e\udd50-\udd67\udda4\uddfb-\ude44\ude48-\ude4a\ude80-\udea2\udea4-\udeb3\udeb7-\udebf\udec1-\udec5\uded0-\uded2\uded5-\uded7\udeeb\udeec\udef4-\udefc\udfe0-\udfeb]|\ud83e[\udd0d\udd0e\udd10-\udd17\udd1d\udd20-\udd25\udd27-\udd2f\udd3a\udd3c\udd3f-\udd45\udd47-\udd76\udd78\udd7a-\uddb4\uddb7\uddba\uddbc-\uddcb\uddd0\uddde-\uddff\ude70-\ude74\ude78-\ude7a\ude80-\ude86\ude90-\udea8\udeb0-\udeb6\udec0-\udec2\uded0-\uded6]|[\u23e9-\u23ec\u23f0\u23f3\u267e\u26ce\u2705\u2728\u274c\u274e\u2753-\u2755\u2795-\u2797\u27b0\u27bf\ue50a])|\ufe0f/g,
[227] Fix | Delete
[228] Fix | Delete
// avoid runtime RegExp creation for not so smart,
[229] Fix | Delete
// not JIT based, and old browsers / engines
[230] Fix | Delete
UFE0Fg = /\uFE0F/g,
[231] Fix | Delete
[232] Fix | Delete
// avoid using a string literal like '\u200D' here because minifiers expand it inline
[233] Fix | Delete
U200D = String.fromCharCode(0x200D),
[234] Fix | Delete
[235] Fix | Delete
// used to find HTML special chars in attributes
[236] Fix | Delete
rescaper = /[&<>'"]/g,
[237] Fix | Delete
[238] Fix | Delete
// nodes with type 1 which should **not** be parsed
[239] Fix | Delete
shouldntBeParsed = /^(?:iframe|noframes|noscript|script|select|style|textarea)$/,
[240] Fix | Delete
[241] Fix | Delete
// just a private shortcut
[242] Fix | Delete
fromCharCode = String.fromCharCode;
[243] Fix | Delete
[244] Fix | Delete
return twemoji;
[245] Fix | Delete
[246] Fix | Delete
[247] Fix | Delete
/////////////////////////
[248] Fix | Delete
// private functions //
[249] Fix | Delete
// declaration //
[250] Fix | Delete
/////////////////////////
[251] Fix | Delete
[252] Fix | Delete
/**
[253] Fix | Delete
* Shortcut to create text nodes
[254] Fix | Delete
* @param string text used to create DOM text node
[255] Fix | Delete
* @return Node a DOM node with that text
[256] Fix | Delete
*/
[257] Fix | Delete
function createText(text, clean) {
[258] Fix | Delete
return document.createTextNode(clean ? text.replace(UFE0Fg, '') : text);
[259] Fix | Delete
}
[260] Fix | Delete
[261] Fix | Delete
/**
[262] Fix | Delete
* Utility function to escape html attribute text
[263] Fix | Delete
* @param string text use in HTML attribute
[264] Fix | Delete
* @return string text encoded to use in HTML attribute
[265] Fix | Delete
*/
[266] Fix | Delete
function escapeHTML(s) {
[267] Fix | Delete
return s.replace(rescaper, replacer);
[268] Fix | Delete
}
[269] Fix | Delete
[270] Fix | Delete
/**
[271] Fix | Delete
* Default callback used to generate emoji src
[272] Fix | Delete
* based on Twitter CDN
[273] Fix | Delete
* @param string the emoji codepoint string
[274] Fix | Delete
* @param string the default size to use, i.e. "36x36"
[275] Fix | Delete
* @return string the image source to use
[276] Fix | Delete
*/
[277] Fix | Delete
function defaultImageSrcGenerator(icon, options) {
[278] Fix | Delete
return ''.concat(options.base, options.size, '/', icon, options.ext);
[279] Fix | Delete
}
[280] Fix | Delete
[281] Fix | Delete
/**
[282] Fix | Delete
* Given a generic DOM nodeType 1, walk through all children
[283] Fix | Delete
* and store every nodeType 3 (#text) found in the tree.
[284] Fix | Delete
* @param Element a DOM Element with probably some text in it
[285] Fix | Delete
* @param Array the list of previously discovered text nodes
[286] Fix | Delete
* @return Array same list with new discovered nodes, if any
[287] Fix | Delete
*/
[288] Fix | Delete
function grabAllTextNodes(node, allText) {
[289] Fix | Delete
var
[290] Fix | Delete
childNodes = node.childNodes,
[291] Fix | Delete
length = childNodes.length,
[292] Fix | Delete
subnode,
[293] Fix | Delete
nodeType;
[294] Fix | Delete
while (length--) {
[295] Fix | Delete
subnode = childNodes[length];
[296] Fix | Delete
nodeType = subnode.nodeType;
[297] Fix | Delete
// parse emoji only in text nodes
[298] Fix | Delete
if (nodeType === 3) {
[299] Fix | Delete
// collect them to process emoji later
[300] Fix | Delete
allText.push(subnode);
[301] Fix | Delete
}
[302] Fix | Delete
// ignore all nodes that are not type 1, that are svg, or that
[303] Fix | Delete
// should not be parsed as script, style, and others
[304] Fix | Delete
else if (nodeType === 1 && !('ownerSVGElement' in subnode) &&
[305] Fix | Delete
!shouldntBeParsed.test(subnode.nodeName.toLowerCase())) {
[306] Fix | Delete
grabAllTextNodes(subnode, allText);
[307] Fix | Delete
}
[308] Fix | Delete
}
[309] Fix | Delete
return allText;
[310] Fix | Delete
}
[311] Fix | Delete
[312] Fix | Delete
/**
[313] Fix | Delete
* Used to both remove the possible variant
[314] Fix | Delete
* and to convert utf16 into code points.
[315] Fix | Delete
* If there is a zero-width-joiner (U+200D), leave the variants in.
[316] Fix | Delete
* @param string the raw text of the emoji match
[317] Fix | Delete
* @return string the code point
[318] Fix | Delete
*/
[319] Fix | Delete
function grabTheRightIcon(rawText) {
[320] Fix | Delete
// if variant is present as \uFE0F
[321] Fix | Delete
return toCodePoint(rawText.indexOf(U200D) < 0 ?
[322] Fix | Delete
rawText.replace(UFE0Fg, '') :
[323] Fix | Delete
rawText
[324] Fix | Delete
);
[325] Fix | Delete
}
[326] Fix | Delete
[327] Fix | Delete
/**
[328] Fix | Delete
* DOM version of the same logic / parser:
[329] Fix | Delete
* emojify all found sub-text nodes placing images node instead.
[330] Fix | Delete
* @param Element generic DOM node with some text in some child node
[331] Fix | Delete
* @param Object options containing info about how to parse
[332] Fix | Delete
*
[333] Fix | Delete
* .callback Function the callback to invoke per each found emoji.
[334] Fix | Delete
* .base string the base url, by default twemoji.base
[335] Fix | Delete
* .ext string the image extension, by default twemoji.ext
[336] Fix | Delete
* .size string the assets size, by default twemoji.size
[337] Fix | Delete
*
[338] Fix | Delete
* @return Element same generic node with emoji in place, if any.
[339] Fix | Delete
*/
[340] Fix | Delete
function parseNode(node, options) {
[341] Fix | Delete
var
[342] Fix | Delete
allText = grabAllTextNodes(node, []),
[343] Fix | Delete
length = allText.length,
[344] Fix | Delete
attrib,
[345] Fix | Delete
attrname,
[346] Fix | Delete
modified,
[347] Fix | Delete
fragment,
[348] Fix | Delete
subnode,
[349] Fix | Delete
text,
[350] Fix | Delete
match,
[351] Fix | Delete
i,
[352] Fix | Delete
index,
[353] Fix | Delete
img,
[354] Fix | Delete
rawText,
[355] Fix | Delete
iconId,
[356] Fix | Delete
src;
[357] Fix | Delete
while (length--) {
[358] Fix | Delete
modified = false;
[359] Fix | Delete
fragment = document.createDocumentFragment();
[360] Fix | Delete
subnode = allText[length];
[361] Fix | Delete
text = subnode.nodeValue;
[362] Fix | Delete
i = 0;
[363] Fix | Delete
while ((match = re.exec(text))) {
[364] Fix | Delete
index = match.index;
[365] Fix | Delete
if (index !== i) {
[366] Fix | Delete
fragment.appendChild(
[367] Fix | Delete
createText(text.slice(i, index), true)
[368] Fix | Delete
);
[369] Fix | Delete
}
[370] Fix | Delete
rawText = match[0];
[371] Fix | Delete
iconId = grabTheRightIcon(rawText);
[372] Fix | Delete
i = index + rawText.length;
[373] Fix | Delete
src = options.callback(iconId, options);
[374] Fix | Delete
if (iconId && src) {
[375] Fix | Delete
img = new Image();
[376] Fix | Delete
img.onerror = options.onerror;
[377] Fix | Delete
img.setAttribute('draggable', 'false');
[378] Fix | Delete
attrib = options.attributes(rawText, iconId);
[379] Fix | Delete
for (attrname in attrib) {
[380] Fix | Delete
if (
[381] Fix | Delete
attrib.hasOwnProperty(attrname) &&
[382] Fix | Delete
// don't allow any handlers to be set + don't allow overrides
[383] Fix | Delete
attrname.indexOf('on') !== 0 &&
[384] Fix | Delete
!img.hasAttribute(attrname)
[385] Fix | Delete
) {
[386] Fix | Delete
img.setAttribute(attrname, attrib[attrname]);
[387] Fix | Delete
}
[388] Fix | Delete
}
[389] Fix | Delete
img.className = options.className;
[390] Fix | Delete
img.alt = rawText;
[391] Fix | Delete
img.src = src;
[392] Fix | Delete
modified = true;
[393] Fix | Delete
fragment.appendChild(img);
[394] Fix | Delete
}
[395] Fix | Delete
if (!img) fragment.appendChild(createText(rawText, false));
[396] Fix | Delete
img = null;
[397] Fix | Delete
}
[398] Fix | Delete
// is there actually anything to replace in here ?
[399] Fix | Delete
if (modified) {
[400] Fix | Delete
// any text left to be added ?
[401] Fix | Delete
if (i < text.length) {
[402] Fix | Delete
fragment.appendChild(
[403] Fix | Delete
createText(text.slice(i), true)
[404] Fix | Delete
);
[405] Fix | Delete
}
[406] Fix | Delete
// replace the text node only, leave intact
[407] Fix | Delete
// anything else surrounding such text
[408] Fix | Delete
subnode.parentNode.replaceChild(fragment, subnode);
[409] Fix | Delete
}
[410] Fix | Delete
}
[411] Fix | Delete
return node;
[412] Fix | Delete
}
[413] Fix | Delete
[414] Fix | Delete
/**
[415] Fix | Delete
* String/HTML version of the same logic / parser:
[416] Fix | Delete
* emojify a generic text placing images tags instead of surrogates pair.
[417] Fix | Delete
* @param string generic string with possibly some emoji in it
[418] Fix | Delete
* @param Object options containing info about how to parse
[419] Fix | Delete
*
[420] Fix | Delete
* .callback Function the callback to invoke per each found emoji.
[421] Fix | Delete
* .base string the base url, by default twemoji.base
[422] Fix | Delete
* .ext string the image extension, by default twemoji.ext
[423] Fix | Delete
* .size string the assets size, by default twemoji.size
[424] Fix | Delete
*
[425] Fix | Delete
* @return the string with <img tags> replacing all found and parsed emoji
[426] Fix | Delete
*/
[427] Fix | Delete
function parseString(str, options) {
[428] Fix | Delete
return replace(str, function (rawText) {
[429] Fix | Delete
var
[430] Fix | Delete
ret = rawText,
[431] Fix | Delete
iconId = grabTheRightIcon(rawText),
[432] Fix | Delete
src = options.callback(iconId, options),
[433] Fix | Delete
attrib,
[434] Fix | Delete
attrname;
[435] Fix | Delete
if (iconId && src) {
[436] Fix | Delete
// recycle the match string replacing the emoji
[437] Fix | Delete
// with its image counter part
[438] Fix | Delete
ret = '<img '.concat(
[439] Fix | Delete
'class="', options.className, '" ',
[440] Fix | Delete
'draggable="false" ',
[441] Fix | Delete
// needs to preserve user original intent
[442] Fix | Delete
// when variants should be copied and pasted too
[443] Fix | Delete
'alt="',
[444] Fix | Delete
rawText,
[445] Fix | Delete
'"',
[446] Fix | Delete
' src="',
[447] Fix | Delete
src,
[448] Fix | Delete
'"'
[449] Fix | Delete
);
[450] Fix | Delete
attrib = options.attributes(rawText, iconId);
[451] Fix | Delete
for (attrname in attrib) {
[452] Fix | Delete
if (
[453] Fix | Delete
attrib.hasOwnProperty(attrname) &&
[454] Fix | Delete
// don't allow any handlers to be set + don't allow overrides
[455] Fix | Delete
attrname.indexOf('on') !== 0 &&
[456] Fix | Delete
ret.indexOf(' ' + attrname + '=') === -1
[457] Fix | Delete
) {
[458] Fix | Delete
ret = ret.concat(' ', attrname, '="', escapeHTML(attrib[attrname]), '"');
[459] Fix | Delete
}
[460] Fix | Delete
}
[461] Fix | Delete
ret = ret.concat('/>');
[462] Fix | Delete
}
[463] Fix | Delete
return ret;
[464] Fix | Delete
});
[465] Fix | Delete
}
[466] Fix | Delete
[467] Fix | Delete
/**
[468] Fix | Delete
* Function used to actually replace HTML special chars
[469] Fix | Delete
* @param string HTML special char
[470] Fix | Delete
* @return string encoded HTML special char
[471] Fix | Delete
*/
[472] Fix | Delete
function replacer(m) {
[473] Fix | Delete
return escaper[m];
[474] Fix | Delete
}
[475] Fix | Delete
[476] Fix | Delete
/**
[477] Fix | Delete
* Default options.attribute callback
[478] Fix | Delete
* @return null
[479] Fix | Delete
*/
[480] Fix | Delete
function returnNull() {
[481] Fix | Delete
return null;
[482] Fix | Delete
}
[483] Fix | Delete
[484] Fix | Delete
/**
[485] Fix | Delete
* Given a generic value, creates its squared counterpart if it's a number.
[486] Fix | Delete
* As example, number 36 will return '36x36'.
[487] Fix | Delete
* @param any a generic value.
[488] Fix | Delete
* @return any a string representing asset size, i.e. "36x36"
[489] Fix | Delete
* only in case the value was a number.
[490] Fix | Delete
* Returns initial value otherwise.
[491] Fix | Delete
*/
[492] Fix | Delete
function toSizeSquaredAsset(value) {
[493] Fix | Delete
return typeof value === 'number' ?
[494] Fix | Delete
value + 'x' + value :
[495] Fix | Delete
value;
[496] Fix | Delete
}
[497] Fix | Delete
[498] Fix | Delete
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function