2 ( function( window, settings ) {
4 var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver,
7 * Flag to determine if the browser and the OS support emoji.
13 supportsEmoji = false,
16 * Flag to determine if the browser and the OS support flag (two character) emoji.
22 supportsFlagEmoji = false,
25 * Flag to determine if we should replace emoji characters with images.
33 isIE8 = window.navigator.userAgent.indexOf( 'IE 8' ) !== -1,
40 * Runs when the document load event is fired, so we can do our first parse of the page.
45 if ( typeof window.twemoji === 'undefined' ) {
46 // Break if waiting for longer than 30 sec.
52 window.clearTimeout( timer );
53 timer = window.setTimeout( load, 50 );
59 twemoji = window.twemoji;
61 if ( MutationObserver ) {
62 new MutationObserver( function( mutationRecords ) {
63 var i = mutationRecords.length,
67 ii = mutationRecords[ i ].addedNodes.length;
70 node = mutationRecords[ i ].addedNodes[ ii ];
72 if ( node.nodeType === 3 ) {
73 node = node.parentNode;
76 if ( node && node.nodeType === 1 ) {
81 } ).observe( document.body, {
87 parse( document.body );
91 * Given an element or string, parse any emoji characters into Twemoji images.
95 * @param {HTMLElement|String} object The element or string to parse.
96 * @param {Object} args Additional options for Twemoji.
98 function parse( object, args ) {
99 if ( ! replaceEmoji ) {
105 return twemoji.parse( object, {
106 base: settings.baseUrl,
108 className: args.className || 'emoji',
109 imgAttr: args.imgAttr,
110 callback: function( icon, options ) {
111 // Ignore some standard characters that TinyMCE recommends in its character map.
124 if ( ! supportsFlagEmoji && supportsEmoji &&
125 ! /^1f1(?:e[6-9a-f]|f[0-9a-f])-1f1(?:e[6-9a-f]|f[0-9a-f])$/.test( icon ) ) {
130 return ''.concat( options.base, icon, options.ext );
135 // Load when the readyState changes to 'interactive', not 'complete'.
137 if ( ( ! isIE8 && 'interactive' === document.readyState ) || ( isIE8 && 'complete' === document.readyState ) ) {
143 * Initialize our emoji support, and set up listeners.
146 supportsEmoji = window._wpemojiSettings.supports.simple;
147 supportsFlagEmoji = window._wpemojiSettings.supports.flag;
148 replaceEmoji = ! supportsEmoji || ! supportsFlagEmoji;
150 if ( ( ! isIE8 && 'loading' === document.readyState ) || ( isIE8 && 'complete' !== document.readyState ) ) {
151 if ( document.addEventListener ) {
152 document.addEventListener( 'readystatechange', onLoad, false );
153 } else if ( document.attachEvent ) {
154 document.attachEvent( 'onreadystatechange', onLoad );
162 replaceEmoji: replaceEmoji,
167 window.wp = window.wp || {};
168 window.wp.emoji = new wpEmoji();
170 } )( window, window._wpemojiSettings );