Editor: Add init and remove methods to Quicktags.

Props helgatheviking azaozz.
Fixes #26183 #40708.
Built from https://develop.svn.wordpress.org/trunk@40598


git-svn-id: http://core.svn.wordpress.org/trunk@40468 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Ozz 2017-05-10 02:47:42 +00:00
parent 391145df30
commit 0b2f789e93
3 changed files with 42 additions and 24 deletions

View File

@ -223,7 +223,7 @@ function edButton(id, display, tagStart, tagEnd, access) {
if ( tb.addEventListener ) {
tb.addEventListener( 'click', onclick, false );
if ( wrap ) {
wrap.addEventListener( 'click', setActiveEditor, false );
}
@ -243,12 +243,20 @@ function edButton(id, display, tagStart, tagEnd, access) {
return document.getElementById(name + '_' + id);
};
qt.instances[id] = t;
t.init = function() {
_domReady( function(){ qt._buttonsInit( id ); } );
};
if ( ! qt.instances['0'] ) {
qt.instances['0'] = qt.instances[id];
_domReady( function(){ qt._buttonsInit(); } );
}
t.remove = function() {
delete qt.instances[id];
if ( tb && tb.parentNode ) {
tb.parentNode.removeChild( tb );
}
};
qt.instances[id] = t;
t.init();
};
function _escape( text ) {
@ -263,16 +271,14 @@ function edButton(id, display, tagStart, tagEnd, access) {
return qt.instances[id];
};
qt._buttonsInit = function() {
var t = this, canvas, name, settings, theButtons, html, inst, ed, id, i, use,
defaults = ',strong,em,link,block,del,ins,img,ul,ol,li,code,more,close,';
qt._buttonsInit = function( id ) {
var t = this;
for ( inst in t.instances ) {
if ( '0' === inst ) {
continue;
}
function _init( instanceId ) {
var canvas, name, settings, theButtons, html, ed, id, i, use,
defaults = ',strong,em,link,block,del,ins,img,ul,ol,li,code,more,close,';
ed = t.instances[inst];
ed = t.instances[instanceId];
canvas = ed.canvas;
name = ed.name;
settings = ed.settings;
@ -286,7 +292,7 @@ function edButton(id, display, tagStart, tagEnd, access) {
}
for ( i in edButtons ) {
if ( !edButtons[i] ) {
if ( ! edButtons[i] ) {
continue;
}
@ -295,11 +301,11 @@ function edButton(id, display, tagStart, tagEnd, access) {
continue;
}
if ( !edButtons[i].instance || edButtons[i].instance === inst ) {
if ( ! edButtons[i].instance || edButtons[i].instance === instanceId ) {
theButtons[id] = edButtons[i];
if ( edButtons[i].html ) {
html += edButtons[i].html(name + '_');
html += edButtons[i].html( name + '_' );
}
}
}
@ -309,9 +315,9 @@ function edButton(id, display, tagStart, tagEnd, access) {
html += theButtons.dfw.html( name + '_' );
}
if ( 'rtl' === document.getElementsByTagName('html')[0].dir ) {
if ( 'rtl' === document.getElementsByTagName( 'html' )[0].dir ) {
theButtons.textdirection = new qt.TextDirectionButton();
html += theButtons.textdirection.html(name + '_');
html += theButtons.textdirection.html( name + '_' );
}
ed.toolbar.innerHTML = html;
@ -321,6 +327,15 @@ function edButton(id, display, tagStart, tagEnd, access) {
jQuery( document ).triggerHandler( 'quicktags-init', [ ed ] );
}
}
if ( id ) {
_init( id );
} else {
for ( id in t.instances ) {
_init( id );
}
}
t.buttonsInitDone = true;
};
@ -606,9 +621,12 @@ function edButton(id, display, tagStart, tagEnd, access) {
qt.CloseButton.prototype.callback = qt._close;
qt.closeAllTags = function(editor_id) {
var ed = this.getInstance(editor_id);
qt._close('', ed.canvas, ed);
qt.closeAllTags = function( editor_id ) {
var ed = this.getInstance( editor_id );
if ( ed ) {
qt._close( '', ed.canvas, ed );
}
};
// the link button

File diff suppressed because one or more lines are too long

View File

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