Editor: Add `wp.editor.remove()` for editors that were dynamically instantiated from JS.

Fixes: #35760
Built from https://develop.svn.wordpress.org/trunk@40588


git-svn-id: http://core.svn.wordpress.org/trunk@40458 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Ozz 2017-05-09 03:41:42 +00:00
parent ec622956c8
commit cbf3b2cff5
3 changed files with 44 additions and 2 deletions

View File

@ -617,6 +617,48 @@ window.wp = window.wp || {};
} }
}; };
/**
* Remove one editor instance.
*
* Intended for use with editors that were initialized with wp.editor.initialize().
*
* @since 4.8
*
* @param {string} id The HTML id of the editor textarea.
*/
wp.editor.remove = function( id ) {
var mceInstance, qtInstance,
$wrap = $( '#wp-' + id + '-wrap' );
if ( window.tinymce ) {
mceInstance = window.tinymce.get( id );
if ( mceInstance ) {
if ( ! mceInstance.isHidden() ) {
mceInstance.save();
}
mceInstance.remove();
}
}
if ( window.quicktags ) {
qtInstance = window.QTags.getInstance( id );
if ( qtInstance ) {
$( qtInstance.toolbar ).remove();
delete window.QTags.instances[ id ];
delete window.QTags.instances[ 0 ];
}
}
if ( $wrap.length ) {
$wrap.after( $( '#' + id ) );
$wrap.remove();
}
};
/** /**
* Get the editor content. * Get the editor content.
* *

File diff suppressed because one or more lines are too long

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.8-alpha-40587'; $wp_version = '4.8-alpha-40588';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.