Use native ES5 Array prototype methods instead of jQuery
authorFomafix <fomafix@googlemail.com>
Thu, 18 Jan 2018 15:24:43 +0000 (16:24 +0100)
committerFomafix <fomafix@googlemail.com>
Thu, 18 Jan 2018 18:44:35 +0000 (19:44 +0100)
Replace
* $.each( array, function ( index, value ) { ... } ) by
  array.forEach( function ( value ) { ... } )

* $.each( array, function () { ... this ... } ) by
  array.forEach( function ( value ) { ... value ... } )

Also replace forEach by map, to simplify the code.

Change-Id: I657c737d356cb6e310bc6351a7869a60955ebed9

resources/src/jquery/jquery.tablesorter.js
resources/src/mediawiki.action/mediawiki.action.edit.preview.js
resources/src/mediawiki.toolbar/toolbar.js
resources/src/mediawiki/api/messages.js
resources/src/mediawiki/mediawiki.Upload.BookletLayout.js

index 6d67ade..d712c0c 100644 (file)
 
        /**
         * Converts sort objects [ { Integer: String }, ... ] to the internally used nested array
-        * structure [ [ Integer , Integer ], ... ]
+        * structure [ [ Integer, Integer ], ... ]
         *
         * @param {Array} sortObjects List of sort objects.
         * @return {Array} List of internal sort definitions.
         */
        function convertSortList( sortObjects ) {
                var sortList = [];
-               $.each( sortObjects, function ( i, sortObject ) {
+               sortObjects.forEach( function ( sortObject ) {
                        $.each( sortObject, function ( columnIndex, order ) {
                                var orderIndex = ( order === 'desc' ) ? 1 : 0;
                                sortList.push( [ parseInt( columnIndex, 10 ), orderIndex ] );
index ab1ce27..b86f5c8 100644 (file)
 
                        parseRequest = api.post( postData );
                        parseRequest.done( function ( response ) {
-                               var li, newList, $displaytitle, $content, $parent, $list;
+                               var newList, $displaytitle, $content, $parent, $list;
                                if ( response.parse.jsconfigvars ) {
                                        mw.config.set( response.parse.jsconfigvars );
                                }
                                        $( '.catlinks[data-mw="interface"]' ).replaceWith( $content );
                                }
                                if ( response.parse.templates ) {
-                                       newList = [];
-                                       $.each( response.parse.templates, function ( i, template ) {
-                                               li = $( '<li>' )
+                                       newList = response.parse.templates.map( function ( template ) {
+                                               return $( '<li>' )
                                                        .append( $( '<a>' )
                                                                .attr( {
                                                                        href: mw.util.getUrl( template.title ),
                                                                } )
                                                                .text( template.title )
                                                        );
-                                               newList.push( li );
                                        } );
 
                                        $editform.find( '.templatesUsed .mw-editfooter-list' ).detach().empty().append( newList ).appendTo( '.templatesUsed' );
                                        $( '.limitreport' ).html( response.parse.limitreporthtml );
                                }
                                if ( response.parse.langlinks && mw.config.get( 'skin' ) === 'vector' ) {
-                                       newList = [];
-                                       $.each( response.parse.langlinks, function ( i, langlink ) {
+                                       newList = response.parse.langlinks.map( function ( langlink ) {
                                                var bcp47 = mw.language.bcp47( langlink.lang );
-                                               li = $( '<li>' )
+                                               return $( '<li>' )
                                                        .addClass( 'interlanguage-link interwiki-' + langlink.lang )
                                                        .append( $( '<a>' )
                                                                .attr( {
                                                                } )
                                                                .text( langlink.autonym )
                                                        );
-                                               newList.push( li );
                                        } );
                                        $list = $( '#p-lang ul' );
                                        $parent = $list.parent();
index d55ed80..4707f78 100644 (file)
                                buttons = slice.call( arguments );
                        }
                        if ( isReady ) {
-                               $.each( buttons, function () {
-                                       insertButton( this );
+                               buttons.forEach( function ( button ) {
+                                       insertButton( button );
                                } );
                        } else {
                                // Push each button into the queue
index a1a4999..688f0b2 100644 (file)
@@ -28,7 +28,7 @@
                        }, options ) ).then( function ( data ) {
                                var result = {};
 
-                               $.each( data.query.allmessages, function ( i, obj ) {
+                               data.query.allmessages.forEach( function ( obj ) {
                                        if ( !obj.missing ) {
                                                result[ obj.name ] = obj.content;
                                        }
index 3ade332..06788f5 100644 (file)
                                        $( '<p>' ).msg( 'filepageexists', 'File:' + warnings[ 'page-exists' ] ),
                                        { recoverable: false }
                                ) );
-                       } else if ( warnings.duplicate !== undefined ) {
-                               $.each( warnings.duplicate, function ( i, filename ) {
+                       } else if ( Array.isArray( warnings.duplicate ) ) {
+                               warnings.duplicate.forEach( function ( filename ) {
                                        var $a = $( '<a>' ).text( filename ),
                                                href = mw.Title.makeTitle( mw.config.get( 'wgNamespaceIds' ).file, filename ).getUrl( {} );