Use native ES5 Array prototype methods instead of jQuery
authorFomafix <fomafix@googlemail.com>
Fri, 22 Sep 2017 04:46:40 +0000 (06:46 +0200)
committerFomafix <fomafix@googlemail.com>
Fri, 22 Sep 2017 20:58:44 +0000 (22:58 +0200)
Replace
* $.each( array, function ( index, value ) { ... } ) by
  array.forEach( function ( value ) { ... } )

* $.grep( array, function ( value ) { ... } ) by
  array.filter( function ( value ) { ... } )

* $.map( array, function ( value ) { ... } ) by
  array.map( function ( value ) { ... } )

Change-Id: I985ddf710e13c9ae788245349e2791571aeec97e

resources/src/jquery/jquery.accessKeyLabel.js
resources/src/jquery/jquery.color.js
resources/src/jquery/jquery.localize.js
resources/src/jquery/jquery.tablesorter.js
resources/src/mediawiki.language/mediawiki.language.months.js
resources/src/mediawiki.legacy/wikibits.js
resources/src/mediawiki.special/mediawiki.special.apisandbox.js
resources/src/mediawiki.special/mediawiki.special.import.js
resources/src/mediawiki/api.js
resources/src/mediawiki/mediawiki.inspect.js
resources/src/mediawiki/mediawiki.js

index 4f900a4..91b7035 100644 (file)
                }
 
                parts = ( mw.msg( 'word-separator' ) + mw.msg( 'brackets' ) ).split( '$1' );
-               regexp = new RegExp( $.map( parts, mw.RegExp.escape ).join( '.*?' ) + '$' );
+               regexp = new RegExp( parts.map( mw.RegExp.escape ).join( '.*?' ) + '$' );
                newTitle = oldTitle.replace( regexp, '' );
                accessKeyLabel = getAccessKeyLabel( element );
 
index 847afd4..894cf86 100644 (file)
@@ -28,7 +28,7 @@
        }
 
        // We override the animation for all of these color styles
