diff --git a/wp-admin/js/editor.js b/wp-admin/js/editor.js index 917721a426..33c9ae4194 100644 --- a/wp-admin/js/editor.js +++ b/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. * diff --git a/wp-admin/js/editor.min.js b/wp-admin/js/editor.min.js index 52b1a61fb7..c6e83fab38 100644 --- a/wp-admin/js/editor.min.js +++ b/wp-admin/js/editor.min.js @@ -1 +1 @@ -window.wp=window.wp||{},function(a,b){function c(){function c(){!j&&window.tinymce&&(j=window.tinymce,k=j.$,k(document).on("click",function(a){var b,c,d=k(a.target);d.hasClass("wp-switch-editor")&&(b=d.attr("data-wp-editor-id"),c=d.hasClass("switch-tmce")?"tmce":"html",e(b,c))}))}function d(a){var b=k(".mce-toolbar-grp",a.getContainer())[0],c=b&&b.clientHeight;return c&&c>10&&c<200?parseInt(c,10):30}function e(a,b){a=a||"content",b=b||"toggle";var c,e,f,g=j.get(a),h=k("#wp-"+a+"-wrap"),i=k("#"+a),l=i[0];if("toggle"===b&&(b=g&&!g.isHidden()?"html":"tmce"),"tmce"===b||"tinymce"===b){if(g&&!g.isHidden())return!1;"undefined"!=typeof window.QTags&&window.QTags.closeAllTags(a),c=parseInt(l.style.height,10)||0,g?(g.show(),!j.Env.iOS&&c&&(e=d(g),c=c-e+14,c>50&&c<5e3&&g.theme.resizeTo(null,c))):j.init(window.tinyMCEPreInit.mceInit[a]),h.removeClass("html-active").addClass("tmce-active"),i.attr("aria-hidden",!0),window.setUserSetting("editor","tinymce")}else if("html"===b){if(g&&g.isHidden())return!1;g?(j.Env.iOS||(f=g.iframeElement,c=f?parseInt(f.style.height,10):0,c&&(e=d(g),c=c+e-14,c>50&&c<5e3&&(l.style.height=c+"px"))),g.hide()):i.css({display:"",visibility:""}),h.removeClass("tmce-active").addClass("html-active"),i.attr("aria-hidden",!1),window.setUserSetting("editor","html")}}function f(a){var b="blockquote|ul|ol|li|dl|dt|dd|table|thead|tbody|tfoot|tr|th|td|h[1-6]|fieldset|figure",c=b+"|div|p",d=b+"|pre",e=!1,f=!1,g=[];return a?(a.indexOf("]*>[\s\S]*?<\/\1>/g,function(a){return g.push(a),""})),a.indexOf("]*>[\s\S]+?<\/pre>/g,function(a){return a=a.replace(/
(\r\n|\n)?/g,""),a=a.replace(/<\/?p( [^>]*)?>(\r\n|\n)?/g,""),a.replace(/\r?\n/g,"")})),a.indexOf("[caption")!==-1&&(f=!0,a=a.replace(/\[caption[\s\S]+?\[\/caption\]/g,function(a){return a.replace(/]*)>/g,"").replace(/[\r\n\t]+/,"")})),a=a.replace(new RegExp("\\s*\\s*","g"),"\n"),a=a.replace(new RegExp("\\s*<((?:"+c+")(?: [^>]*)?)>","g"),"\n<$1>"),a=a.replace(/(

]+>.*?)<\/p>/g,"$1"),a=a.replace(/]*)?>\s*

