Make WordPress Core

Changeset 26212


Ignore:
Timestamp:
11/15/2013 02:25:29 PM (11 years ago)
Author:
nacin
Message:

Fix JSHint errors in quicktags.js. Ignore deprecated API rather than marking it as exported globals.

props kovshenin.
fixes #26046.

File:
1 edited

Legend:

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

    r24490 r26212  
     1/* global adminpage, wpActiveEditor, quicktagsL10n, wpLink, fullscreen, prompt */
    12/*
    23 * Quicktags
     
    2223// http://www.alexking.org/
    2324
    24 var QTags, edButtons = [], edCanvas,
     25var QTags, edCanvas,
     26    edButtons = [];
     27
     28/* jshint ignore:start */
    2529
    2630/**
     
    2933 * Define all former global functions so plugins that hack quicktags.js directly don't cause fatal errors.
    3034 */
    31 edAddTag = function(){},
     35var edAddTag = function(){},
    3236edCheckOpenTags = function(){},
    3337edCloseAllTags = function(){},
     
    6670 * @see QTags.addButton()
    6771 */
    68 function edButton(id, display, tagStart, tagEnd, access, open) {
     72function edButton(id, display, tagStart, tagEnd, access) {
    6973    return QTags.addButton( id, display, tagStart, tagEnd, access, '', -1 );
    7074}
     75
     76/* jshint ignore:end */
    7177
    7278(function(){
    7379    // private stuff is prefixed with an underscore
    7480    var _domReady = function(func) {
    75         var t, i,  DOMContentLoaded;
    76 
    77         if ( typeof jQuery != 'undefined' ) {
     81        var t, i, DOMContentLoaded, _tryReady;
     82
     83        if ( typeof jQuery !== 'undefined' ) {
    7884            jQuery(document).ready(func);
    7985        } else {
     
    106112                    window.attachEvent('onload', t.ready);
    107113
    108                     (function(){
     114                    _tryReady = function() {
    109115                        try {
    110                             document.documentElement.doScroll("left");
     116                            document.documentElement.doScroll('left');
    111117                        } catch(e) {
    112                             setTimeout(arguments.callee, 50);
     118                            setTimeout(_tryReady, 50);
    113119                            return;
    114120                        }
    115121
    116122                        t.ready();
    117                     })();
     123                    };
     124                    _tryReady();
    118125                }
    119126
     
    129136            var str = number.toString();
    130137
    131             if ( str.length < 2 )
    132                 str = "0" + str;
     138            if ( str.length < 2 ) {
     139                str = '0' + str;
     140            }
    133141
    134142            return str;
    135         }
     143        };
    136144
    137145        return now.getUTCFullYear() + '-' +
     
    146154
    147155    qt = QTags = function(settings) {
    148         if ( typeof(settings) == 'string' )
     156        if ( typeof(settings) === 'string' ) {
    149157            settings = {id: settings};
    150         else if ( typeof(settings) != 'object' )
     158        } else if ( typeof(settings) !== 'object' ) {
    151159            return false;
     160        }
    152161
    153162        var t = this,
     
    157166            tb, onclick, toolbar_id;
    158167
    159         if ( !id || !canvas )
     168        if ( !id || !canvas ) {
    160169            return false;
     170        }
    161171
    162172        t.name = name;
     
    165175        t.settings = settings;
    166176
    167         if ( id == 'content' && typeof(adminpage) == 'string' && ( adminpage == 'post-new-php' || adminpage == 'post-php' ) ) {
     177        if ( id === 'content' && typeof(adminpage) === 'string' && ( adminpage === 'post-new-php' || adminpage === 'post-php' ) ) {
    168178            // back compat hack :-(
    169179            edCanvas = canvas;
     
    186196
    187197            // don't call the callback on pressing the accesskey when the button is not visible
    188             if ( !visible )
     198            if ( !visible ) {
    189199                return;
     200            }
    190201
    191202            // as long as it has the class ed_button, execute the callback
     
    195206                i = target.id.replace(name + '_', '');
    196207
    197                 if ( t.theButtons[i] )
     208                if ( t.theButtons[i] ) {
    198209                    t.theButtons[i].callback.call(t.theButtons[i], target, canvas, t);
     210                }
    199211            }
    200212        };
     
    233245
    234246        for ( inst in t.instances ) {
    235             if ( inst == 0 )
     247            if ( inst === 0 ) {
    236248                continue;
     249            }
    237250
    238251            ed = t.instances[inst];
     
    245258
    246259            // set buttons
    247             if ( settings.buttons )
     260            if ( settings.buttons ) {
    248261                use = ','+settings.buttons+',';
     262            }
    249263
    250264            for ( i in edButtons ) {
    251                 if ( !edButtons[i] )
     265                if ( !edButtons[i] ) {
    252266                    continue;
     267                }
    253268
    254269                id = edButtons[i].id;
    255                 if ( use && defaults.indexOf(','+id+',') != -1 && use.indexOf(','+id+',') == -1 )
     270                if ( use && defaults.indexOf( ',' + id + ',' ) !== -1 && use.indexOf( ',' + id + ',' ) === -1 ) {
    256271                    continue;
    257 
    258                 if ( !edButtons[i].instance || edButtons[i].instance == inst ) {
     272                }
     273
     274                if ( !edButtons[i].instance || edButtons[i].instance === inst ) {
    259275                    theButtons[id] = edButtons[i];
    260276
    261                     if ( edButtons[i].html )
     277                    if ( edButtons[i].html ) {
    262278                        html += edButtons[i].html(name + '_');
    263                 }
    264             }
    265 
    266             if ( use && use.indexOf(',fullscreen,') != -1 ) {
    267                 theButtons['fullscreen'] = new qt.FullscreenButton();
    268                 html += theButtons['fullscreen'].html(name + '_');
    269             }
    270 
    271 
    272             if ( 'rtl' == document.getElementsByTagName('html')[0].dir ) {
    273                 theButtons['textdirection'] = new qt.TextDirectionButton();
    274                 html += theButtons['textdirection'].html(name + '_');
     279                    }
     280                }
     281            }
     282
     283            if ( use && use.indexOf(',fullscreen,') !== -1 ) {
     284                theButtons.fullscreen = new qt.FullscreenButton();
     285                html += theButtons.fullscreen.html(name + '_');
     286            }
     287
     288
     289            if ( 'rtl' === document.getElementsByTagName('html')[0].dir ) {
     290                theButtons.textdirection = new qt.TextDirectionButton();
     291                html += theButtons.textdirection.html(name + '_');
    275292            }
    276293
     
    310327        var btn;
    311328
    312         if ( !id || !display )
     329        if ( !id || !display ) {
    313330            return;
     331        }
    314332
    315333        priority = priority || 0;
     
    325343        }
    326344
    327         if ( priority == -1 ) // back-compat
     345        if ( priority === -1 ) { // back-compat
    328346            return btn;
     347        }
    329348
    330349        if ( priority > 0 ) {
    331             while ( typeof(edButtons[priority]) != 'undefined' ) {
    332                 priority++
     350            while ( typeof(edButtons[priority]) !== 'undefined' ) {
     351                priority++;
    333352            }
    334353
     
    338357        }
    339358
    340         if ( this.buttonsInitDone )
     359        if ( this.buttonsInitDone ) {
    341360            this._buttonsInit(); // add the button HTML to all instances toolbars if addButton() was called too late
     361        }
    342362    };
    343363
     
    345365        var sel, startPos, endPos, scrollTop, text, canvas = document.getElementById(wpActiveEditor);
    346366
    347         if ( !canvas )
     367        if ( !canvas ) {
    348368            return false;
     369        }
    349370
    350371        if ( document.selection ) { //IE
     
    353374            sel.text = content;
    354375            canvas.focus();
    355         } else if ( canvas.selectionStart || canvas.selectionStart == '0' ) { // FF, WebKit, Opera
     376        } else if ( canvas.selectionStart || canvas.selectionStart === '0' ) { // FF, WebKit, Opera
    356377            text = canvas.value;
    357378            startPos = canvas.selectionStart;
     
    420441        if ( ed.openTags ) {
    421442            while ( ret === false && i < ed.openTags.length ) {
    422                 ret = ed.openTags[i] == t.id ? i : false;
     443                ret = ed.openTags[i] === t.id ? i : false;
    423444                i ++;
    424445            }
     
    435456            sel = document.selection.createRange();
    436457            if ( sel.text.length > 0 ) {
    437                 if ( !t.tagEnd )
     458                if ( !t.tagEnd ) {
    438459                    sel.text = sel.text + t.tagStart;
    439                 else
     460                } else {
    440461                    sel.text = t.tagStart + sel.text + endTag;
     462                }
    441463            } else {
    442464                if ( !t.tagEnd ) {
     
    451473            }
    452474            canvas.focus();
    453         } else if ( canvas.selectionStart || canvas.selectionStart == '0' ) { // FF, WebKit, Opera
     475        } else if ( canvas.selectionStart || canvas.selectionStart === '0' ) { // FF, WebKit, Opera
    454476            startPos = canvas.selectionStart;
    455477            endPos = canvas.selectionEnd;
     
    459481            r = v.substring(endPos, v.length); // right of the selection
    460482            i = v.substring(startPos, endPos); // inside the selection
    461             if ( startPos != endPos ) {
     483            if ( startPos !== endPos ) {
    462484                if ( !t.tagEnd ) {
    463485                    canvas.value = l + i + t.tagStart + r; // insert self closing tags after the selection
     
    518540                element = document.getElementById(ed.name + '_' + button.id);
    519541
    520                 if ( e )
     542                if ( e ) {
    521543                    button.callback.call(button, element, c, ed);
    522                 else
     544                } else {
    523545                    button.closeTag(element, ed);
     546                }
    524547            }
    525548        }
     
    541564        var URL, t = this;
    542565
    543         if ( typeof(wpLink) != 'undefined' ) {
     566        if ( typeof(wpLink) !== 'undefined' ) {
    544567            wpLink.open();
    545568            return;
    546569        }
    547570
    548         if ( ! defaultValue )
     571        if ( ! defaultValue ) {
    549572            defaultValue = 'http://';
     573        }
    550574
    551575        if ( t.isOpen(ed) === false ) {
     
    582606    qt.FullscreenButton.prototype = new qt.Button();
    583607    qt.FullscreenButton.prototype.callback = function(e, c) {
    584         if ( !c.id || typeof(fullscreen) == 'undefined' )
     608        if ( !c.id || typeof(fullscreen) === 'undefined' ) {
    585609            return;
     610        }
    586611
    587612        fullscreen.on();
     
    589614
    590615    qt.TextDirectionButton = function() {
    591         qt.Button.call(this, 'textdirection', quicktagsL10n.textdirection, '', quicktagsL10n.toggleTextdirection)
     616        qt.Button.call(this, 'textdirection', quicktagsL10n.textdirection, '', quicktagsL10n.toggleTextdirection);
    592617    };
    593618    qt.TextDirectionButton.prototype = new qt.Button();
    594619    qt.TextDirectionButton.prototype.callback = function(e, c) {
    595         var isRTL = ( 'rtl' == document.getElementsByTagName('html')[0].dir ),
     620        var isRTL = ( 'rtl' === document.getElementsByTagName('html')[0].dir ),
    596621            currentDirection = c.style.direction;
    597622
    598         if ( ! currentDirection )
     623        if ( ! currentDirection ) {
    599624            currentDirection = ( isRTL ) ? 'rtl' : 'ltr';
    600 
    601         c.style.direction = ( 'rtl' == currentDirection ) ? 'ltr' : 'rtl';
     625        }
     626
     627        c.style.direction = ( 'rtl' === currentDirection ) ? 'ltr' : 'rtl';
    602628        c.focus();
    603     }
     629    };
    604630
    605631    // ensure backward compatibility
     
    616642    edButtons[110] = new qt.TagButton('code','code','<code>','</code>','c'),
    617643    edButtons[120] = new qt.TagButton('more','more','<!--more-->','','t'),
    618     edButtons[140] = new qt.CloseButton()
     644    edButtons[140] = new qt.CloseButton();
    619645
    620646})();
Note: See TracChangeset for help on using the changeset viewer.