WordPress.org

Make WordPress Core

Changeset 36160


Ignore:
Timestamp:
01/03/2016 04:25:52 AM (4 years ago)
Author:
pento
Message:

Emoji: Add a test to the emoji loader, to see if the browser supports emoji diversity. If it doesn't, fall back to twemoji.

See #33592.

Location:
trunk/src/wp-includes/js
Files:
2 edited

Legend:

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

    r35606 r36160  
    1313    function browserSupportsEmoji( type ) {
    1414        var canvas = document.createElement( 'canvas' ),
    15             context = canvas.getContext && canvas.getContext( '2d' );
     15            context = canvas.getContext && canvas.getContext( '2d' ),
     16            tone;
    1617
    1718        if ( ! context || ! context.fillText ) {
     
    3940            context.fillText( String.fromCharCode( 55356, 56806, 55356, 56826 ), 0, 0 );
    4041            return canvas.toDataURL().length > 3000;
     42        } else if ( 'diversity' === type ) {
     43            /*
     44             * This tests if the browser supports the Emoji Diversity specification, by rendering an
     45             * emoji with no skin tone specified (in this case, Santa). It then adds a skin tone, and
     46             * compares if the emoji rendering has changed.
     47             */
     48            context.fillText( String.fromCharCode( 55356, 57221 ), 0, 0 );
     49            tone = context.getImageData( 16, 16, 1, 1 ).data.toString();
     50            context.fillText( String.fromCharCode( 55356, 57221, 55356, 57343 ), 0, 0 );
     51            // Chrome has issues comparing arrays, so we compare it as a  string, instead.
     52            return tone !== context.getImageData( 16, 16, 1, 1 ).data.toString();
    4153        } else {
    4254            if ( 'simple' === type ) {
     
    6779
    6880    settings.supports = {
    69         simple:   browserSupportsEmoji( 'simple' ),
    70         flag:     browserSupportsEmoji( 'flag' ),
    71         unicode8: browserSupportsEmoji( 'unicode8' )
     81        simple:    browserSupportsEmoji( 'simple' ),
     82        flag:      browserSupportsEmoji( 'flag' ),
     83        unicode8:  browserSupportsEmoji( 'unicode8' ),
     84        diversity: browserSupportsEmoji( 'diversity' )
    7285    };
    7386
     
    7790    };
    7891
    79     if ( ! settings.supports.simple || ! settings.supports.flag || ! settings.supports.unicode8 ) {
     92    if ( ! settings.supports.simple || ! settings.supports.flag || ! settings.supports.unicode8 || ! settings.supports.diversity ) {
    8093        ready = function() {
    8194            settings.readyCallback();
  • trunk/src/wp-includes/js/wp-emoji.js

    r35637 r36160  
    150150                    }
    151151
    152                     if ( ! settings.supports.flag && settings.supports.simple && settings.supports.unicode8 &&
     152                    if ( ! settings.supports.flag && settings.supports.simple && settings.supports.unicode8 && settings.supports.diversity &&
    153153                        ! /^1f1(?:e[6-9a-f]|f[0-9a-f])-1f1(?:e[6-9a-f]|f[0-9a-f])$/.test( icon ) ) {
    154154
     
    179179         */
    180180        if ( settings ) {
    181             replaceEmoji = ! settings.supports.simple || ! settings.supports.flag || ! settings.supports.unicode8;
     181            replaceEmoji = ! settings.supports.simple || ! settings.supports.flag || ! settings.supports.unicode8 || ! settings.supports.diversity;
    182182
    183183            if ( settings.DOMReady ) {
Note: See TracChangeset for help on using the changeset viewer.