| 4058 | function print_emoji_detection_script() { |
| 4059 | $settings = array( |
| 4060 | /** |
| 4061 | * Filter the URL where emoji images are hosted. |
| 4062 | * |
| 4063 | * @since 4.2.0 |
| 4064 | * |
| 4065 | * @param string The emoji base URL. |
| 4066 | */ |
| 4067 | 'baseUrl' => apply_filters( 'emoji_url', '//s0.wp.com/wp-content/mu-plugins/emoji/twemoji/72x72' ), |
| 4068 | |
| 4069 | /** |
| 4070 | * Filter the extension of the emoji files. |
| 4071 | * |
| 4072 | * @since 4.2.0 |
| 4073 | * |
| 4074 | * @param string The emoji extension. Default .png. |
| 4075 | */ |
| 4076 | 'ext' => apply_filters( 'emoji_ext', '.png' ), |
| 4077 | ); |
| 4078 | |
| 4079 | if ( SCRIPT_DEBUG ) { |
| 4080 | ?> |
| 4081 | <script type="text/javascript"> |
| 4082 | ( function( window ) { |
| 4083 | /** |
| 4084 | * Detect if the browser supports rendering emoji or flag emoji. Flag emoji are a single glyph |
| 4085 | * made of two characters, so some browsers (notably, Firefox OS X) don't support them. |
| 4086 | * |
| 4087 | * @since 4.2.0 |
| 4088 | * |
| 4089 | * @param type {String} Whether to test for support of "simple" or "flag" emoji. |
| 4090 | * @return {Boolean} True if the browser can render emoji, false if it cannot. |
| 4091 | */ |
| 4092 | browserSupportsEmoji = function( type ) { |
| 4093 | var canvas = document.createElement( 'canvas' ), |
| 4094 | context = canvas.getContext && canvas.getContext( '2d' ); |
| 4095 | |
| 4096 | if ( ! context || ! context.fillText ) { |
| 4097 | return false; |
| 4098 | } |
| 4099 | |
| 4100 | /* |
| 4101 | * Chrome on OS X added native emoji rendering in M41. Unfortunately, |
| 4102 | * it doesn't work when the font is bolder than 500 weight. So, we |
| 4103 | * check for bold rendering support to avoid invisible emoji in Chrome. |
| 4104 | */ |
| 4105 | context.textBaseline = 'top'; |
| 4106 | context.font = '600 32px Arial'; |
| 4107 | |
| 4108 | if ( type === 'flag' ) { |
| 4109 | /* |
| 4110 | * This works because the image will be one of three things: |
| 4111 | * - Two empty squares, if the browser doesn't render emoji |
| 4112 | * - Two squares with 'G' and 'B' in them, if the browser doesn't render flag emoji |
| 4113 | * - The British flag |
| 4114 | * |
| 4115 | * The first two will encode to small images (1-2KB data URLs), the third will encode |
| 4116 | * to a larger image (4-5KB data URL). |
| 4117 | */ |
| 4118 | context.fillText( String.fromCharCode( 55356, 56812, 55356, 56807 ), 0, 0 ); |
| 4119 | return canvas.toDataURL().length > 3000; |
| 4120 | } else { |
| 4121 | /* |
| 4122 | * This creates a smiling emoji, and checks to see if there is any image data in the |
| 4123 | * center pixel. In browsers that don't support emoji, the character will be rendered |
| 4124 | * as an empty square, so the center pixel will be blank. |
| 4125 | */ |
| 4126 | context.fillText( String.fromCharCode( 55357, 56835 ), 0, 0 ); |
| 4127 | return context.getImageData( 16, 16, 1, 1 ).data[0] !== 0; |
| 4128 | } |
| 4129 | } |
| 4130 | |
| 4131 | if ( ! browserSupportsEmoji( 'simple' ) || ! browserSupportsEmoji( 'flag' ) ) { |
| 4132 | var script = document.createElement( 'script' ); |
| 4133 | script.src = '/wp-includes/js/twemoji.js'; |
| 4134 | script.type = 'text/javascript'; |
| 4135 | document.getElementsByTagName( 'head' )[0].appendChild( script ); |
| 4136 | |
| 4137 | waitForTwemoji(); |
| 4138 | } |
| 4139 | |
| 4140 | function waitForTwemoji() { |
| 4141 | if ( ! window.twemoji ) { |
| 4142 | // Still waiting. |
| 4143 | window.setTimeout( waitForTwemoji, 50 ); |
| 4144 | } |
| 4145 | |
| 4146 | var script = document.createElement( 'script' ); |
| 4147 | script.src = '/wp-includes/js/wp-emoji.js'; |
| 4148 | script.type = 'text/javascript'; |
| 4149 | document.getElementsByTagName( 'head' )[0].appendChild( script ); |
| 4150 | } |
| 4151 | |
| 4152 | window._wpemojiSettings = <?php echo wp_json_encode( $settings ); ?>; |
| 4153 | } )( window ); |
| 4154 | </script> |
| 4155 | <?php |
| 4156 | } else { // ! SCRIPT_DEBUG |
| 4157 | ?> |
| 4158 | <script type="text/javascript"> |
| 4159 | // TODO: Minified version of the emoji detection script |
| 4160 | </script> |
| 4161 | <?php |
| 4162 | } |
| 4163 | } |
| 4164 | |