WordPress.org

Make WordPress Core

Changeset 40588


Ignore:
Timestamp:
05/09/2017 03:40:30 AM (13 months ago)
Author:
azaozz
Message:

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

Fixes: #35760

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/js/editor.js

    r40476 r40588  
    619619
    620620    /**
     621     * Remove one editor instance.
     622     *
     623     * Intended for use with editors that were initialized with wp.editor.initialize().
     624     *
     625     * @since 4.8
     626     *
     627     * @param {string} id The HTML id of the editor textarea.
     628     */
     629    wp.editor.remove = function( id ) {
     630        var mceInstance, qtInstance,
     631            $wrap = $( '#wp-' + id + '-wrap' );
     632
     633        if ( window.tinymce ) {
     634            mceInstance = window.tinymce.get( id );
     635
     636            if ( mceInstance ) {
     637                if ( ! mceInstance.isHidden() ) {
     638                    mceInstance.save();
     639                }
     640
     641                mceInstance.remove();
     642            }
     643        }
     644
     645        if ( window.quicktags ) {
     646            qtInstance = window.QTags.getInstance( id );
     647
     648            if ( qtInstance ) {
     649                $( qtInstance.toolbar ).remove();
     650
     651                delete window.QTags.instances[ id ];
     652                delete window.QTags.instances[ 0 ];
     653            }
     654        }
     655
     656        if ( $wrap.length ) {
     657            $wrap.after( $( '#' + id ) );
     658            $wrap.remove();
     659        }
     660    };
     661
     662    /**
    621663     * Get the editor content.
    622664     *
Note: See TracChangeset for help on using the changeset viewer.