From 5a0564bb8fa52cae8b6b13a6f2f562b7c9d56610 Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Tue, 24 Mar 2015 23:32:23 +0000 Subject: [PATCH] Emoji: Instead of loading the emoji JS files automatically, we now include a small JS shim in the header, to test if the user's browser needs Twemoji. It then loads the emoji JS files only if they're needed. Props pento, azaozz. Fixes #31701. git-svn-id: https://develop.svn.wordpress.org/trunk@31875 602fd350-edb4-49c9-b593-d223f7449a82 --- Gruntfile.js | 21 ++++++ package.json | 1 + src/wp-includes/default-filters.php | 1 + src/wp-includes/formatting.php | 69 +++++++++++++++++- src/wp-includes/js/wp-emoji-loader.js | 76 ++++++++++++++++++++ src/wp-includes/js/wp-emoji.js | 100 +++++++++++--------------- src/wp-includes/script-loader.php | 23 ------ 7 files changed, 207 insertions(+), 84 deletions(-) create mode 100755 src/wp-includes/js/wp-emoji-loader.js diff --git a/Gruntfile.js b/Gruntfile.js index eb5c6d7be9..f4436f2ded 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -464,6 +464,19 @@ module.exports = function(grunt) { BUILD_DIR + 'wp-includes/js/tinymce/plugins/*/plugin.min.js' ], dest: BUILD_DIR + 'wp-includes/js/tinymce/wp-tinymce.js' + }, + emoji: { + options: { + separator: '\n', + process: function( src, filepath ) { + return '// Source: ' + filepath.replace( BUILD_DIR, '' ) + '\n' + src; + } + }, + src: [ + BUILD_DIR + 'wp-includes/js/twemoji.min.js', + BUILD_DIR + 'wp-includes/js/wp-emoji.min.js' + ], + dest: BUILD_DIR + 'wp-includes/js/wp-emoji-release.min.js' } }, compress: { @@ -502,6 +515,12 @@ module.exports = function(grunt) { dest: SOURCE_DIR } }, + includes: { + emoji: { + src: BUILD_DIR + 'wp-includes/formatting.php', + dest: '.' + } + }, _watch: { all: { files: [ @@ -615,6 +634,8 @@ module.exports = function(grunt) { 'concat:tinymce', 'compress:tinymce', 'clean:tinymce', + 'concat:emoji', + 'includes:emoji', 'jsvalidate:build' ] ); diff --git a/package.json b/package.json index ae3b09cda4..17f74a8b9d 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "grunt-contrib-qunit": "~0.5.2", "grunt-contrib-uglify": "~0.8.0", "grunt-contrib-watch": "~0.6.1", + "grunt-includes": "~0.4.5", "grunt-jsvalidate": "~0.2.2", "grunt-legacy-util": "^0.2.0", "grunt-patch-wordpress": "~0.3.0", diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php index 69905be1c3..449d971cb8 100644 --- a/src/wp-includes/default-filters.php +++ b/src/wp-includes/default-filters.php @@ -213,6 +213,7 @@ add_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 ); add_action( 'wp_head', 'locale_stylesheet' ); add_action( 'publish_future_post', 'check_and_publish_future_post', 10, 1 ); add_action( 'wp_head', 'noindex', 1 ); +add_action( 'wp_head', 'print_emoji_detection_script', 7 ); add_action( 'wp_head', 'wp_print_styles', 8 ); add_action( 'wp_head', 'wp_print_head_scripts', 9 ); add_action( 'wp_head', 'wp_generator' ); diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php index f14ef866db..6a3a66e7af 100644 --- a/src/wp-includes/formatting.php +++ b/src/wp-includes/formatting.php @@ -4082,6 +4082,13 @@ function wp_spaces_regexp() { * @since 4.2.0 */ function print_emoji_styles() { + static $printed = false; + + if ( $printed ) { + return; + } + + $printed = true; ?>