~canonical-sysadmins/wordpress/4.8.1

« back to all changes in this revision

Viewing changes to wp-includes/js/wp-emoji-loader.js

  • Committer: Barry Price
  • Date: 2016-08-17 04:50:12 UTC
  • mfrom: (1.1.18 upstream)
  • Revision ID: barry.price@canonical.com-20160817045012-qfui81zhqnqv2ba9
Merge WP4.6 from upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
                var canvas = document.createElement( 'canvas' ),
15
15
                        context = canvas.getContext && canvas.getContext( '2d' ),
16
16
                        stringFromCharCode = String.fromCharCode,
17
 
                        tonedata, tone, tone2;
 
17
                        flag, flag2, tonedata, tone, tone2;
18
18
 
19
19
                if ( ! context || ! context.fillText ) {
20
20
                        return false;
40
40
                                 * to a larger image (4-5KB data URL).
41
41
                                 */
42
42
                                context.fillText( stringFromCharCode( 55356, 56806, 55356, 56826 ), 0, 0 );
43
 
                                return canvas.toDataURL().length > 3000;
 
43
                                if ( canvas.toDataURL().length < 3000 ) {
 
44
                                        return false;
 
45
                                }
 
46
 
 
47
                                context.clearRect( 0, 0, canvas.width, canvas.height );
 
48
 
 
49
                                /*
 
50
                                 * Test for rainbow flag compatibility. As the rainbow flag was added out of sequence with
 
51
                                 * the usual Unicode release cycle, some browsers support it, and some don't, even if their
 
52
                                 * Unicode support is up to date.
 
53
                                 *
 
54
                                 * To test for support, we try to render it, and compare the rendering to how it would look if
 
55
                                 * the browser doesn't render it correctly (white flag emoji + rainbow emoji).
 
56
                                 */
 
57
                                context.fillText( stringFromCharCode( 55356, 57331, 65039, 8205, 55356, 57096 ), 0, 0 );
 
58
                                flag = canvas.toDataURL();
 
59
 
 
60
                                context.clearRect( 0, 0, canvas.width, canvas.height );
 
61
 
 
62
                                context.fillText( stringFromCharCode( 55356, 57331, 55356, 57096 ), 0, 0 );
 
63
                                flag2 = canvas.toDataURL();
 
64
 
 
65
                                return flag !== flag2;
44
66
                        case 'diversity':
45
67
                                /*
46
68
                                 * This tests if the browser supports the Emoji Diversity specification, by rendering an
73
95
                                 */
74
96
                                context.fillText( stringFromCharCode( 55356, 57135 ), 0, 0 );
75
97
                                return context.getImageData( 16, 16, 1, 1 ).data[0] !== 0;
 
98
                        case 'unicode9':
 
99
                                /*
 
100
                                 * Do Unicode 9 emoji render?
 
101
                                 * ¯\_(ツ)_/¯
 
102
                                 */
 
103
                                context.fillText( stringFromCharCode( 55358, 56631 ), 0, 0 );
 
104
                                return context.getImageData( 16, 16, 1, 1 ).data[0] !== 0;
76
105
                }
77
106
 
78
107
                return false;
86
115
                document.getElementsByTagName( 'head' )[0].appendChild( script );
87
116
        }
88
117
 
89
 
        tests = Array( 'simple', 'flag', 'unicode8', 'diversity' );
 
118
        tests = Array( 'simple', 'flag', 'unicode8', 'diversity', 'unicode9' );
90
119
 
91
120
        settings.supports = {
92
121
                everything: true,