From 47fb9c7f3d282d4922db4dc6edd9d16c2009e1de Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Mon, 7 Jun 2021 23:07:57 +0000 Subject: [PATCH] TinyMCE: Fix initialization when the editor is in a postbox by delaying it until `document.readyState === 'complete'`. Props metalandcoffee, desrosj, patkemper, herrvigg, spikeuk1, dway, mkdgs, azaozz. Fixes #52133, #52050. Built from https://develop.svn.wordpress.org/trunk@51082 git-svn-id: http://core.svn.wordpress.org/trunk@50691 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-editor.php | 31 ++++++++++++++++++++++++------- wp-includes/version.php | 2 +- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/wp-includes/class-wp-editor.php b/wp-includes/class-wp-editor.php index 32f638240f..8812c770ab 100644 --- a/wp-includes/class-wp-editor.php +++ b/wp-includes/class-wp-editor.php @@ -1663,19 +1663,24 @@ final class _WP_Editors { ?> ( function() { - var init, id, $wrap; + var initialize = function() { + var init, id, inPostbox, $wrap; + var readyState = document.readyState; - if ( typeof tinymce !== 'undefined' ) { - if ( tinymce.Env.ie && tinymce.Env.ie < 11 ) { - tinymce.$( '.wp-editor-wrap ' ).removeClass( 'tmce-active' ).addClass( 'html-active' ); + if ( readyState !== 'complete' && readyState !== 'interactive' ) { return; } for ( id in tinyMCEPreInit.mceInit ) { - init = tinyMCEPreInit.mceInit[id]; - $wrap = tinymce.$( '#wp-' + id + '-wrap' ); + init = tinyMCEPreInit.mceInit[id]; + $wrap = tinymce.$( '#wp-' + id + '-wrap' ); + inPostbox = $wrap.parents( '.postbox' ).length > 0; - if ( ( $wrap.hasClass( 'tmce-active' ) || ! tinyMCEPreInit.qtInit.hasOwnProperty( id ) ) && ! init.wp_skip_init ) { + if ( + ! init.wp_skip_init && + ( $wrap.hasClass( 'tmce-active' ) || ! tinyMCEPreInit.qtInit.hasOwnProperty( id ) ) && + ( readyState === 'complete' || ( ! inPostbox && readyState === 'interactive' ) ) + ) { tinymce.init( init ); if ( ! window.wpActiveEditor ) { @@ -1685,6 +1690,18 @@ final class _WP_Editors { } } + if ( typeof tinymce !== 'undefined' ) { + if ( tinymce.Env.ie && tinymce.Env.ie < 11 ) { + tinymce.$( '.wp-editor-wrap ' ).removeClass( 'tmce-active' ).addClass( 'html-active' ); + } else { + if ( document.readyState === 'complete' ) { + initialize(); + } else { + document.addEventListener( 'readystatechange', initialize ); + } + } + } + if ( typeof quicktags !== 'undefined' ) { for ( id in tinyMCEPreInit.qtInit ) { quicktags( tinyMCEPreInit.qtInit[id] ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 5c76d4dd4e..f157aab402 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.8-alpha-51081'; +$wp_version = '5.8-alpha-51082'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.