Make WordPress Core

Changeset 40598


Ignore:
Timestamp:
05/10/2017 02:46:24 AM (7 years ago)
Author:
azaozz
Message:

Editor: Add init and remove methods to Quicktags.

Props helgatheviking azaozz.
Fixes #26183 #40708.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/js/quicktags.js

    r37661 r40598  
    224224        if ( tb.addEventListener ) {
    225225            tb.addEventListener( 'click', onclick, false );
    226            
     226
    227227            if ( wrap ) {
    228228                wrap.addEventListener( 'click', setActiveEditor, false );
     
    244244        };
    245245
     246        t.init = function() {
     247            _domReady( function(){ qt._buttonsInit( id ); } );
     248        };
     249
     250        t.remove = function() {
     251            delete qt.instances[id];
     252
     253            if ( tb && tb.parentNode ) {
     254                tb.parentNode.removeChild( tb );
     255            }
     256        };
     257
    246258        qt.instances[id] = t;
    247 
    248         if ( ! qt.instances['0'] ) {
    249             qt.instances['0'] = qt.instances[id];
    250             _domReady( function(){ qt._buttonsInit(); } );
    251         }
     259        t.init();
    252260    };
    253261
     
    264272    };
    265273
    266     qt._buttonsInit = function() {
    267         var t = this, canvas, name, settings, theButtons, html, inst, ed, id, i, use,
    268             defaults = ',strong,em,link,block,del,ins,img,ul,ol,li,code,more,close,';
    269 
    270         for ( inst in t.instances ) {
    271             if ( '0' === inst ) {
    272                 continue;
    273             }
    274 
    275             ed = t.instances[inst];
     274    qt._buttonsInit = function( id ) {
     275        var t = this;
     276
     277        function _init( instanceId ) {
     278            var canvas, name, settings, theButtons, html, ed, id, i, use,
     279                defaults = ',strong,em,link,block,del,ins,img,ul,ol,li,code,more,close,';
     280
     281            ed = t.instances[instanceId];
    276282            canvas = ed.canvas;
    277283            name = ed.name;
     
    287293
    288294            for ( i in edButtons ) {
    289                 if ( !edButtons[i] ) {
     295                if ( ! edButtons[i] ) {
    290296                    continue;
    291297                }
     
    296302                }
    297303
    298                 if ( !edButtons[i].instance || edButtons[i].instance === inst ) {
     304                if ( ! edButtons[i].instance || edButtons[i].instance === instanceId ) {
    299305                    theButtons[id] = edButtons[i];
    300306
    301307                    if ( edButtons[i].html ) {
    302                         html += edButtons[i].html(name + '_');
     308                        html += edButtons[i].html( name + '_' );
    303309                    }
    304310                }
     
    310316            }
    311317
    312             if ( 'rtl' === document.getElementsByTagName('html')[0].dir ) {
     318            if ( 'rtl' === document.getElementsByTagName( 'html' )[0].dir ) {
    313319                theButtons.textdirection = new qt.TextDirectionButton();
    314                 html += theButtons.textdirection.html(name + '_');
     320                html += theButtons.textdirection.html( name + '_' );
    315321            }
    316322
     
    322328            }
    323329        }
     330
     331        if ( id ) {
     332            _init( id );
     333        } else {
     334            for ( id in t.instances ) {
     335                _init( id );
     336            }
     337        }
     338
    324339        t.buttonsInitDone = true;
    325340    };
     
    607622    qt.CloseButton.prototype.callback = qt._close;
    608623
    609     qt.closeAllTags = function(editor_id) {
    610         var ed = this.getInstance(editor_id);
    611         qt._close('', ed.canvas, ed);
     624    qt.closeAllTags = function( editor_id ) {
     625        var ed = this.getInstance( editor_id );
     626
     627        if ( ed ) {
     628            qt._close( '', ed.canvas, ed );
     629        }
    612630    };
    613631
Note: See TracChangeset for help on using the changeset viewer.