From 6368ee0c6a2c6ff1c8a5d00d369ed3369dd067d8 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Sun, 3 May 2015 19:07:31 +0000 Subject: [PATCH] Emoji: before parsing added nodes test if the text in them contains emoji chars. That speeds up the processing quite a bit. See #32125. git-svn-id: https://develop.svn.wordpress.org/trunk@32335 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/js/wp-emoji.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/js/wp-emoji.js b/src/wp-includes/js/wp-emoji.js index f41907865e..eed3fe389e 100644 --- a/src/wp-includes/js/wp-emoji.js +++ b/src/wp-includes/js/wp-emoji.js @@ -70,7 +70,7 @@ node = node.parentNode; } - if ( node && node.nodeType === 1 ) { + if ( node && node.nodeType === 1 && test( node.textContent ) ) { parse( node ); } } @@ -84,6 +84,22 @@ parse( document.body ); } + /** + * Test if a text string contains emoji characters + * + * @since 4.3.0 + * + * @param {String} text The string to test + * @returns Boolean + */ + function test( text ) { + if ( text && twemoji ) { + return twemoji.test( text ); + } + + return false; + } + /** * Given an element or string, parse any emoji characters into Twemoji images. * @@ -144,7 +160,8 @@ return { replaceEmoji: replaceEmoji, - parse: parse + parse: parse, + test: test }; }