From 6213114f49301e5f614339cbed6078b2c9946bb8 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Mon, 7 Jun 2021 23:06:48 +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. git-svn-id: https://develop.svn.wordpress.org/trunk@51082 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-editor.php | 31 ++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/wp-includes/class-wp-editor.php b/src/wp-includes/class-wp-editor.php index 32f638240f..8812c770ab 100644 --- a/src/wp-includes/class-wp-editor.php +++ b/src/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] );