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

Fixes: #35760

git-svn-id: https://develop.svn.wordpress.org/trunk@40588 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz 2017-05-09 03:40:30 +00:00
parent 3d2137f1b4
commit 4469ab9d66
1 changed files with 42 additions and 0 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.
*