From: Fomafix Date: Fri, 17 Mar 2017 05:31:13 +0000 (+0100) Subject: Replace deprecated jQuery.isArray by Array.isArray X-Git-Tag: 1.31.0-rc.0~3607^2 X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/modifier.php?a=commitdiff_plain;h=93aafce974bce277a5c167e1f08348bb636c026c;p=lhc%2Fweb%2Fwiklou.git Replace deprecated jQuery.isArray by Array.isArray 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 --- diff --git a/resources/src/jquery/jquery.colorUtil.js b/resources/src/jquery/jquery.colorUtil.js index c53ec3b147..2be1dbaea5 100644 --- a/resources/src/jquery/jquery.colorUtil.js +++ b/resources/src/jquery/jquery.colorUtil.js @@ -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; } diff --git a/resources/src/jquery/jquery.mwExtension.js b/resources/src/jquery/jquery.mwExtension.js index f9675fa69c..6d478bd355 100644 --- a/resources/src/jquery/jquery.mwExtension.js +++ b/resources/src/jquery/jquery.mwExtension.js @@ -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; } diff --git a/resources/src/mediawiki.special/mediawiki.special.apisandbox.js b/resources/src/mediawiki.special/mediawiki.special.apisandbox.js index 97659edca3..7cb67b0084 100644 --- a/resources/src/mediawiki.special/mediawiki.special.apisandbox.js +++ b/resources/src/mediawiki.special/mediawiki.special.apisandbox.js @@ -473,7 +473,7 @@ break; default: - if ( !$.isArray( pi.type ) ) { + if ( !Array.isArray( pi.type ) ) { throw new Error( 'Unknown parameter type ' + pi.type ); } @@ -1532,7 +1532,7 @@ break; default: - if ( $.isArray( pi.parameters[ i ].type ) ) { + if ( Array.isArray( pi.parameters[ i ].type ) ) { flag = false; count = pi.parameters[ i ].type.length; } diff --git a/resources/src/mediawiki.toolbar/toolbar.js b/resources/src/mediawiki.toolbar/toolbar.js index e9fc024605..2af8b2f20f 100644 --- a/resources/src/mediawiki.toolbar/toolbar.js +++ b/resources/src/mediawiki.toolbar/toolbar.js @@ -124,7 +124,7 @@ * button object in a list of variadic arguments. */ addButtons: function ( buttons ) { - if ( !$.isArray( buttons ) ) { + if ( !Array.isArray( buttons ) ) { buttons = slice.call( arguments ); } if ( isReady ) { @@ -180,7 +180,7 @@ 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 { diff --git a/resources/src/mediawiki.widgets/mw.widgets.CategoryMultiselectWidget.js b/resources/src/mediawiki.widgets/mw.widgets.CategoryMultiselectWidget.js index ccc5c9dcb4..5f680303b9 100644 --- a/resources/src/mediawiki.widgets/mw.widgets.CategoryMultiselectWidget.js +++ b/resources/src/mediawiki.widgets/mw.widgets.CategoryMultiselectWidget.js @@ -369,7 +369,7 @@ 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; } ) ); diff --git a/resources/src/mediawiki/api.js b/resources/src/mediawiki/api.js index 37c0c9b6dc..b4639ab427 100644 --- a/resources/src/mediawiki/api.js +++ b/resources/src/mediawiki/api.js @@ -162,7 +162,7 @@ // 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 { diff --git a/resources/src/mediawiki/api/watch.js b/resources/src/mediawiki/api/watch.js index 529925229d..f50e59a918 100644 --- a/resources/src/mediawiki/api/watch.js +++ b/resources/src/mediawiki/api/watch.js @@ -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 } ); } diff --git a/resources/src/mediawiki/htmlform/hide-if.js b/resources/src/mediawiki/htmlform/hide-if.js index 157ac06211..3bf75ae60e 100644 --- a/resources/src/mediawiki/htmlform/hide-if.js +++ b/resources/src/mediawiki/htmlform/hide-if.js @@ -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 ] ); @@ -131,7 +131,7 @@ 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 ] ); diff --git a/resources/src/mediawiki/mediawiki.Title.js b/resources/src/mediawiki/mediawiki.Title.js index 0e2af5060a..6765270a2b 100644 --- a/resources/src/mediawiki/mediawiki.Title.js +++ b/resources/src/mediawiki/mediawiki.Title.js @@ -745,7 +745,7 @@ 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++ ) { diff --git a/resources/src/mediawiki/mediawiki.Uri.js b/resources/src/mediawiki/mediawiki.Uri.js index 95263ec451..59261cdccf 100644 --- a/resources/src/mediawiki/mediawiki.Uri.js +++ b/resources/src/mediawiki/mediawiki.Uri.js @@ -198,7 +198,7 @@ // 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 ]; @@ -316,7 +316,7 @@ q[ k ] = [ q[ k ] ]; } // Add to the array - if ( $.isArray( q[ k ] ) ) { + if ( Array.isArray( q[ k ] ) ) { q[ k ].push( v ); } } @@ -366,7 +366,7 @@ 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 ); diff --git a/resources/src/mediawiki/mediawiki.inspect.js b/resources/src/mediawiki/mediawiki.inspect.js index 5c2f83f9d2..638fba7e63 100644 --- a/resources/src/mediawiki/mediawiki.inspect.js +++ b/resources/src/mediawiki/mediawiki.inspect.js @@ -315,7 +315,7 @@ // 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 diff --git a/resources/src/mediawiki/mediawiki.jqueryMsg.js b/resources/src/mediawiki/mediawiki.jqueryMsg.js index 282a2ee739..6d3b4f081a 100644 --- a/resources/src/mediawiki/mediawiki.jqueryMsg.js +++ b/resources/src/mediawiki/mediawiki.jqueryMsg.js @@ -73,7 +73,7 @@ function appendWithoutParsing( $parent, children ) { var i, len; - if ( !$.isArray( children ) ) { + if ( !Array.isArray( children ) ) { children = [ children ]; } @@ -138,7 +138,7 @@ // 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 ) { diff --git a/resources/src/mediawiki/mediawiki.js b/resources/src/mediawiki/mediawiki.js index c2cee7ec6f..cd3d915f72 100644 --- a/resources/src/mediawiki/mediawiki.js +++ b/resources/src/mediawiki/mediawiki.js @@ -144,7 +144,7 @@ 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' ) { @@ -205,7 +205,7 @@ */ 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; @@ -1321,7 +1321,7 @@ 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 @@ -1412,7 +1412,7 @@ // 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: { : [url, ..] } diff --git a/tests/qunit/suites/resources/jquery/jquery.textSelection.test.js b/tests/qunit/suites/resources/jquery/jquery.textSelection.test.js index f958e09315..5b3c2ed08b 100644 --- a/tests/qunit/suites/resources/jquery/jquery.textSelection.test.js +++ b/tests/qunit/suites/resources/jquery/jquery.textSelection.test.js @@ -223,7 +223,7 @@ } 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 ); diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.loader.test.js b/tests/qunit/suites/resources/mediawiki/mediawiki.loader.test.js index 477b04dcc9..7a0de81d8e 100644 --- a/tests/qunit/suites/resources/mediawiki/mediawiki.loader.test.js +++ b/tests/qunit/suites/resources/mediawiki/mediawiki.loader.test.js @@ -546,7 +546,7 @@ 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' ); } ); @@ -557,7 +557,7 @@ 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,