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
This commit is contained in:
Andrew Ozz
2021-06-07 23:06:48 +00:00
parent 40a61e6c14
commit 6213114f49

View File

@@ -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] );