/gi,"\n\n"),a=a.replace(/\s*

/gi,""),a=a.replace(/\s*<\/p>\s*/gi,"\n\n"),a=a.replace(/\n[\s\u00a0]+\n/g,"\n\n"),a=a.replace(/\s*
\s*/gi,"\n"),a=a.replace(/\s*

\s*/g,"
\n"),a=a.replace(/\s*\[caption([^\[]+)\[\/caption\]\s*/gi,"\n\n[caption$1[/caption]\n\n"),a=a.replace(/caption\]\n\n+\[caption/g,"caption]\n\n[caption"),a=a.replace(new RegExp("\\s*<((?:"+d+")(?: [^>]*)?)\\s*>","g"),"\n<$1>"),a=a.replace(new RegExp("\\s*\\s*","g"),"\n"),a=a.replace(/<((li|dt|dd)[^>]*)>/g," \t<$1>"),a.indexOf("/g,"\n")),a.indexOf("]*)?>\s*/g,"\n\n\n\n")),a.indexOf("/g,function(a){return a.replace(/[\r\n]+/g,"")})),a=a.replace(/<\/p#>/g,"

\n"),a=a.replace(/\s*(

]+>[\s\S]*?<\/p>)/g,"\n$1"),a=a.replace(/^\s+/,""),a=a.replace(/[\s\u00a0]+$/,""),e&&(a=a.replace(//g,"\n")),f&&(a=a.replace(/]*)>/g,"")),g.length&&(a=a.replace(//g,function(){return g.shift()})),a):""}function g(a){var b=!1,c=!1,d="table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary";return a=a.replace(/\r\n|\r/g,"\n"),a.indexOf("\n")===-1?a:(a.indexOf("/g,function(a){return a.replace(/\n+/g,"")})),a=a.replace(/<[^<>]+>/g,function(a){return a.replace(/[\n\t ]+/g," ")}),a.indexOf("]*>[\s\S]*?<\/\1>/g,function(a){return a.replace(/\n/g,"")})),a.indexOf("]*>)/g,"$1"),a=a.replace(/<\/figcaption>\s*/g,"")),a.indexOf("[caption")!==-1&&(c=!0,a=a.replace(/\[caption[\s\S]+?\[\/caption\]/g,function(a){return a=a.replace(/]*)>/g,""),a=a.replace(/<[^<>]+>/g,function(a){return a.replace(/[\n\t ]+/," ")}),a.replace(/\s*\n\s*/g,"")})),a+="\n\n",a=a.replace(/
\s*
/gi,"\n\n"),a=a.replace(new RegExp("(<(?:"+d+")(?: [^>]*)?>)","gi"),"\n\n$1"),a=a.replace(new RegExp("()","gi"),"$1\n\n"),a=a.replace(/]*)?>/gi,"\n\n"),a=a.replace(/\s*"),a=a.replace(/\n\s*\n+/g,"\n\n"),a=a.replace(/([\s\S]+?)\n\n/g,"

$1

\n"),a=a.replace(/

\s*?<\/p>/gi,""),a=a.replace(new RegExp("

\\s*(]*)?>)\\s*

","gi"),"$1"),a=a.replace(/

(/gi,"$1"),a=a.replace(/

\s*]*)>/gi,"

"),a=a.replace(/<\/blockquote>\s*<\/p>/gi,"

"),a=a.replace(new RegExp("

\\s*(]*)?>)","gi"),"$1"),a=a.replace(new RegExp("(]*)?>)\\s*

","gi"),"$1"),a=a.replace(/(]*>)\s*\n/gi,"$1"),a=a.replace(/\s*\n/g,"
\n"),a=a.replace(new RegExp("(]*>)\\s*
","gi"),"$1"),a=a.replace(/
(\s*<\/?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)>)/gi,"$1"),a=a.replace(/(?:

|
)*\s*\[caption([^\[]+)\[\/caption\]\s*(?:<\/p>|
)*/gi,"[caption$1[/caption]"),a=a.replace(/(<(?:div|th|td|form|fieldset|dd)[^>]*>)(.*?)<\/p>/g,function(a,b,c){return c.match(/]*)?>/)?a:b+"

"+c+"

"}),b&&(a=a.replace(//g,"\n")),c&&(a=a.replace(/]*)>/g,"")),a)}function h(b){var c={o:l,data:b,unfiltered:b};return a&&a("body").trigger("beforePreWpautop",[c]),c.data=f(c.data),a&&a("body").trigger("afterPreWpautop",[c]),c.data}function i(b){var c={o:l,data:b,unfiltered:b};return a&&a("body").trigger("beforeWpautop",[c]),c.data=g(c.data),a&&a("body").trigger("afterWpautop",[c]),c.data}var j,k,l={};return a?a(document).ready(c):document.addEventListener?(document.addEventListener("DOMContentLoaded",c,!1),window.addEventListener("load",c,!1)):window.attachEvent&&(window.attachEvent("onload",c),document.attachEvent("onreadystatechange",function(){"complete"===document.readyState&&c()})),b.editor.autop=i,b.editor.removep=h,l={go:e,wpautop:i,pre_wpautop:h,_wp_Autop:g,_wp_Nop:f}}b.editor=b.editor||{},window.switchEditors=new c,b.editor.initialize=function(c,d){var e,f;if(a&&c&&b.editor.getDefaultSettings){if(f=b.editor.getDefaultSettings(),d||(d={tinymce:!0}),d.tinymce&&d.quicktags){var g=a("#"+c),h=a("
").attr({"class":"wp-core-ui wp-editor-wrap tmce-active",id:"wp-"+c+"-wrap"}),i=a('
'),j=a("