From 86c521d86884a787d2a45f25840461b9ae46ca45 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Thu, 12 Mar 2015 19:52:13 +0000 Subject: [PATCH] Emoji: - Patch twemoji.js to prevent infinite loop. - Fix some `undefined` errors in old IE. Props iseulde. See #31242. git-svn-id: https://develop.svn.wordpress.org/trunk@31756 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/js/twemoji.js | 6 +++--- src/wp-includes/js/wp-emoji.js | 8 +++++--- src/wp-includes/script-loader.php | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/wp-includes/js/twemoji.js b/src/wp-includes/js/twemoji.js index a985f1e098..a80cd453c3 100644 --- a/src/wp-includes/js/twemoji.js +++ b/src/wp-includes/js/twemoji.js @@ -370,10 +370,10 @@ twemoji = (function ( } } fragment.appendChild(img || createText(alt)); - img = null; } // is there actually anything to replace in here ? - if (0 < i) { + if (img) { + img = null; // any text left to be added ? if (i < text.length) { fragment.appendChild( @@ -516,4 +516,4 @@ twemoji = (function ( return r.join(sep || '-'); } -}()); \ No newline at end of file +}()); diff --git a/src/wp-includes/js/wp-emoji.js b/src/wp-includes/js/wp-emoji.js index 7b36505cd1..73cfba389d 100644 --- a/src/wp-includes/js/wp-emoji.js +++ b/src/wp-includes/js/wp-emoji.js @@ -1,6 +1,8 @@ window.wp = window.wp || {}; ( function( window, wp, twemoji, settings ) { + var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver; + var emoji = { /** * Flag to determine if we should parse all emoji characters into Twemoji images. @@ -68,7 +70,7 @@ window.wp = window.wp || {}; node = node.parentNode; } - if ( node.nodeType === 1 ) { + if ( node && node.nodeType === 1 ) { emoji.parse( node ); } } @@ -95,7 +97,7 @@ window.wp = window.wp || {}; var canvas = document.createElement( 'canvas' ), context = canvas.getContext && canvas.getContext( '2d' ); - if ( ! context.fillText ) { + if ( ! context || ! context.fillText ) { return false; } @@ -123,7 +125,7 @@ window.wp = window.wp || {}; var canvas = document.createElement( 'canvas' ), context = canvas.getContext && canvas.getContext( '2d' ); - if ( ! context.fillText ) { + if ( ! context || ! context.fillText ) { return false; } diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index 78062d7470..7bd909698b 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -434,7 +434,7 @@ function wp_default_scripts( &$scripts ) { * * @param string The emoji base URL. */ - 'baseUrl' => apply_filters( 'emoji_url', '//s0.wp.com/wp-content/mu-plugins/emoji/twemoji/72x72/' ), + 'baseUrl' => apply_filters( 'emoji_url', '//s0.wp.com/wp-content/mu-plugins/emoji/twemoji/72x72' ), /** * Filter the extension of the emoji files. *