mediawiki.special.apisandbox.js: Apply JavaScript coding conventions
authorFomafix <fomafix@googlemail.com>
Tue, 21 Nov 2017 18:14:44 +0000 (19:14 +0100)
committerFomafix <fomafix@googlemail.com>
Thu, 23 Nov 2017 20:23:29 +0000 (21:23 +0100)
Do not use the jQuery constructor with second argument.
https://www.mediawiki.org/wiki/Manual:Coding_conventions/JavaScript#Pitfalls

Change-Id: I0c7e93438c78e234c6656b2e6499e674a0322cd3

resources/src/mediawiki.special/mediawiki.special.apisandbox.js

index ed51c34..ff4335a 100644 (file)
                                .empty()
                                .append( $( '<p>' ).append( Util.parseMsg( 'apisandbox-intro' ) ) )
                                .append(
-                                       $( '<div>', { id: 'mw-apisandbox-ui' } )
+                                       $( '<div>' ).attr( 'id', 'mw-apisandbox-ui' )
                                                .append( $toolbar )
                                                .append( panel.$element )
                                );
                                                        width: 'auto',
                                                        padded: true,
                                                        $content: $( '<ul>' ).append( $.map( pi.helpurls, function ( link ) {
-                                                               return $( '<li>' ).append( $( '<a>', {
-                                                                       href: link,
-                                                                       target: '_blank',
-                                                                       text: link
-                                                               } ) );
+                                                               return $( '<li>' ).append( $( '<a>' )
+                                                                       .attr( { href: link, target: '_blank' } )
+                                                                       .text( link )
+                                                               );
                                                        } ) )
                                                }
                                        } ) );
                                                        width: 'auto',
                                                        padded: true,
                                                        $content: $( '<ul>' ).append( $.map( pi.examples, function ( example ) {
-                                                               var a = $( '<a>', {
-                                                                       href: '#' + example.query,
-                                                                       html: example.description
-                                                               } );
+                                                               var a = $( '<a>' )
+                                                                       .attr( 'href', '#' + example.query )
+                                                                       .html( example.description );
                                                                a.find( 'a' ).contents().unwrap(); // Can't nest links
                                                                return $( '<li>' ).append( a );
                                                        } ) )
                                                        var $this = $( this );
                                                        $this.parent().prev( 'p' ).append( $this );
                                                } );
-                                               descriptionContainer.append( $( '<div>', { addClass: 'description', append: tmp } ) );
+                                               descriptionContainer.append( $( '<div>' ).addClass( 'description' ).append( tmp ) );
 
                                                if ( pi.parameters[ i ].info && pi.parameters[ i ].info.length ) {
                                                        for ( j = 0; j < pi.parameters[ i ].info.length; j++ ) {
-                                                               descriptionContainer.append( $( '<div>', {
-                                                                       addClass: 'info',
-                                                                       append: Util.parseHTML( pi.parameters[ i ].info[ j ] )
-                                                               } ) );
+                                                               descriptionContainer.append( $( '<div>' )
+                                                                       .addClass( 'info' )
+                                                                       .append( Util.parseHTML( pi.parameters[ i ].info[ j ] ) )
+                                                               );
                                                        }
                                                }
                                                flag = true;
 
                                                        case 'limit':
                                                                if ( pi.parameters[ i ].highmax !== undefined ) {
-                                                                       descriptionContainer.append( $( '<div>', {
-                                                                               addClass: 'info',
-                                                                               append: [
+                                                                       descriptionContainer.append( $( '<div>' )
+                                                                               .addClass( 'info' )
+                                                                               .append(
                                                                                        Util.parseMsg(
                                                                                                'api-help-param-limit2', pi.parameters[ i ].max, pi.parameters[ i ].highmax
                                                                                        ),
                                                                                        ' ',
                                                                                        Util.parseMsg( 'apisandbox-param-limit' )
-                                                                               ]
-                                                                       } ) );
+                                                                               )
+                                                                       );
                                                                } else {
-                                                                       descriptionContainer.append( $( '<div>', {
-                                                                               addClass: 'info',
-                                                                               append: [
+                                                                       descriptionContainer.append( $( '<div>' )
+                                                                               .addClass( 'info' )
+                                                                               .append(
                                                                                        Util.parseMsg( 'api-help-param-limit', pi.parameters[ i ].max ),
                                                                                        ' ',
                                                                                        Util.parseMsg( 'apisandbox-param-limit' )
-                                                                               ]
-                                                                       } ) );
+                                                                               )
+                                                                       );
                                                                }
                                                                break;
 
                                                                        tmp += 'max';
                                                                }
                                                                if ( tmp !== '' ) {
-                                                                       descriptionContainer.append( $( '<div>', {
-                                                                               addClass: 'info',
-                                                                               append: Util.parseMsg(
+                                                                       descriptionContainer.append( $( '<div>' )
+                                                                               .addClass( 'info' )
+                                                                               .append( Util.parseMsg(
                                                                                        'api-help-param-integer-' + tmp,
                                                                                        Util.apiBool( pi.parameters[ i ].multi ) ? 2 : 1,
                                                                                        pi.parameters[ i ].min, pi.parameters[ i ].max
-                                                                               )
-                                                                       } ) );
+                                                                               ) )
+                                                                       );
                                                                }
                                                                break;
 
                                                                );
                                                        }
                                                        if ( tmp.length ) {
-                                                               descriptionContainer.append( $( '<div>', {
-                                                                       addClass: 'info',
-                                                                       append: Util.parseHTML( tmp.join( ' ' ) )
-                                                               } ) );
+                                                               descriptionContainer.append( $( '<div>' )
+                                                                       .addClass( 'info' )
+                                                                       .append( Util.parseHTML( tmp.join( ' ' ) ) )
+                                                               );
                                                        }
                                                }
                                                if ( 'maxbytes' in pi.parameters[ i ] ) {
-                                                       descriptionContainer.append( $( '<div>', {
-                                                               addClass: 'info',
-                                                               append: Util.parseMsg( 'api-help-param-maxbytes', pi.parameters[ i ].maxbytes )
-                                                       } ) );
+                                                       descriptionContainer.append( $( '<div>' )
+                                                               .addClass( 'info' )
+                                                               .append( Util.parseMsg( 'api-help-param-maxbytes', pi.parameters[ i ].maxbytes ) )
+                                                       );
                                                }
                                                if ( 'maxchars' in pi.parameters[ i ] ) {
-                                                       descriptionContainer.append( $( '<div>', {
-                                                               addClass: 'info',
-                                                               append: Util.parseMsg( 'api-help-param-maxchars', pi.parameters[ i ].maxchars )
-                                                       } ) );
+                                                       descriptionContainer.append( $( '<div>' )
+                                                               .addClass( 'info' )
+                                                               .append( Util.parseMsg( 'api-help-param-maxchars', pi.parameters[ i ].maxchars ) )
+                                                       );
                                                }
                                                helpField = new OO.ui.FieldLayout(
                                                        new OO.ui.Widget( {