diff --git src/js/_enqueues/wp/emoji.js src/js/_enqueues/wp/emoji.js
index 46cddd02be..b240560b52 100644
|
|
|
1 | 1 | |
2 | 2 | ( function( window, settings ) { |
| 3 | /** |
| 4 | * Replaces text with Twitter emojis. |
| 5 | * |
| 6 | * Description. (use period) |
| 7 | * |
| 8 | * @since 4.2.0 |
| 9 | * @access private |
| 10 | * |
| 11 | * @class |
| 12 | * |
| 13 | * @see Twitter Emoji library |
| 14 | * @link https://github.com/twitter/twemoji |
| 15 | * |
| 16 | * @return {Object} The wpEmoji parse and test functions. |
| 17 | */ |
3 | 18 | function wpEmoji() { |
4 | 19 | var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver, |
5 | 20 | |
… |
… |
|
34 | 49 | /** |
35 | 50 | * Runs when the document load event is fired, so we can do our first parse of the page. |
36 | 51 | * |
| 52 | * Listens to all the DOM mutations and checks for added nodes that |
| 53 | * contain emoji characters and replaces those with twitter emoji |
| 54 | * images. |
| 55 | * |
37 | 56 | * @since 4.2.0 |
38 | 57 | */ |
39 | 58 | function load() { |
… |
… |
|
41 | 60 | return; |
42 | 61 | } |
43 | 62 | |
| 63 | // Ensure twemoji is available on the global window before proceeding. |
44 | 64 | if ( typeof window.twemoji === 'undefined' ) { |
45 | 65 | // Break if waiting for longer than 30 sec. |
46 | 66 | if ( count > 600 ) { |
… |
… |
|
58 | 78 | twemoji = window.twemoji; |
59 | 79 | loaded = true; |
60 | 80 | |
| 81 | // Initialize the mutation observer, which checks all added nodes for replaceable emoji characters. |
61 | 82 | if ( MutationObserver ) { |
62 | 83 | new MutationObserver( function( mutationRecords ) { |
63 | 84 | var i = mutationRecords.length, |
… |
… |
|
68 | 89 | removedNodes = mutationRecords[ i ].removedNodes; |
69 | 90 | ii = addedNodes.length; |
70 | 91 | |
| 92 | /* |
| 93 | * Checks if an image has been replaced by a text element |
| 94 | * with the same text as the alternate description of the replaced image. |
| 95 | * (presumably because the image could not be loaded). |
| 96 | * If it is, do absolutely nothing. |
| 97 | * |
| 98 | * Node type 3 is a TEXT_NODE. |
| 99 | * See: https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType |
| 100 | */ |
71 | 101 | if ( |
72 | 102 | ii === 1 && removedNodes.length === 1 && |
73 | 103 | addedNodes[0].nodeType === 3 && |
… |
… |
|
78 | 108 | return; |
79 | 109 | } |
80 | 110 | |
| 111 | // Loop through all the added nodes. |
81 | 112 | while ( ii-- ) { |
82 | 113 | node = addedNodes[ ii ]; |
83 | 114 | |
| 115 | // Node type 3 is a TEXT_NODE. |
84 | 116 | if ( node.nodeType === 3 ) { |
85 | 117 | if ( ! node.parentNode ) { |
86 | 118 | continue; |
… |
… |
|
92 | 124 | * It unnecessarily splits text nodes when it encounters a HTML |
93 | 125 | * template interpolation symbol ( "{{", for example ). So, we |
94 | 126 | * join the text nodes back together as a work-around. |
| 127 | * |
| 128 | * Node type 3 is a TEXT_NODE. |
95 | 129 | */ |
96 | 130 | while( node.nextSibling && 3 === node.nextSibling.nodeType ) { |
97 | 131 | node.nodeValue = node.nodeValue + node.nextSibling.nodeValue; |
… |
… |
|
102 | 136 | node = node.parentNode; |
103 | 137 | } |
104 | 138 | |
| 139 | /* |
| 140 | * If the class name of a non-element node contains 'wp-exclude-emoji' ignore it. |
| 141 | * |
| 142 | * Node type 1 is an ELEMENT_NODE. |
| 143 | */ |
105 | 144 | if ( ! node || node.nodeType !== 1 || |
106 | 145 | ( node.className && typeof node.className === 'string' && node.className.indexOf( 'wp-exclude-emoji' ) !== -1 ) ) { |
107 | 146 | |
… |
… |
|
155 | 194 | function parse( object, args ) { |
156 | 195 | var params; |
157 | 196 | |
| 197 | /* |
| 198 | * If the browser has full support, twemoji is not loaded or our |
| 199 | * object is not what was expected, we do not parse anything. |
| 200 | */ |
158 | 201 | if ( settings.supports.everything || ! twemoji || ! object || |
159 | 202 | ( 'string' !== typeof object && ( ! object.childNodes || ! object.childNodes.length ) ) ) { |
160 | 203 | |
161 | 204 | return object; |
162 | 205 | } |
163 | 206 | |
| 207 | // Compose the params for the twitter emoji library. |
164 | 208 | args = args || {}; |
165 | 209 | params = { |
166 | 210 | base: browserSupportsSvgAsImage() ? settings.svgUrl : settings.baseUrl, |