Edit File by line
/home/barbar84/public_h.../wp-inclu.../js
File: wp-emoji.js
/**
[0] Fix | Delete
* wp-emoji.js is used to replace emoji with images in browsers when the browser
[1] Fix | Delete
* doesn't support emoji natively.
[2] Fix | Delete
*
[3] Fix | Delete
* @output wp-includes/js/wp-emoji.js
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
( function( window, settings ) {
[7] Fix | Delete
/**
[8] Fix | Delete
* Replaces emoji with images when browsers don't support emoji.
[9] Fix | Delete
*
[10] Fix | Delete
* @since 4.2.0
[11] Fix | Delete
* @access private
[12] Fix | Delete
*
[13] Fix | Delete
* @class
[14] Fix | Delete
*
[15] Fix | Delete
* @see Twitter Emoji library
[16] Fix | Delete
* @link https://github.com/twitter/twemoji
[17] Fix | Delete
*
[18] Fix | Delete
* @return {Object} The wpEmoji parse and test functions.
[19] Fix | Delete
*/
[20] Fix | Delete
function wpEmoji() {
[21] Fix | Delete
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver,
[22] Fix | Delete
[23] Fix | Delete
// Compression and maintain local scope.
[24] Fix | Delete
document = window.document,
[25] Fix | Delete
[26] Fix | Delete
// Private.
[27] Fix | Delete
twemoji, timer,
[28] Fix | Delete
loaded = false,
[29] Fix | Delete
count = 0,
[30] Fix | Delete
ie11 = window.navigator.userAgent.indexOf( 'Trident/7.0' ) > 0;
[31] Fix | Delete
[32] Fix | Delete
/**
[33] Fix | Delete
* Detect if the browser supports SVG.
[34] Fix | Delete
*
[35] Fix | Delete
* @since 4.6.0
[36] Fix | Delete
* @private
[37] Fix | Delete
*
[38] Fix | Delete
* @see Modernizr
[39] Fix | Delete
* @link https://github.com/Modernizr/Modernizr/blob/master/feature-detects/svg/asimg.js
[40] Fix | Delete
*
[41] Fix | Delete
* @return {boolean} True if the browser supports svg, false if not.
[42] Fix | Delete
*/
[43] Fix | Delete
function browserSupportsSvgAsImage() {
[44] Fix | Delete
if ( !! document.implementation.hasFeature ) {
[45] Fix | Delete
return document.implementation.hasFeature( 'http://www.w3.org/TR/SVG11/feature#Image', '1.1' );
[46] Fix | Delete
}
[47] Fix | Delete
[48] Fix | Delete
// document.implementation.hasFeature is deprecated. It can be presumed
[49] Fix | Delete
// if future browsers remove it, the browser will support SVGs as images.
[50] Fix | Delete
return true;
[51] Fix | Delete
}
[52] Fix | Delete
[53] Fix | Delete
/**
[54] Fix | Delete
* Runs when the document load event is fired, so we can do our first parse of
[55] Fix | Delete
* the page.
[56] Fix | Delete
*
[57] Fix | Delete
* Listens to all the DOM mutations and checks for added nodes that contain
[58] Fix | Delete
* emoji characters and replaces those with twitter emoji images.
[59] Fix | Delete
*
[60] Fix | Delete
* @since 4.2.0
[61] Fix | Delete
* @private
[62] Fix | Delete
*/
[63] Fix | Delete
function load() {
[64] Fix | Delete
if ( loaded ) {
[65] Fix | Delete
return;
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
// Ensure twemoji is available on the global window before proceeding.
[69] Fix | Delete
if ( typeof window.twemoji === 'undefined' ) {
[70] Fix | Delete
// Break if waiting for longer than 30 seconds.
[71] Fix | Delete
if ( count > 600 ) {
[72] Fix | Delete
return;
[73] Fix | Delete
}
[74] Fix | Delete
[75] Fix | Delete
// Still waiting.
[76] Fix | Delete
window.clearTimeout( timer );
[77] Fix | Delete
timer = window.setTimeout( load, 50 );
[78] Fix | Delete
count++;
[79] Fix | Delete
[80] Fix | Delete
return;
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
twemoji = window.twemoji;
[84] Fix | Delete
loaded = true;
[85] Fix | Delete
[86] Fix | Delete
// Initialize the mutation observer, which checks all added nodes for
[87] Fix | Delete
// replaceable emoji characters.
[88] Fix | Delete
if ( MutationObserver ) {
[89] Fix | Delete
new MutationObserver( function( mutationRecords ) {
[90] Fix | Delete
var i = mutationRecords.length,
[91] Fix | Delete
addedNodes, removedNodes, ii, node;
[92] Fix | Delete
[93] Fix | Delete
while ( i-- ) {
[94] Fix | Delete
addedNodes = mutationRecords[ i ].addedNodes;
[95] Fix | Delete
removedNodes = mutationRecords[ i ].removedNodes;
[96] Fix | Delete
ii = addedNodes.length;
[97] Fix | Delete
[98] Fix | Delete
/*
[99] Fix | Delete
* Checks if an image has been replaced by a text element
[100] Fix | Delete
* with the same text as the alternate description of the replaced image.
[101] Fix | Delete
* (presumably because the image could not be loaded).
[102] Fix | Delete
* If it is, do absolutely nothing.
[103] Fix | Delete
*
[104] Fix | Delete
* Node type 3 is a TEXT_NODE.
[105] Fix | Delete
*
[106] Fix | Delete
* @link https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
[107] Fix | Delete
*/
[108] Fix | Delete
if (
[109] Fix | Delete
ii === 1 && removedNodes.length === 1 &&
[110] Fix | Delete
addedNodes[0].nodeType === 3 &&
[111] Fix | Delete
removedNodes[0].nodeName === 'IMG' &&
[112] Fix | Delete
addedNodes[0].data === removedNodes[0].alt &&
[113] Fix | Delete
'load-failed' === removedNodes[0].getAttribute( 'data-error' )
[114] Fix | Delete
) {
[115] Fix | Delete
return;
[116] Fix | Delete
}
[117] Fix | Delete
[118] Fix | Delete
// Loop through all the added nodes.
[119] Fix | Delete
while ( ii-- ) {
[120] Fix | Delete
node = addedNodes[ ii ];
[121] Fix | Delete
[122] Fix | Delete
// Node type 3 is a TEXT_NODE.
[123] Fix | Delete
if ( node.nodeType === 3 ) {
[124] Fix | Delete
if ( ! node.parentNode ) {
[125] Fix | Delete
continue;
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
if ( ie11 ) {
[129] Fix | Delete
/*
[130] Fix | Delete
* IE 11's implementation of MutationObserver is buggy.
[131] Fix | Delete
* It unnecessarily splits text nodes when it encounters a HTML
[132] Fix | Delete
* template interpolation symbol ( "{{", for example ). So, we
[133] Fix | Delete
* join the text nodes back together as a work-around.
[134] Fix | Delete
*
[135] Fix | Delete
* Node type 3 is a TEXT_NODE.
[136] Fix | Delete
*/
[137] Fix | Delete
while( node.nextSibling && 3 === node.nextSibling.nodeType ) {
[138] Fix | Delete
node.nodeValue = node.nodeValue + node.nextSibling.nodeValue;
[139] Fix | Delete
node.parentNode.removeChild( node.nextSibling );
[140] Fix | Delete
}
[141] Fix | Delete
}
[142] Fix | Delete
[143] Fix | Delete
node = node.parentNode;
[144] Fix | Delete
}
[145] Fix | Delete
[146] Fix | Delete
/*
[147] Fix | Delete
* If the class name of a non-element node contains 'wp-exclude-emoji' ignore it.
[148] Fix | Delete
*
[149] Fix | Delete
* Node type 1 is an ELEMENT_NODE.
[150] Fix | Delete
*/
[151] Fix | Delete
if ( ! node || node.nodeType !== 1 ||
[152] Fix | Delete
( node.className && typeof node.className === 'string' && node.className.indexOf( 'wp-exclude-emoji' ) !== -1 ) ) {
[153] Fix | Delete
[154] Fix | Delete
continue;
[155] Fix | Delete
}
[156] Fix | Delete
[157] Fix | Delete
if ( test( node.textContent ) ) {
[158] Fix | Delete
parse( node );
[159] Fix | Delete
}
[160] Fix | Delete
}
[161] Fix | Delete
}
[162] Fix | Delete
} ).observe( document.body, {
[163] Fix | Delete
childList: true,
[164] Fix | Delete
subtree: true
[165] Fix | Delete
} );
[166] Fix | Delete
}
[167] Fix | Delete
[168] Fix | Delete
parse( document.body );
[169] Fix | Delete
}
[170] Fix | Delete
[171] Fix | Delete
/**
[172] Fix | Delete
* Tests if a text string contains emoji characters.
[173] Fix | Delete
*
[174] Fix | Delete
* @since 4.3.0
[175] Fix | Delete
*
[176] Fix | Delete
* @memberOf wp.emoji
[177] Fix | Delete
*
[178] Fix | Delete
* @param {string} text The string to test.
[179] Fix | Delete
*
[180] Fix | Delete
* @return {boolean} Whether the string contains emoji characters.
[181] Fix | Delete
*/
[182] Fix | Delete
function test( text ) {
[183] Fix | Delete
// Single char. U+20E3 to detect keycaps. U+00A9 "copyright sign" and U+00AE "registered sign" not included.
[184] Fix | Delete
var single = /[\u203C\u2049\u20E3\u2122\u2139\u2194-\u2199\u21A9\u21AA\u2300\u231A\u231B\u2328\u2388\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638\u2639\u263A\u2648-\u2653\u2660\u2663\u2665\u2666\u2668\u267B\u267F\u2692\u2693\u2694\u2696\u2697\u2699\u269B\u269C\u26A0\u26A1\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753\u2754\u2755\u2757\u2763\u2764\u2795\u2796\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05\u2B06\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]/,
[185] Fix | Delete
// Surrogate pair range. Only tests for the second half.
[186] Fix | Delete
pair = /[\uDC00-\uDFFF]/;
[187] Fix | Delete
[188] Fix | Delete
if ( text ) {
[189] Fix | Delete
return pair.test( text ) || single.test( text );
[190] Fix | Delete
}
[191] Fix | Delete
[192] Fix | Delete
return false;
[193] Fix | Delete
}
[194] Fix | Delete
[195] Fix | Delete
/**
[196] Fix | Delete
* Parses any emoji characters into Twemoji images.
[197] Fix | Delete
*
[198] Fix | Delete
* - When passed an element the emoji characters are replaced inline.
[199] Fix | Delete
* - When passed a string the emoji characters are replaced and the result is
[200] Fix | Delete
* returned.
[201] Fix | Delete
*
[202] Fix | Delete
* @since 4.2.0
[203] Fix | Delete
*
[204] Fix | Delete
* @memberOf wp.emoji
[205] Fix | Delete
*
[206] Fix | Delete
* @param {HTMLElement|string} object The element or string to parse.
[207] Fix | Delete
* @param {Object} args Additional options for Twemoji.
[208] Fix | Delete
*
[209] Fix | Delete
* @return {HTMLElement|string} A string where all emoji are now image tags of
[210] Fix | Delete
* emoji. Or the element that was passed as the first argument.
[211] Fix | Delete
*/
[212] Fix | Delete
function parse( object, args ) {
[213] Fix | Delete
var params;
[214] Fix | Delete
[215] Fix | Delete
/*
[216] Fix | Delete
* If the browser has full support, twemoji is not loaded or our
[217] Fix | Delete
* object is not what was expected, we do not parse anything.
[218] Fix | Delete
*/
[219] Fix | Delete
if ( settings.supports.everything || ! twemoji || ! object ||
[220] Fix | Delete
( 'string' !== typeof object && ( ! object.childNodes || ! object.childNodes.length ) ) ) {
[221] Fix | Delete
[222] Fix | Delete
return object;
[223] Fix | Delete
}
[224] Fix | Delete
[225] Fix | Delete
// Compose the params for the twitter emoji library.
[226] Fix | Delete
args = args || {};
[227] Fix | Delete
params = {
[228] Fix | Delete
base: browserSupportsSvgAsImage() ? settings.svgUrl : settings.baseUrl,
[229] Fix | Delete
ext: browserSupportsSvgAsImage() ? settings.svgExt : settings.ext,
[230] Fix | Delete
className: args.className || 'emoji',
[231] Fix | Delete
callback: function( icon, options ) {
[232] Fix | Delete
// Ignore some standard characters that TinyMCE recommends in its character map.
[233] Fix | Delete
switch ( icon ) {
[234] Fix | Delete
case 'a9':
[235] Fix | Delete
case 'ae':
[236] Fix | Delete
case '2122':
[237] Fix | Delete
case '2194':
[238] Fix | Delete
case '2660':
[239] Fix | Delete
case '2663':
[240] Fix | Delete
case '2665':
[241] Fix | Delete
case '2666':
[242] Fix | Delete
return false;
[243] Fix | Delete
}
[244] Fix | Delete
[245] Fix | Delete
if ( settings.supports.everythingExceptFlag &&
[246] Fix | Delete
! /^1f1(?:e[6-9a-f]|f[0-9a-f])-1f1(?:e[6-9a-f]|f[0-9a-f])$/.test( icon ) && // Country flags.
[247] Fix | Delete
! /^(1f3f3-fe0f-200d-1f308|1f3f4-200d-2620-fe0f)$/.test( icon ) // Rainbow and pirate flags.
[248] Fix | Delete
) {
[249] Fix | Delete
return false;
[250] Fix | Delete
}
[251] Fix | Delete
[252] Fix | Delete
return ''.concat( options.base, icon, options.ext );
[253] Fix | Delete
},
[254] Fix | Delete
attributes: function() {
[255] Fix | Delete
return {
[256] Fix | Delete
role: 'img'
[257] Fix | Delete
};
[258] Fix | Delete
},
[259] Fix | Delete
onerror: function() {
[260] Fix | Delete
if ( twemoji.parentNode ) {
[261] Fix | Delete
this.setAttribute( 'data-error', 'load-failed' );
[262] Fix | Delete
twemoji.parentNode.replaceChild( document.createTextNode( twemoji.alt ), twemoji );
[263] Fix | Delete
}
[264] Fix | Delete
}
[265] Fix | Delete
};
[266] Fix | Delete
[267] Fix | Delete
if ( typeof args.imgAttr === 'object' ) {
[268] Fix | Delete
params.attributes = function() {
[269] Fix | Delete
return args.imgAttr;
[270] Fix | Delete
};
[271] Fix | Delete
}
[272] Fix | Delete
[273] Fix | Delete
return twemoji.parse( object, params );
[274] Fix | Delete
}
[275] Fix | Delete
[276] Fix | Delete
/**
[277] Fix | Delete
* Initialize our emoji support, and set up listeners.
[278] Fix | Delete
*/
[279] Fix | Delete
if ( settings ) {
[280] Fix | Delete
if ( settings.DOMReady ) {
[281] Fix | Delete
load();
[282] Fix | Delete
} else {
[283] Fix | Delete
settings.readyCallback = load;
[284] Fix | Delete
}
[285] Fix | Delete
}
[286] Fix | Delete
[287] Fix | Delete
return {
[288] Fix | Delete
parse: parse,
[289] Fix | Delete
test: test
[290] Fix | Delete
};
[291] Fix | Delete
}
[292] Fix | Delete
[293] Fix | Delete
window.wp = window.wp || {};
[294] Fix | Delete
[295] Fix | Delete
/**
[296] Fix | Delete
* @namespace wp.emoji
[297] Fix | Delete
*/
[298] Fix | Delete
window.wp.emoji = new wpEmoji();
[299] Fix | Delete
[300] Fix | Delete
} )( window, window._wpemojiSettings );
[301] Fix | Delete
[302] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function