diff --git a/src/wp-includes/js/quicktags.js b/src/wp-includes/js/quicktags.js index 6d00901a78..f8e30d39b5 100644 --- a/src/wp-includes/js/quicktags.js +++ b/src/wp-includes/js/quicktags.js @@ -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