Make WordPress Core

Ticket #19173: metabox-editor-reinit.diff

File metabox-editor-reinit.diff, 2.2 KB (added by guillaumemolter, 8 years ago)

Proposal of fix for #19173

  • wp-admin/js/editor.js

    diff --git wp-admin/js/editor.js wp-admin/js/editor.js
    index a63a51c..5f45e52 100644
     
    484484                        } );
    485485                }
    486486
     487                /**
     488                 * @summary Re-init editors in metaboxes.
     489                 *
     490                 * @since 4.8.0
     491                 *
     492                 * @memberof switchEditors
     493                 *
     494                 * @returns {void}
     495                 */
     496                function reinit_metabox_editors() {
     497                        // We check the context.
     498                        if ( ! tinymce || 'object' !== typeof tinymce ) {
     499                                return;
     500                        }
     501                        // We get all instances of the editors.
     502                        var editors = tinymce.get();
     503                        // We iterate through the list of editors.
     504                        $.each( editors, function( index, editor ) {
     505                                // We ignore the main editor and make sure the editor is in a metabox.
     506                                if ( 'content' !== editor.id && $( editor.editorContainer ).parents( '.meta-box-sortables' ).length === 1 ) {
     507                                        // Check if we are displaying Quicktags or TinyMCE.
     508                                        if ( ! editor.isHidden() ) {
     509                                                // If tinyMCE we save (localy) the content.
     510                                                editor.save();
     511                                        }
     512                                        // Remove the instance of the editor.
     513                                        tinymce.remove( editor );
     514                                        // And then re-init it.
     515                                        tinymce.init( tinyMCEPreInit.mceInit[ editor.id ] );
     516                                        // If we were viewing Quicktags we switch back to the tab.
     517                                        if ( editor.isHidden() ) {
     518                                                $( '#' + editor.id + '-html' ).click();
     519                                        }
     520                                }
     521                        });
     522                }
     523
    487524                window.wp = window.wp || {};
    488525                window.wp.editor = window.wp.editor || {};
    489526                window.wp.editor.autop = wpautop;
    490527                window.wp.editor.removep = pre_wpautop;
     528                window.wp.editor.reinit_metabox_editors = reinit_metabox_editors;
    491529
    492530                exports = {
    493531                        go: switchEditor,
    494532                        wpautop: wpautop,
    495533                        pre_wpautop: pre_wpautop,
     534                        reinit_metabox_editors: reinit_metabox_editors,
    496535                        _wp_Autop: autop,
    497536                        _wp_Nop: removep
    498537                };
  • wp-admin/js/postbox.js

    diff --git wp-admin/js/postbox.js wp-admin/js/postbox.js
    index bbc73b2..75e9e13 100644
    var postboxes; 
    240240                                        }
    241241
    242242                                        postboxes.save_order(page);
     243
     244                                        // If DOM is reordered we re-init potential WYSIWYG editors.
     245                                        if ( 'function' === typeof wp.editor.reinit_metabox_editors ) {
     246                                                wp.editor.reinit_metabox_editors();
     247                                        }
    243248                                },
    244249                                receive: function(e,ui) {
    245250                                        if ( 'dashboard_browser_nag' == ui.item[0].id )