Make WordPress Core

Ticket #31701: 31701.7.diff

File 31701.7.diff, 12.0 KB (added by pento, 10 years ago)
  • Gruntfile.js

     
    464464                                        BUILD_DIR + 'wp-includes/js/tinymce/plugins/*/plugin.min.js'
    465465                                ],
    466466                                dest: BUILD_DIR + 'wp-includes/js/tinymce/wp-tinymce.js'
     467                        },
     468                        emoji: {
     469                                options: {
     470                                        separator: '\n',
     471                                        process: function( src, filepath ) {
     472                                                return '// Source: ' + filepath.replace( BUILD_DIR, '' ) + '\n' + src;
     473                                        }
     474                                },
     475                                src: [
     476                                        BUILD_DIR + 'wp-includes/js/twemoji.min.js',
     477                                        BUILD_DIR + 'wp-includes/js/wp-emoji.min.js'
     478                                ],
     479                                dest: BUILD_DIR + 'wp-includes/js/wp-emoji-release.min.js'
    467480                        }
    468481                },
    469482                compress: {
     
    502515                                dest: SOURCE_DIR
    503516                        }
    504517                },
     518                includes: {
     519                        emoji: {
     520                                src: BUILD_DIR + 'wp-includes/formatting.php',
     521                                dest: '.'
     522                        }
     523                },
    505524                _watch: {
    506525                        all: {
    507526                                files: [
     
    615634                'concat:tinymce',
    616635                'compress:tinymce',
    617636                'clean:tinymce',
     637                'concat:emoji',
     638                'includes:emoji',
    618639                'jsvalidate:build'
    619640        ] );
    620641
  • package.json

     
    2222    "grunt-contrib-qunit": "~0.5.2",
    2323    "grunt-contrib-uglify": "~0.8.0",
    2424    "grunt-contrib-watch": "~0.6.1",
     25    "grunt-includes": "~0.4.5",
    2526    "grunt-jsvalidate": "~0.2.2",
    2627    "grunt-legacy-util": "^0.2.0",
    2728    "grunt-patch-wordpress": "~0.3.0",
  • src/wp-includes/default-filters.php

     
    224224add_action( 'init',                'check_theme_switched',            99    );
    225225add_action( 'after_switch_theme',  '_wp_sidebars_changed'                   );
    226226add_action( 'wp_print_styles',     'print_emoji_styles'                     );
     227add_action( 'wp_print_scripts',    'print_emoji_detection_script'           );
    227228
    228229if ( isset( $_GET['replytocom'] ) )
    229230    add_action( 'wp_head', 'wp_no_robots' );
  • src/wp-includes/formatting.php

     
    40824082 * @since 4.2.0
    40834083 */
    40844084function print_emoji_styles() {
     4085        static $printed = false;
     4086        if ( $printed ) {
     4087                return;
     4088        }
     4089        $printed = true;
    40854090?>
    40864091<style type="text/css">
    40874092img.wp-smiley,
     
    41004105<?php
    41014106}
    41024107
     4108function print_emoji_detection_script() {
     4109        global $wp_version;
     4110
     4111        static $printed = false;
     4112        if ( $printed ) {
     4113                return;
     4114        }
     4115        $printed = true;
     4116
     4117        $settings = array(
     4118                /**
     4119                 * Filter the URL where emoji images are hosted.
     4120                 *
     4121                 * @since 4.2.0
     4122                 *
     4123                 * @param string The emoji base URL.
     4124                 */
     4125                'baseUrl' => apply_filters( 'emoji_url', set_url_scheme( '//s0.wp.com/wp-content/mu-plugins/emoji/twemoji/72x72' ) ),
     4126
     4127                /**
     4128                 * Filter the extension of the emoji files.
     4129                 *
     4130                 * @since 4.2.0
     4131                 *
     4132                 * @param string The emoji extension. Default .png.
     4133                 */
     4134                'ext'     => apply_filters( 'emoji_ext', '.png' ),
     4135                'ver'     => $wp_version,
     4136        );
     4137
     4138        if ( SCRIPT_DEBUG ) {
     4139                $settings['js'] = array(
     4140                        'wpemoji' => includes_url( "js/wp-emoji.js" ),
     4141                        'twemoji' => includes_url( "js/twemoji.js" ),
     4142                );
     4143        } else {
     4144                $settings['js'] = array(
     4145                        'wpemoji' => includes_url( "js/wp-emoji-release.min.js" ),
     4146                );
     4147        }
     4148
     4149        if ( SCRIPT_DEBUG ) {
     4150        ?>
     4151                <script type="text/javascript">
     4152                        window._wpemojiSettings = <?php echo wp_json_encode( $settings ); ?>;
     4153                        <?php readfile( ABSPATH . WPINC . "/js/wp-emoji-loader.js" ); ?>
     4154                </script>
     4155        <?php
     4156        } else {
     4157        ?>
     4158                <script type="text/javascript">
     4159                        window._wpemojiSettings = <?php echo wp_json_encode( $settings ); ?>;
     4160                        include "js/wp-emoji-loader.min.js"
     4161                </script>
     4162        <?php
     4163        }
     4164}
     4165
    41034166/**
    41044167 * Convert any 4 byte emoji in a string to their equivalent HTML entity.
    41054168 *
  • src/wp-includes/js/wp-emoji-loader.js

     
     1( function( window ) {
     2        /**
     3         * Detect if the browser supports rendering emoji or flag emoji. Flag emoji are a single glyph
     4         * made of two characters, so some browsers (notably, Firefox OS X) don't support them.
     5         *
     6         * @since 4.2.0
     7         *
     8         * @param type {String} Whether to test for support of "simple" or "flag" emoji.
     9         * @return {Boolean} True if the browser can render emoji, false if it cannot.
     10         */
     11        var browserSupportsEmoji = function( type ) {
     12                var canvas = document.createElement( 'canvas' ),
     13                        context = canvas.getContext && canvas.getContext( '2d' );
     14
     15                if ( ! context || ! context.fillText ) {
     16                        return false;
     17                }
     18
     19                /*
     20                 * Chrome on OS X added native emoji rendering in M41. Unfortunately,
     21                 * it doesn't work when the font is bolder than 500 weight. So, we
     22                 * check for bold rendering support to avoid invisible emoji in Chrome.
     23                 */
     24                context.textBaseline = 'top';
     25                context.font = '600 32px Arial';
     26
     27                if ( type === 'flag' ) {
     28                        /*
     29                         * This works because the image will be one of three things:
     30                         * - Two empty squares, if the browser doesn't render emoji
     31                         * - Two squares with 'G' and 'B' in them, if the browser doesn't render flag emoji
     32                         * - The British flag
     33                         *
     34                         * The first two will encode to small images (1-2KB data URLs), the third will encode
     35                         * to a larger image (4-5KB data URL).
     36                         */
     37                        context.fillText( String.fromCharCode( 55356, 56812, 55356, 56807 ), 0, 0 );
     38                        return canvas.toDataURL().length > 3000;
     39                } else {
     40                        /*
     41                         * This creates a smiling emoji, and checks to see if there is any image data in the
     42                         * center pixel. In browsers that don't support emoji, the character will be rendered
     43                         * as an empty square, so the center pixel will be blank.
     44                         */
     45                        context.fillText( String.fromCharCode( 55357, 56835 ), 0, 0 );
     46                        return context.getImageData( 16, 16, 1, 1 ).data[0] !== 0;
     47                }
     48        };
     49        window._wpemojiSettings.supports = {
     50                simple: browserSupportsEmoji( 'simple' ),
     51                flag:   browserSupportsEmoji( 'flag' )
     52        };
     53
     54        if ( ! window._wpemojiSettings.supports.simple || ! window._wpemojiSettings.supports.flag ) {
     55                var src;
     56                if ( window._wpemojiSettings.js.twemoji ) {
     57                        src = window._wpemojiSettings.js.twemoji;
     58                } else {
     59                        src = window._wpemojiSettings.js.wpemoji;
     60                }
     61
     62                var script = document.createElement( 'script' );
     63                script.src = src + '?ver=' + window._wpemojiSettings.ver;
     64                script.type = 'text/javascript';
     65                document.getElementsByTagName( 'head' )[0].appendChild( script );
     66
     67                if ( window._wpemojiSettings.js.twemoji ) {
     68                        waitForTwemoji();
     69                }
     70        }
     71
     72        function waitForTwemoji() {
     73                if ( ! window.twemoji ) {
     74                        // Still waiting.
     75                        window.setTimeout( waitForTwemoji, 50 );
     76                        return;
     77                }
     78
     79                var script = document.createElement( 'script' );
     80                script.src = window._wpemojiSettings.js.wpemoji + '?ver=' + window._wpemojiSettings.ver;
     81                script.type = 'text/javascript';
     82                document.getElementsByTagName( 'head' )[0].appendChild( script );
     83        }
     84
     85} )( window );
  • src/wp-includes/js/wp-emoji.js

    Property changes on: src/wp-includes/js/wp-emoji-loader.js
    ___________________________________________________________________
    Added: svn:executable
    ## -0,0 +1 ##
    +*
    \ No newline at end of property
     
    6666                }
    6767
    6868                /**
    69                  * Detect if the browser supports rendering emoji or flag emoji. Flag emoji are a single glyph
    70                  * made of two characters, so some browsers (notably, Firefox OS X) don't support them.
    71                  *
    72                  * @since 4.2.0
    73                  *
    74                  * @param type {String} Whether to test for support of "simple" or "flag" emoji.
    75                  * @return {Boolean} True if the browser can render emoji, false if it cannot.
    76                  */
    77                 function browserSupportsEmoji( type ) {
    78                         var canvas = document.createElement( 'canvas' ),
    79                                 context = canvas.getContext && canvas.getContext( '2d' );
    80 
    81                         if ( ! context || ! context.fillText ) {
    82                                 return false;
    83                         }
    84 
    85                         /*
    86                          * Chrome on OS X added native emoji rendering in M41. Unfortunately,
    87                          * it doesn't work when the font is bolder than 500 weight. So, we
    88                          * check for bold rendering support to avoid invisible emoji in Chrome.
    89                          */
    90                         context.textBaseline = 'top';
    91                         context.font = '600 32px Arial';
    92 
    93                         if ( type === 'flag' ) {
    94                                 /*
    95                                  * This works because the image will be one of three things:
    96                                  * - Two empty squares, if the browser doesn't render emoji
    97                                  * - Two squares with 'G' and 'B' in them, if the browser doesn't render flag emoji
    98                                  * - The British flag
    99                                  *
    100                                  * The first two will encode to small images (1-2KB data URLs), the third will encode
    101                                  * to a larger image (4-5KB data URL).
    102                                  */
    103                                 context.fillText( String.fromCharCode( 55356, 56812, 55356, 56807 ), 0, 0 );
    104                                 return canvas.toDataURL().length > 3000;
    105                         } else {
    106                                 /*
    107                                  * This creates a smiling emoji, and checks to see if there is any image data in the
    108                                  * center pixel. In browsers that don't support emoji, the character will be rendered
    109                                  * as an empty square, so the center pixel will be blank.
    110                                  */
    111                                 context.fillText( String.fromCharCode( 55357, 56835 ), 0, 0 );
    112                                 return context.getImageData( 16, 16, 1, 1 ).data[0] !== 0;
    113                         }
    114                 }
    115 
    116                 /**
    11769                 * Given an element or string, parse any emoji characters into Twemoji images.
    11870                 *
    11971                 * @since 4.2.0
     
    161113                 * Initialize our emoji support, and set up listeners.
    162114                 */
    163115                if ( twemoji && settings ) {
    164                         supportsEmoji = browserSupportsEmoji();
    165                         supportsFlagEmoji = browserSupportsEmoji( 'flag' );
     116                        supportsEmoji = window._wpemojiSettings.supports.simple;
     117                        supportsFlagEmoji = window._wpemojiSettings.supports.flag;
    166118                        replaceEmoji = ! supportsEmoji || ! supportsFlagEmoji;
    167119
    168                         if ( window.addEventListener ) {
    169                                 window.addEventListener( 'load', load, false );
    170                         } else if ( window.attachEvent ) {
    171                                 window.attachEvent( 'onload', load );
     120                        if ( 'loading' == document.readyState ) {
     121                                if ( window.addEventListener ) {
     122                                        window.addEventListener( 'readystatechange', load, false );
     123                                } else if ( window.attachEvent ) {
     124                                        window.attachEvent( 'onreadystatechange', load );
     125                                }
     126                        } else {
     127                                load();
    172128                        }
    173129                }
    174130
    175131                return {
    176                         browserSupportsEmoji: browserSupportsEmoji,
    177132                        replaceEmoji: replaceEmoji,
    178133                        parse: parse
    179134                };
  • src/wp-includes/script-loader.php

     
    424424        $scripts->add( 'media-audiovideo', "/wp-includes/js/media/audio-video$suffix.js", array( 'media-editor' ), false, 1 );
    425425        $scripts->add( 'mce-view', "/wp-includes/js/mce-view$suffix.js", array( 'shortcode', 'media-models', 'media-audiovideo', 'wp-playlist' ), false, 1 );
    426426
    427         $scripts->add( 'twemoji', "/wp-includes/js/twemoji$suffix.js", array(), '1.3.2', 1 );
    428         $scripts->add( 'emoji', "/wp-includes/js/wp-emoji$suffix.js", array( 'twemoji' ), false, 1 );
    429         did_action( 'init' ) && $scripts->localize( 'emoji', '_wpemojiSettings', array(
    430                 /**
    431                  * Filter the URL where emoji images are hosted.
    432                  *
    433                  * @since 4.2.0
    434                  *
    435                  * @param string The emoji base URL.
    436                  */
    437                 'baseUrl' => apply_filters( 'emoji_url', '//s0.wp.com/wp-content/mu-plugins/emoji/twemoji/72x72' ),
    438 
    439                 /**
    440                  * Filter the extension of the emoji files.
    441                  *
    442                  * @since 4.2.0
    443                  *
    444                  * @param string The emoji extension. Default .png.
    445                  */
    446                 'ext'      => apply_filters( 'emoji_ext', '.png' ),
    447         ) );
    448         $scripts->enqueue( 'emoji' );
    449 
    450427        if ( is_admin() ) {
    451428                $scripts->add( 'admin-tags', "/wp-admin/js/tags$suffix.js", array( 'jquery', 'wp-ajax-response' ), false, 1 );
    452429                did_action( 'init' ) && $scripts->localize( 'admin-tags', 'tagsl10n', array(