-       $.each( [
+       [
                'backgroundColor',
                'borderBottomColor',
                'borderLeftColor',
@@ -36,7 +36,7 @@
                'borderTopColor',
                'color',
                'outlineColor'
-       ], function ( i, attr ) {
+       ].forEach( function ( attr ) {
                $.fx.step[ attr ] = function ( fx ) {
                        if ( !fx.colorInit ) {
                                fx.start = getColor( fx.elem, attr );
index 05b3891..b1bf0f4 100644 (file)
                // Attributes
                // Note: there's no way to prevent escaping of values being injected into attributes, this is
                // on purpose, not a design flaw.
-               $.each( attributes, function ( i, attr ) {
+               attributes.forEach( function ( attr ) {
                        var msgAttr = attr + '-msg';
                        $target.find( '[' + msgAttr + ']' ).each( function () {
                                var $el = $( this );
index ecd376a..cac103e 100644 (file)
@@ -77,7 +77,7 @@
                if ( node.tagName.toLowerCase() === 'img' ) {
                        return $node.attr( 'alt' ) || ''; // handle undefined alt
                }
-               return $.map( $.makeArray( node.childNodes ), function ( elem ) {
+               return $.makeArray( node.childNodes ).map( function ( elem ) {
                        if ( elem.nodeType === Node.ELEMENT_NODE ) {
                                return getElementSortKey( elem );
                        }
index 5a1a5cb..7b78562 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Loading this module also ensures the availability of appropriate messages via mw.msg.
  */
-( function ( mw, $ ) {
+( function ( mw ) {
        var
                monthMessages = [
                        'january', 'february', 'march', 'april',
@@ -21,8 +21,8 @@
                        'sep', 'oct', 'nov', 'dec'
                ];
 
-       // Function suitable for passing to jQuery.map
-       // Can't use mw.msg directly because jQuery.map passes element index as second argument
+       // Function suitable for passing to Array.prototype.map
+       // Can't use mw.msg directly because Array.prototype.map passes element index as second argument
        function mwMsgMapper( key ) {
                return mw.msg( key );
        }
@@ -48,9 +48,9 @@
                        genitive: monthGenMessages,
                        abbrev: monthAbbrevMessages
                },
-               names: $.map( monthMessages, mwMsgMapper ),
-               genitive: $.map( monthGenMessages, mwMsgMapper ),
-               abbrev: $.map( monthAbbrevMessages, mwMsgMapper )
+               names: monthMessages.map( mwMsgMapper ),
+               genitive: monthGenMessages.map( mwMsgMapper ),
+               abbrev: monthAbbrevMessages.map( mwMsgMapper )
        };
 
-}( mediaWiki, jQuery ) );
+}( mediaWiki ) );
index bd1b918..f5bdfd8 100644 (file)
@@ -96,7 +96,7 @@
         *
         * @deprecated since 1.26
         */
-       $.each( [ 'write', 'writeln' ], function ( idx, method ) {
+       [ 'write', 'writeln' ].forEach( function ( method ) {
                mw.log.deprecate( document, method, function () {
                        $( 'body' ).append( $.parseHTML( Array.prototype.join.call( arguments, '' ) ) );
                }, 'Use jQuery or mw.loader.load instead.', 'document.' + method );
index 9e8d4f4..7029116 100644 (file)
                        multi: function () {
                                var map = this.paramInfo.submodules,
                                        v = this.isDisabled() ? this.paramInfo[ 'default' ] : this.getApiValue();
-                               return v === undefined || v === '' ? [] : $.map( String( v ).split( '|' ), function ( v ) {
+                               return v === undefined || v === '' ? [] : String( v ).split( '|' ).map( function ( v ) {
                                        return { value: v, path: map[ v ] };
                                } );
                        }
                                                throw new Error( 'Unknown parameter type ' + pi.type );
                                        }
 
-                                       items = $.map( pi.type, function ( v ) {
+                                       items = pi.type.map( function ( v ) {
                                                var config = {
                                                        data: String( v ),
                                                        label: String( v ),
index 3357461..2cb96af 100644 (file)
@@ -11,7 +11,7 @@
                        option, options;
 
                if ( $selected.attr( 'data-subprojects' ) ) {
-                       options = $.map( $selected.attr( 'data-subprojects' ).split( ' ' ), function ( el ) {
+                       options = $selected.attr( 'data-subprojects' ).split( ' ' ).map( function ( el ) {
                                option = document.createElement( 'option' );
                                option.appendChild( document.createTextNode( el ) );
                                option.setAttribute( 'value', el );
index b4639ab..f178698 100644 (file)
                 * @method
                 */
                abort: function () {
-                       $.each( this.requests, function ( index, request ) {
+                       this.requests.forEach( function ( request ) {
                                if ( request ) {
                                        request.abort();
                                }
index 9332773..006ca1f 100644 (file)
@@ -47,7 +47,7 @@
                        var modules = inspect.getLoadedModules(),
                                graph = {};
 
-                       $.each( modules, function ( moduleIndex, moduleName ) {
+                       modules.forEach( function ( moduleName ) {
                                var dependencies = mw.loader.moduleRegistry[ moduleName ].dependencies || [];
 
                                if ( !hasOwn.call( graph, moduleName ) ) {
                 * @return {Array} List of module names
                 */
                getLoadedModules: function () {
-                       return $.grep( mw.loader.getModuleNames(), function ( module ) {
+                       return mw.loader.getModuleNames().filter( function ( module ) {
                                return mw.loader.getState( module ) === 'ready';
                        } );
                },
                                Array.prototype.slice.call( arguments ) :
                                $.map( inspect.reports, function ( v, k ) { return k; } );
 
-                       $.each( reports, function ( index, name ) {
+                       reports.forEach( function ( name ) {
                                inspect.dumpTable( inspect.reports[ name ]() );
                        } );
                },
                         */
                        size: function () {
                                // Map each module to a descriptor object.
-                               var modules = $.map( inspect.getLoadedModules(), function ( module ) {
+                               var modules = inspect.getLoadedModules().map( function ( module ) {
                                        return {
                                                name: module,
                                                size: inspect.getModuleSize( module )
                                sortByProperty( modules, 'size', true );
 
                                // Convert size to human-readable string.
-                               $.each( modules, function ( i, module ) {
+                               modules.forEach( function ( module ) {
                                        module.sizeInBytes = module.size;
                                        module.size = humanSize( module.size );
                                } );
                        css: function () {
                                var modules = [];
 
-                               $.each( inspect.getLoadedModules(), function ( index, name ) {
+                               inspect.getLoadedModules().forEach( function ( name ) {
                                        var css, stats, module = mw.loader.moduleRegistry[ name ];
 
                                        try {
                                pattern = new RegExp( mw.RegExp.escape( pattern ), 'g' );
                        }
 
-                       return $.grep( inspect.getLoadedModules(), function ( moduleName ) {
+                       return inspect.getLoadedModules().filter( function ( moduleName ) {
                                var module = mw.loader.moduleRegistry[ moduleName ];
 
                                // Grep module's JavaScript
index 506d60a..aae292d 100644 (file)
                                        } );
                                }
 
-                               $.each( dependencies, function ( idx, module ) {
+                               dependencies.forEach( function ( module ) {
                                        var state = mw.loader.getState( module );
                                        // Only queue modules that are still in the initial 'registered' state
                                        // (not ones already loading, ready or error).