Make WordPress Core

Ticket #25945: shortcode.diff

File shortcode.diff, 4.0 KB (added by tommcfarlin, 11 years ago)

Resolving the JSHint errors regarding conditional braces and unused function argumnets.

  • src/wp-includes/js/shortcode.js

     
    1919                        re.lastIndex = index || 0;
    2020                        match = re.exec( text );
    2121
    22                         if ( ! match )
     22                        if ( ! match ) {
    2323                                return;
     24                        }
    2425
    2526                        // If we matched an escaped shortcode, try again.
    26                         if ( match[1] === '[' && match[7] === ']' )
     27                        if ( '[' === match[1] && ']' === match[7] ) {
    2728                                return wp.shortcode.next( tag, text, re.lastIndex );
     29                        }
    2830
    2931                        result = {
    3032                                index:     match.index,
     
    4042                        }
    4143
    4244                        // If we matched a trailing `]`, strip it from the match.
    43                         if ( match[7] )
     45                        if ( match[7] ) {
    4446                                result.match = result.match.slice( 0, -1 );
     47                        }
    4548
    4649                        return result;
    4750                },
     
    5659                // a shortcode `attrs` object, the `content` between shortcode tags,
    5760                // and a boolean flag to indicate if the match was a `single` tag.
    5861                replace: function( tag, text, callback ) {
    59                         return text.replace( wp.shortcode.regexp( tag ), function( match, left, tag, attrs, slash, content, closing, right, offset ) {
     62                        return text.replace( wp.shortcode.regexp( tag ), function( match, left, tag, attrs, slash, content, closing, right ) {
    6063                                // If both extra brackets exist, the shortcode has been
    6164                                // properly escaped.
    62                                 if ( left === '[' && right === ']' )
     65                                if ( left === '[' && right === ']' ) {
    6366                                        return match;
     67                                }
    6468
    6569                                // Create the match object and pass it through the callback.
    6670                                var result = callback( wp.shortcode.fromMatch( arguments ) );
     
    164168                fromMatch: function( match ) {
    165169                        var type;
    166170
    167                         if ( match[4] )
     171                        if ( match[4] ) {
    168172                                type = 'self-closing';
    169                         else if ( match[6] )
     173                        } else if ( match[6] ) {
    170174                                type = 'closed';
    171                         else
     175                        } else {
    172176                                type = 'single';
     177                        }
    173178
    174179                        return new wp.shortcode({
    175180                                tag:     match[2],
     
    202207                        numeric: []
    203208                };
    204209
    205                 if ( ! attrs )
     210                if ( ! attrs ) {
    206211                        return;
     212                }
    207213
    208214                // Parse a string of attributes.
    209215                if ( _.isString( attrs ) ) {
     
    244250                        var text    = '[' + this.tag;
    245251
    246252                        _.each( this.attrs.numeric, function( value ) {
    247                                 if ( /\s/.test( value ) )
     253                                if ( /\s/.test( value ) ) {
    248254                                        text += ' "' + value + '"';
    249                                 else
     255                                } else {
    250256                                        text += ' ' + value;
     257                                }
    251258                        });
    252259
    253260                        _.each( this.attrs.named, function( value, name ) {
     
    256263
    257264                        // If the tag is marked as `single` or `self-closing`, close the
    258265                        // tag and ignore any additional content.
    259                         if ( 'single' === this.type )
     266                        if ( 'single' === this.type ) {
    260267                                return text + ']';
    261                         else if ( 'self-closing' === this.type )
     268                        } else if ( 'self-closing' === this.type ) {
    262269                                return text + ' /]';
     270                        }
    263271
    264272                        // Complete the opening tag.
    265273                        text += ']';
    266274
    267                         if ( this.content )
     275                        if ( this.content ) {
    268276                                text += this.content;
     277                        }
    269278
    270279                        // Add the closing tag.
    271280                        return text + '[/' + this.tag + ']';
     
    291300                        var result, attrs;
    292301
    293302                        // If `content` ends in a slash, strip it.
    294                         if ( '/' === content[ content.length - 1 ] )
     303                        if ( '/' === content[ content.length - 1 ] ) {
    295304                                content = content.slice( 0, -1 );
     305                        }
    296306
    297307                        result = wp.shortcode.attrs( content );
    298308                        attrs  = result.named;
    299309
    300310                        _.each( result.numeric, function( key ) {
    301                                 if ( /\s/.test( key ) )
     311                                if ( /\s/.test( key ) ) {
    302312                                        return;
     313                                }
    303314
    304315                                attrs[ key ] = '';
    305316                        });
     
    316327                                text += ' ' + attr;
    317328
    318329                                // Use empty attribute notation where possible.
    319                                 if ( '' === value )
     330                                if ( '' === value ) {
    320331                                        return;
     332                                }
    321333
    322334                                // Convert boolean values to strings.
    323                                 if ( _.isBoolean( value ) )
     335                                if ( _.isBoolean( value ) ) {
    324336                                        value = value ? 'true' : 'false';
     337                                }
    325338
    326339                                text += '="' + value + '"';
    327340                        });
    328341
    329342                        // Return the result if it is a self-closing tag.
    330                         if ( options.single )
     343                        if ( options.single ) {
    331344                                return text + ' />';
     345                        }
    332346
    333347                        // Complete the opening tag.
    334348                        text += '>';