Make WordPress Core

Changeset 32335


Ignore:
Timestamp:
05/03/2015 07:07:31 PM (11 years ago)
Author:
azaozz
Message:

Emoji: before parsing added nodes test if the text in them contains emoji chars. That speeds up the processing quite a bit.
See #32125.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/js/wp-emoji.js

    r32334 r32335  
    7171                                                        }
    7272
    73                                                         if ( node && node.nodeType === 1 ) {
     73                                                        if ( node && node.nodeType === 1 && test( node.textContent ) ) {
    7474                                                                parse( node );
    7575                                                        }
    … …  
    8383
    8484                        parse( document.body );
     85                }
     86
     87                /**
     88                 * Test if a text string contains emoji characters
     89                 *
     90                 * @since 4.3.0
     91                 *
     92                 * @param {String} text The string to test
     93                 * @returns Boolean
     94                 */
     95                function test( text ) {
     96                        if ( text && twemoji ) {
     97                                return twemoji.test( text );
     98                        }
     99
     100                        return false;
    85101                }
    86102
    … …  
    145161                return {
    146162                        replaceEmoji: replaceEmoji,
    147                         parse: parse
     163                        parse: parse,
     164                        test: test
    148165                };
    149166        }
Note: See TracChangeset for help on using the changeset viewer.