Replace deprecated jQuery.isArray by Array.isArray
authorFomafix <fomafix@googlemail.com>
Fri, 17 Mar 2017 05:31:13 +0000 (06:31 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Tue, 4 Apr 2017 02:55:07 +0000 (19:55 -0700)
jQuery.isArray gets deprecated in jQuery 3.2.0. [1]

Array.isArray is supported since the following browser versions: [2]
* Chrome 5
* Firefox (Gecko) 4.0 (2.0)
* Internet Explorer 9
* Opera 10.5
* Safari 5

Performed using:
find resources/src tests -type f -name \*.js -exec sed -i -e 's/\$\.isArray/Array.isArray/g' {} \;

[1] https://blog.jquery.com/2017/03/16/jquery-3-2-0-is-out/
[2] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray#Browser_compatibility

Bug: T160953
Change-Id: I1f5fe19d247ec420810e1c4a6db779425b69de23

15 files changed:
resources/src/jquery/jquery.colorUtil.js
resources/src/jquery/jquery.mwExtension.js
resources/src/mediawiki.special/mediawiki.special.apisandbox.js
resources/src/mediawiki.toolbar/toolbar.js
resources/src/mediawiki.widgets/mw.widgets.CategoryMultiselectWidget.js
resources/src/mediawiki/api.js
resources/src/mediawiki/api/watch.js
resources/src/mediawiki/htmlform/hide-if.js
resources/src/mediawiki/mediawiki.Title.js
resources/src/mediawiki/mediawiki.Uri.js
resources/src/mediawiki/mediawiki.inspect.js
resources/src/mediawiki/mediawiki.jqueryMsg.js
resources/src/mediawiki/mediawiki.js
tests/qunit/suites/resources/jquery/jquery.textSelection.test.js
tests/qunit/suites/resources/mediawiki/mediawiki.loader.test.js

index c53ec3b..2be1dba 100644 (file)
@@ -26,7 +26,7 @@
                        var result;
 
                        // Check if we're already dealing with an array of colors
-                       if ( color && $.isArray( color ) && color.length === 3 ) {
+                       if ( color && Array.isArray( color ) && color.length === 3 ) {
                                return color;
                        }
 
index f9675fa..6d478bd 100644 (file)
@@ -45,7 +45,7 @@
                                return false;
                        }
                        for ( i = 0; i < arrThis.length; i++ ) {
-                               if ( $.isArray( arrThis[ i ] ) ) {
+                               if ( Array.isArray( arrThis[ i ] ) ) {
                                        if ( !$.compareArray( arrThis[ i ], arrAgainst[ i ] ) ) {
                                                return false;
                                        }
index 97659ed..7cb67b0 100644 (file)
                                        break;
 
                                default:
-                                       if ( !$.isArray( pi.type ) ) {
+                                       if ( !Array.isArray( pi.type ) ) {
                                                throw new Error( 'Unknown parameter type ' + pi.type );
                                        }
 
                                                                break;
 
                                                        default:
-                                                               if ( $.isArray( pi.parameters[ i ].type ) ) {
+                                                               if ( Array.isArray( pi.parameters[ i ].type ) ) {
                                                                        flag = false;
                                                                        count = pi.parameters[ i ].type.length;
                                                                }
index e9fc024..2af8b2f 100644 (file)
                 *  button object in a list of variadic arguments.
                 */
                addButtons: function ( buttons ) {
-                       if ( !$.isArray( buttons ) ) {
+                       if ( !Array.isArray( buttons ) ) {
                                buttons = slice.call( arguments );
                        }
                        if ( isReady ) {
 
                for ( i = 0; i < queue.length; i++ ) {
                        button = queue[ i ];
-                       if ( $.isArray( button ) ) {
+                       if ( Array.isArray( button ) ) {
                                // Forwarded arguments array from mw.toolbar.addButton
                                insertButton.apply( toolbar, button );
                        } else {
index ccc5c9d..5f68030 100644 (file)
                                        var categories = [];
 
                                        $.each( res.query.pages, function ( index, page ) {
-                                               if ( !page.missing && $.isArray( page.categories ) ) {
+                                               if ( !page.missing && Array.isArray( page.categories ) ) {
                                                        categories.push.apply( categories, page.categories.map( function ( category ) {
                                                                return category.title;
                                                        } ) );
index 37c0c9b..b4639ab 100644 (file)
                        // Handle common MediaWiki API idioms for passing parameters
                        for ( key in parameters ) {
                                // Multiple values are pipe-separated
-                               if ( $.isArray( parameters[ key ] ) ) {
+                               if ( Array.isArray( parameters[ key ] ) ) {
                                        if ( !useUS || parameters[ key ].join( '' ).indexOf( '|' ) === -1 ) {
                                                parameters[ key ] = parameters[ key ].join( '|' );
                                        } else {
index 5299252..f50e59a 100644 (file)
@@ -28,7 +28,7 @@
                                {
                                        formatversion: 2,
                                        action: 'watch',
-                                       titles: $.isArray( pages ) ? pages.join( '|' ) : String( pages )
+                                       titles: Array.isArray( pages ) ? pages.join( '|' ) : String( pages )
                                },
                                addParams
                        )
@@ -37,7 +37,7 @@
                return apiPromise
                        .then( function ( data ) {
                                // If a single page was given (not an array) respond with a single item as well.
-                               return $.isArray( pages ) ? data.watch : data.watch[ 0 ];
+                               return Array.isArray( pages ) ? data.watch : data.watch[ 0 ];
                        } )
                        .promise( { abort: apiPromise.abort } );
        }
index 157ac06..3bf75ae 100644 (file)
@@ -66,7 +66,7 @@
                                funcs = [];
                                fields = [];
                                for ( i = 1; i < l; i++ ) {
-                                       if ( !$.isArray( spec[ i ] ) ) {
+                                       if ( !Array.isArray( spec[ i ] ) ) {
                                                throw new Error( op + ' parameters must be arrays' );
                                        }
                                        v = hideIfParse( $el, spec[ i ] );
                                if ( l !== 2 ) {
                                        throw new Error( 'NOT takes exactly one parameter' );
                                }
-                               if ( !$.isArray( spec[ 1 ] ) ) {
+                               if ( !Array.isArray( spec[ 1 ] ) ) {
                                        throw new Error( 'NOT parameters must be arrays' );
                                }
                                v = hideIfParse( $el, spec[ 1 ] );
index 0e2af50..6765270 100644 (file)
                        var i, len,
                                pages = this.pages;
 
-                       titles = $.isArray( titles ) ? titles : [ titles ];
+                       titles = Array.isArray( titles ) ? titles : [ titles ];
                        state = state === undefined ? true : !!state;
 
                        for ( i = 0, len = titles.length; i < len; i++ ) {
index 95263ec..59261cd 100644 (file)
                                                // Only copy direct properties, not inherited ones
                                                if ( uri.hasOwnProperty( prop ) ) {
                                                        // Deep copy object properties
-                                                       if ( $.isArray( uri[ prop ] ) || $.isPlainObject( uri[ prop ] ) ) {
+                                                       if ( Array.isArray( uri[ prop ] ) || $.isPlainObject( uri[ prop ] ) ) {
                                                                this[ prop ] = $.extend( true, {}, uri[ prop ] );
                                                        } else {
                                                                this[ prop ] = uri[ prop ];
                                                                        q[ k ] = [ q[ k ] ];
                                                                }
                                                                // Add to the array
-                                                               if ( $.isArray( q[ k ] ) ) {
+                                                               if ( Array.isArray( q[ k ] ) ) {
                                                                        q[ k ].push( v );
                                                                }
                                                        }
                                var args = [];
                                $.each( this.query, function ( key, val ) {
                                        var k = Uri.encode( key ),
-                                               vals = $.isArray( val ) ? val : [ val ];
+                                               vals = Array.isArray( val ) ? val : [ val ];
                                        $.each( vals, function ( i, v ) {
                                                if ( v === null ) {
                                                        args.push( k );
index 5c2f83f..638fba7 100644 (file)
 
                                // Grep module's CSS
                                if (
-                                       $.isPlainObject( module.style ) && $.isArray( module.style.css ) &&
+                                       $.isPlainObject( module.style ) && Array.isArray( module.style.css ) &&
                                        pattern.test( module.style.css.join( '' ) )
                                ) {
                                        // Module's CSS source matches
index 282a2ee..6d3b4f0 100644 (file)
@@ -73,7 +73,7 @@
        function appendWithoutParsing( $parent, children ) {
                var i, len;
 
-               if ( !$.isArray( children ) ) {
+               if ( !Array.isArray( children ) ) {
                        children = [ children ];
                }
 
                                // eslint-disable-next-line new-cap
                                parser = new mw.jqueryMsg.parser( options ),
                                key = args[ 0 ],
-                               argsArray = $.isArray( args[ 1 ] ) ? args[ 1 ] : slice.call( args, 1 );
+                               argsArray = Array.isArray( args[ 1 ] ) ? args[ 1 ] : slice.call( args, 1 );
                        try {
                                return parser.parse( key, argsArray );
                        } catch ( e ) {
index c2cee7e..cd3d915 100644 (file)
                        var results, i;
                        fallback = arguments.length > 1 ? fallback : null;
 
-                       if ( $.isArray( selection ) ) {
+                       if ( Array.isArray( selection ) ) {
                                results = {};
                                for ( i = 0; i < selection.length; i++ ) {
                                        if ( typeof selection[ i ] === 'string' ) {
                 */
                exists: function ( selection ) {
                        var i;
-                       if ( $.isArray( selection ) ) {
+                       if ( Array.isArray( selection ) ) {
                                for ( i = 0; i < selection.length; i++ ) {
                                        if ( typeof selection[ i ] !== 'string' || !hasOwn.call( this.values, selection[ i ] ) ) {
                                                return false;
 
                                        legacyWait.always( function () {
                                                try {
-                                                       if ( $.isArray( script ) ) {
+                                                       if ( Array.isArray( script ) ) {
                                                                nestedAddScript( script, markModuleReady, 0 );
                                                        } else if ( typeof script === 'function' ) {
                                                                // Pass jQuery twice so that the signature of the closure which wraps
 
                                                // Array of css strings in key 'css',
                                                // or back-compat array of urls from media-type
-                                               if ( $.isArray( value ) ) {
+                                               if ( Array.isArray( value ) ) {
                                                        for ( i = 0; i < value.length; i++ ) {
                                                                if ( key === 'bc-url' ) {
                                                                        // back-compat: { <media>: [url, ..] }
index f958e09..5b3c2ed 100644 (file)
                        }
 
                        function among( actual, expected, message ) {
-                               if ( $.isArray( expected ) ) {
+                               if ( Array.isArray( expected ) ) {
                                        assert.ok( $.inArray( actual, expected ) !== -1, message + ' (got ' + actual + '; expected one of ' + expected.join( ', ' ) + ')' );
                                } else {
                                        assert.equal( actual, expected, message );
index 477b04d..7a0de81 100644 (file)
                                assert.ok( true, 'QUnit expected() count dummy' );
                        },
                        function ( e, dependencies ) {
-                               assert.strictEqual( $.isArray( dependencies ), true, 'Expected array of dependencies' );
+                               assert.strictEqual( Array.isArray( dependencies ), true, 'Expected array of dependencies' );
                                assert.deepEqual( dependencies, [ 'test.module7' ], 'Error callback called with module test.module7' );
                        }
                );
                                assert.ok( true, 'QUnit expected() count dummy' );
                        },
                        function ( e, dependencies ) {
-                               assert.strictEqual( $.isArray( dependencies ), true, 'Expected array of dependencies' );
+                               assert.strictEqual( Array.isArray( dependencies ), true, 'Expected array of dependencies' );
                                dependencies.sort();
                                assert.deepEqual(
                                        dependencies,