From 4469ab9d66ad30d9665b351ecdc51c427132945a Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Tue, 9 May 2017 03:40:30 +0000 Subject: [PATCH] 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 --- src/wp-admin/js/editor.js | 42 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/wp-admin/js/editor.js b/src/wp-admin/js/editor.js index 917721a426..33c9ae4194 100644 --- a/src/wp-admin/js/editor.js +++ b/src/wp-admin/js/editor.js @@ -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. *