jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/403970 )
Change subject: Use native ES5 Array prototype methods instead of jQuery ...................................................................... Use native ES5 Array prototype methods instead of jQuery Replace * $.each( array, function ( index, value ) { ... } ) by array.forEach( function ( value, index ) { ... } ) * $.grep( array, function ( value ) { ... } ) by array.filter( function ( value ) { ... } ) * $.map( array, function ( value ) { ... } ) by array.map( function ( value ) { ... } ) * $.inArray( value, array ) by array.indexOf( value ) This change is a follow-up to 1edba8029a561919febf8b90f5df689d090665dd. Change-Id: I16134642c52002de0eacb987bed5143f528bf627 --- M resources/src/jquery/jquery.suggestions.js M resources/src/jquery/jquery.tablesorter.js M resources/src/mediawiki.action/mediawiki.action.edit.stash.js M resources/src/mediawiki.special/mediawiki.special.apisandbox.js M resources/src/mediawiki.special/mediawiki.special.block.js M resources/src/mediawiki.special/mediawiki.special.upload.js M resources/src/mediawiki/api.js M resources/src/mediawiki/mediawiki.jqueryMsg.js M resources/src/mediawiki/page/image-pagination.js M tests/qunit/suites/resources/jquery/jquery.textSelection.test.js M tests/qunit/suites/resources/mediawiki.api/mediawiki.api.options.test.js M tests/qunit/suites/resources/mediawiki.api/mediawiki.api.test.js M tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js 13 files changed, 37 insertions(+), 41 deletions(-) Approvals: Krinkle: Looks good to me, approved jenkins-bot: Verified Jforrester: Looks good to me, but someone else must approve diff --git a/resources/src/jquery/jquery.suggestions.js b/resources/src/jquery/jquery.suggestions.js index 4f4edc9..39c601f 100644 --- a/resources/src/jquery/jquery.suggestions.js +++ b/resources/src/jquery/jquery.suggestions.js @@ -293,7 +293,7 @@ expandFrom = 'left'; // Catch invalid values, default to 'auto' - } else if ( $.inArray( expandFrom, [ 'left', 'right', 'start', 'end', 'auto' ] ) === -1 ) { + } else if ( [ 'left', 'right', 'start', 'end', 'auto' ].indexOf( expandFrom ) === -1 ) { expandFrom = 'auto'; } @@ -757,7 +757,7 @@ ]; if ( context.data.keypressedCount === 0 && e.which === context.data.keypressed && - $.inArray( e.which, allowed ) !== -1 + allowed.indexOf( e.which ) !== -1 ) { $.suggestions.keypress( e, context, context.data.keypressed ); } diff --git a/resources/src/jquery/jquery.tablesorter.js b/resources/src/jquery/jquery.tablesorter.js index 21209f6..6d67ade 100644 --- a/resources/src/jquery/jquery.tablesorter.js +++ b/resources/src/jquery/jquery.tablesorter.js @@ -289,8 +289,8 @@ function uniqueElements( array ) { var uniques = []; - $.each( array, function ( i, elem ) { - if ( elem !== undefined && $.inArray( elem, uniques ) === -1 ) { + array.forEach( function ( elem ) { + if ( elem !== undefined && uniques.indexOf( elem ) === -1 ) { uniques.push( elem ); } } ); @@ -925,9 +925,8 @@ cell = this; // Get current column index columns = config.headerToColumns[ $cell.data( 'headerIndex' ) ]; - newSortList = $.map( columns, function ( c ) { - // jQuery "helpfully" flattens the arrays... - return [ [ c, $cell.data( 'order' ) ] ]; + newSortList = columns.map( function ( c ) { + return [ c, $cell.data( 'order' ) ]; } ); // Index of first column belonging to this header i = columns[ 0 ]; diff --git a/resources/src/mediawiki.action/mediawiki.action.edit.stash.js b/resources/src/mediawiki.action/mediawiki.action.edit.stash.js index 31c22af..5ae91e8 100644 --- a/resources/src/mediawiki.action/mediawiki.action.edit.stash.js +++ b/resources/src/mediawiki.action/mediawiki.action.edit.stash.js @@ -156,7 +156,7 @@ mw.util.getParamValue( 'undo' ) !== null || // Pressing "show changes" and "preview" also signify that the user will // probably save the page soon - $.inArray( $form.find( '#mw-edit-mode' ).val(), [ 'preview', 'diff' ] ) > -1 + [ 'preview', 'diff' ].indexOf( $form.find( '#mw-edit-mode' ).val() ) > -1 ) { checkStash(); } diff --git a/resources/src/mediawiki.special/mediawiki.special.apisandbox.js b/resources/src/mediawiki.special/mediawiki.special.apisandbox.js index a6450e9..35d82b2 100644 --- a/resources/src/mediawiki.special/mediawiki.special.apisandbox.js +++ b/resources/src/mediawiki.special/mediawiki.special.apisandbox.js @@ -1420,7 +1420,7 @@ for ( j = 0; j < tmp.length; j++ ) { availableFormats[ tmp[ j ] ] = true; } - pi.parameters[ i ].type = $.grep( tmp, filterFmModules ); + pi.parameters[ i ].type = tmp.filter( filterFmModules ); pi.parameters[ i ][ 'default' ] = 'json'; pi.parameters[ i ].required = true; } @@ -1429,7 +1429,7 @@ // Hide the 'wrappedhtml' parameter on format modules if ( pi.group === 'format' ) { - pi.parameters = $.grep( pi.parameters, function ( p ) { + pi.parameters = pi.parameters.filter( function ( p ) { return p.name !== 'wrappedhtml'; } ); } @@ -1451,7 +1451,7 @@ popup: { width: 'auto', padded: true, - $content: $( '<ul>' ).append( $.map( pi.helpurls, function ( link ) { + $content: $( '<ul>' ).append( pi.helpurls.map( function ( link ) { return $( '<li>' ).append( $( '<a>' ) .attr( { href: link, target: '_blank' } ) .text( link ) @@ -1469,7 +1469,7 @@ popup: { width: 'auto', padded: true, - $content: $( '<ul>' ).append( $.map( pi.examples, function ( example ) { + $content: $( '<ul>' ).append( pi.examples.map( function ( example ) { var a = $( '<a>' ) .attr( 'href', '#' + example.query ) .html( example.description ); diff --git a/resources/src/mediawiki.special/mediawiki.special.block.js b/resources/src/mediawiki.special/mediawiki.special.block.js index 491a1ff..49e471e 100644 --- a/resources/src/mediawiki.special/mediawiki.special.block.js +++ b/resources/src/mediawiki.special/mediawiki.special.block.js @@ -31,8 +31,8 @@ expiryValue = expiryWidget.dropdowninput.getValue(), // infinityValues are the values the SpecialBlock class accepts as infinity (sf. wfIsInfinity) infinityValues = [ 'infinite', 'indefinite', 'infinity', 'never' ], - isIndefinite = $.inArray( expiryValue, infinityValues ) !== -1 || - ( expiryValue === 'other' && $.inArray( expiryWidget.textinput.getValue(), infinityValues ) !== -1 ); + isIndefinite = infinityValues.indexOf( expiryValue ) !== -1 || + ( expiryValue === 'other' && infinityValues.indexOf( expiryWidget.textinput.getValue() ) !== -1 ); if ( enableAutoblockField ) { enableAutoblockField.toggle( !( isNonEmptyIp ) ); diff --git a/resources/src/mediawiki.special/mediawiki.special.upload.js b/resources/src/mediawiki.special/mediawiki.special.upload.js index 214ee60..1a3f26c 100644 --- a/resources/src/mediawiki.special/mediawiki.special.upload.js +++ b/resources/src/mediawiki.special/mediawiki.special.upload.js @@ -219,17 +219,14 @@ if ( mw.config.get( 'wgCheckFileExtensions' ) && mw.config.get( 'wgStrictFileExtensions' ) && - mw.config.get( 'wgFileExtensions' ) && + Array.isArray( mw.config.get( 'wgFileExtensions' ) ) && $( this ).attr( 'id' ) !== 'wpUploadFileURL' ) { if ( fname.lastIndexOf( '.' ) === -1 || - $.inArray( - fname.slice( fname.lastIndexOf( '.' ) + 1 ).toLowerCase(), - $.map( mw.config.get( 'wgFileExtensions' ), function ( element ) { - return element.toLowerCase(); - } ) - ) === -1 + mw.config.get( 'wgFileExtensions' ).map( function ( element ) { + return element.toLowerCase(); + } ).indexOf( fname.slice( fname.lastIndexOf( '.' ) + 1 ).toLowerCase() ) === -1 ) { // Not a valid extension // Clear the upload and set mw-upload-permitted to error @@ -291,7 +288,7 @@ function fileIsPreviewable( file ) { var known = [ 'image/png', 'image/gif', 'image/jpeg', 'image/svg+xml' ], tooHuge = 10 * 1024 * 1024; - return ( $.inArray( file.type, known ) !== -1 ) && file.size > 0 && file.size < tooHuge; + return ( known.indexOf( file.type ) !== -1 ) && file.size > 0 && file.size < tooHuge; } /** diff --git a/resources/src/mediawiki/api.js b/resources/src/mediawiki/api.js index 2fcb4be..2e5a92e 100644 --- a/resources/src/mediawiki/api.js +++ b/resources/src/mediawiki/api.js @@ -42,7 +42,7 @@ 'import', 'options' ]; - if ( $.inArray( action, csrfActions ) !== -1 ) { + if ( csrfActions.indexOf( action ) !== -1 ) { mw.track( 'mw.deprecate', 'apitoken_' + action ); mw.log.warn( 'Use of the "' + action + '" token is deprecated. Use "csrf" instead.' ); return 'csrf'; diff --git a/resources/src/mediawiki/mediawiki.jqueryMsg.js b/resources/src/mediawiki/mediawiki.jqueryMsg.js index e1681fa..8b25a0b 100644 --- a/resources/src/mediawiki/mediawiki.jqueryMsg.js +++ b/resources/src/mediawiki/mediawiki.jqueryMsg.js @@ -698,14 +698,14 @@ startTagName = startTagName.toLowerCase(); endTagName = endTagName.toLowerCase(); - if ( startTagName !== endTagName || $.inArray( startTagName, settings.allowedHtmlElements ) === -1 ) { + if ( startTagName !== endTagName || settings.allowedHtmlElements.indexOf( startTagName ) === -1 ) { return false; } for ( i = 0, len = attributes.length; i < len; i += 2 ) { attributeName = attributes[ i ]; - if ( $.inArray( attributeName, settings.allowedHtmlCommonAttributes ) === -1 && - $.inArray( attributeName, settings.allowedHtmlAttributesByElement[ startTagName ] || [] ) === -1 ) { + if ( settings.allowedHtmlCommonAttributes.indexOf( attributeName ) === -1 && + ( settings.allowedHtmlAttributesByElement[ startTagName ] || [] ).indexOf( attributeName ) === -1 ) { return false; } } diff --git a/resources/src/mediawiki/page/image-pagination.js b/resources/src/mediawiki/page/image-pagination.js index 6a7d0b9..06c34a5 100644 --- a/resources/src/mediawiki/page/image-pagination.js +++ b/resources/src/mediawiki/page/image-pagination.js @@ -23,7 +23,7 @@ // Try the cache if ( cache[ url ] ) { // Update access freshness - cacheOrder.splice( $.inArray( url, cacheOrder ), 1 ); + cacheOrder.splice( cacheOrder.indexOf( url ), 1 ); cacheOrder.push( url ); return $.Deferred().resolve( cache[ url ] ).promise(); } diff --git a/tests/qunit/suites/resources/jquery/jquery.textSelection.test.js b/tests/qunit/suites/resources/jquery/jquery.textSelection.test.js index 5b3c2ed..32cda7e 100644 --- a/tests/qunit/suites/resources/jquery/jquery.textSelection.test.js +++ b/tests/qunit/suites/resources/jquery/jquery.textSelection.test.js @@ -224,7 +224,7 @@ function among( actual, expected, message ) { if ( Array.isArray( expected ) ) { - assert.ok( $.inArray( actual, expected ) !== -1, message + ' (got ' + actual + '; expected one of ' + expected.join( ', ' ) + ')' ); + assert.ok( expected.indexOf( actual ) !== -1, message + ' (got ' + actual + '; expected one of ' + expected.join( ', ' ) + ')' ); } else { assert.equal( actual, expected, message ); } diff --git a/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.options.test.js b/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.options.test.js index 4ee8038..997a42c 100644 --- a/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.options.test.js +++ b/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.options.test.js @@ -30,7 +30,7 @@ // Requests are POST, match requestBody instead of url this.server.respond( function ( request ) { - if ( $.inArray( request.requestBody, [ + if ( [ // simple 'action=options&format=json&formatversion=2&change=foo%3Dbar&token=%2B%5C', // two options @@ -43,7 +43,7 @@ 'action=options&format=json&formatversion=2&change=foo&token=%2B%5C', // reset an option, not bundleable 'action=options&format=json&formatversion=2&optionname=foo%7Cbar%3Dquux&token=%2B%5C' - ] ) !== -1 ) { + ].indexOf( request.requestBody ) !== -1 ) { assert.ok( true, 'Repond to ' + request.requestBody ); request.respond( 200, { 'Content-Type': 'application/json' }, '{ "options": "success" }' ); @@ -88,7 +88,7 @@ // Requests are POST, match requestBody instead of url this.server.respond( function ( request ) { - if ( $.inArray( request.requestBody, [ + if ( [ // simple 'action=options&format=json&formatversion=2&change=foo%3Dbar&token=%2B%5C', // two options @@ -102,7 +102,7 @@ 'action=options&format=json&formatversion=2&change=foo&token=%2B%5C', // reset an option, not bundleable 'action=options&format=json&formatversion=2&optionname=foo%7Cbar%3Dquux&token=%2B%5C' - ] ) !== -1 ) { + ].indexOf( request.requestBody ) !== -1 ) { assert.ok( true, 'Repond to ' + request.requestBody ); request.respond( 200, diff --git a/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.test.js b/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.test.js index 5a92da4..417ad3d 100644 --- a/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.test.js +++ b/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.test.js @@ -18,7 +18,7 @@ } function sequenceBodies( status, headers, bodies ) { - jQuery.each( bodies, function ( i, body ) { + bodies.forEach( function ( body, i ) { bodies[ i ] = [ status, headers, body ]; } ); return sequence( bodies ); diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js b/tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js index 67ee3b8..2a563c8 100644 --- a/tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js +++ b/tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js @@ -504,11 +504,11 @@ ] ]; - $.each( testCases, function () { + testCases.forEach( function ( testCase ) { var - key = this[ 0 ], - input = this[ 1 ], - output = this[ 2 ]; + key = testCase[ 0 ], + input = testCase[ 1 ], + output = testCase[ 2 ]; mw.messages.set( key, input ); assert.htmlEqual( formatParse( key ), @@ -592,11 +592,11 @@ ] ]; - $.each( testCases, function () { + testCases.forEach( function ( testCase ) { var - key = this[ 0 ], - input = this[ 1 ], - output = this[ 2 ], + key = testCase[ 0 ], + input = testCase[ 1 ], + output = testCase[ 2 ], paramHref = key.slice( 0, 8 ) === 'wikilink' ? 'Example' : 'http://example.com', paramText = 'Text'; mw.messages.set( key, input ); -- To view, visit https://gerrit.wikimedia.org/r/403970 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I16134642c52002de0eacb987bed5143f528bf627 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Fomafix <foma...@googlemail.com> Gerrit-Reviewer: Anomie <bjor...@wikimedia.org> Gerrit-Reviewer: Jforrester <jforres...@wikimedia.org> Gerrit-Reviewer: Krinkle <krinklem...@gmail.com> Gerrit-Reviewer: Mattflaschen <mflasc...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits