Make WordPress Core

Changeset 51082


Ignore:
Timestamp:
06/07/2021 11:06:48 PM (3 years ago)
Author:
azaozz
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-editor.php

    r50980 r51082  
    16641664
    16651665        ( function() {
    1666             var init, id, $wrap;
     1666            var initialize = function() {
     1667                var init, id, inPostbox, $wrap;
     1668                var readyState = document.readyState;
     1669
     1670                if ( readyState !== 'complete' && readyState !== 'interactive' ) {
     1671                    return;
     1672                }
     1673
     1674                for ( id in tinyMCEPreInit.mceInit ) {
     1675                    init      = tinyMCEPreInit.mceInit[id];
     1676                    $wrap     = tinymce.$( '#wp-' + id + '-wrap' );
     1677                    inPostbox = $wrap.parents( '.postbox' ).length > 0;
     1678
     1679                    if (
     1680                        ! init.wp_skip_init &&
     1681                        ( $wrap.hasClass( 'tmce-active' ) || ! tinyMCEPreInit.qtInit.hasOwnProperty( id ) ) &&
     1682                        ( readyState === 'complete' || ( ! inPostbox && readyState === 'interactive' ) )
     1683                    ) {
     1684                        tinymce.init( init );
     1685
     1686                        if ( ! window.wpActiveEditor ) {
     1687                            window.wpActiveEditor = id;
     1688                        }
     1689                    }
     1690                }
     1691            }
    16671692
    16681693            if ( typeof tinymce !== 'undefined' ) {
    16691694                if ( tinymce.Env.ie && tinymce.Env.ie < 11 ) {
    16701695                    tinymce.$( '.wp-editor-wrap ' ).removeClass( 'tmce-active' ).addClass( 'html-active' );
    1671                     return;
    1672                 }
    1673 
    1674                 for ( id in tinyMCEPreInit.mceInit ) {
    1675                     init = tinyMCEPreInit.mceInit[id];
    1676                     $wrap = tinymce.$( '#wp-' + id + '-wrap' );
    1677 
    1678                     if ( ( $wrap.hasClass( 'tmce-active' ) || ! tinyMCEPreInit.qtInit.hasOwnProperty( id ) ) && ! init.wp_skip_init ) {
    1679                         tinymce.init( init );
    1680 
    1681                         if ( ! window.wpActiveEditor ) {
    1682                             window.wpActiveEditor = id;
    1683                         }
     1696                } else {
     1697                    if ( document.readyState === 'complete' ) {
     1698                        initialize();
     1699                    } else {
     1700                        document.addEventListener( 'readystatechange', initialize );
    16841701                    }
    16851702                }
Note: See TracChangeset for help on using the changeset viewer.