Fomafix has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/403689 )
Change subject: [WIP] Use native ES5 Array prototype methods instead of jQuery
......................................................................
[WIP] 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 ) { ... } )
This change is a follow-up to 9d67e9973e6766e057c70ea8c811be8e269fb80a.
Change-Id: I8ef9af8c4d2f440faca65ec7c78a977ea7c31ad2
---
M resources/src/jquery/jquery.tablesorter.js
M resources/src/mediawiki.special/mediawiki.special.apisandbox.js
M resources/src/mediawiki.widgets.datetime/CalendarWidget.js
M resources/src/mediawiki/mediawiki.jqueryMsg.js
M tests/qunit/data/testrunner.js
M tests/qunit/suites/resources/jquery/jquery.highlightText.test.js
M tests/qunit/suites/resources/jquery/jquery.tablesorter.parsers.test.js
M tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js
M tests/qunit/suites/resources/mediawiki.api/mediawiki.api.test.js
M tests/qunit/suites/resources/mediawiki/mediawiki.RegExp.test.js
M tests/qunit/suites/resources/mediawiki/mediawiki.Uri.test.js
M tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js
M tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js
M tests/qunit/suites/resources/startup.test.js
14 files changed, 31 insertions(+), 31 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/89/403689/1
diff --git a/resources/src/jquery/jquery.tablesorter.js
b/resources/src/jquery/jquery.tablesorter.js
index cac103e..1dfdf4e 100644
--- a/resources/src/jquery/jquery.tablesorter.js
+++ b/resources/src/jquery/jquery.tablesorter.js
@@ -345,7 +345,7 @@
} );
} );
// We want to find the row that has the most columns
(ignoring colspan)
- $.each( exploded, function ( index, cellArray ) {
+ exploded.forEach( function ( cellArray, index ) {
headerCount = $( uniqueElements( cellArray )
).filter( 'th' ).length;
if ( headerCount >= maxSeen ) {
maxSeen = headerCount;
@@ -423,9 +423,9 @@
*/
function setHeadersOrder( $headers, sortList, headerToColumns ) {
// Loop through all headers to retrieve the indices of the
columns the header spans across:
- $.each( headerToColumns, function ( headerIndex, columns ) {
+ headerToColumns.forEach( function ( columns, headerIndex ) {
- $.each( columns, function ( i, columnIndex ) {
+ columns.forEach( function ( columnIndex, i ) {
var header = $headers[ headerIndex ],
$header = $( header );
@@ -437,7 +437,7 @@
} );
} else {
// Column shall be sorted: Apply
designated count and order.
- $.each( sortList, function ( j,
sortColumn ) {
+ sortList.forEach( function ( j,
sortColumn ) {
if ( sortColumn[ 0 ] === i ) {
$header.data( {
order:
sortColumn[ 1 ],
@@ -622,7 +622,7 @@
}
return ret;
} );
- $.each( rowspanCells, function () {
+ rowspanCells.forEach( function () {
$.data( this, 'tablesorter' ).needResort =
false;
} );
}
@@ -925,7 +925,7 @@
cell = this;
// Get current column index
columns =
config.headerToColumns[ $cell.data( 'headerIndex' ) ];
- newSortList = $.map( columns,
function ( c ) {
+ newSortList = columns.map(
function ( c ) {
// jQuery "helpfully"
flattens the arrays...
return [ [ c,
$cell.data( 'order' ) ] ];
} );
diff --git a/resources/src/mediawiki.special/mediawiki.special.apisandbox.js
b/resources/src/mediawiki.special/mediawiki.special.apisandbox.js
index 534af05..a6450e9 100644
--- a/resources/src/mediawiki.special/mediawiki.special.apisandbox.js
+++ b/resources/src/mediawiki.special/mediawiki.special.apisandbox.js
@@ -1074,7 +1074,7 @@
label:
Util.parseMsg( 'apisandbox-request-selectformat-label' )
}
).$element,
- $.map( formatItems, function (
item ) {
+ formatItems.map( function (
item ) {
return
item.getData().$element;
} ),
$result
diff --git a/resources/src/mediawiki.widgets.datetime/CalendarWidget.js
b/resources/src/mediawiki.widgets.datetime/CalendarWidget.js
index 54a5a85..fa05991 100644
--- a/resources/src/mediawiki.widgets.datetime/CalendarWidget.js
+++ b/resources/src/mediawiki.widgets.datetime/CalendarWidget.js
@@ -216,7 +216,7 @@
if ( dates instanceof Date ) {
dates = [ dates ];
} else if ( Array.isArray( dates ) ) {
- dates = $.grep( dates, function ( dt ) { return dt
instanceof Date; } );
+ dates = dates.filter( function ( dt ) { return dt
instanceof Date; } );
dates.sort();
} else {
dates = [];
diff --git a/resources/src/mediawiki/mediawiki.jqueryMsg.js
b/resources/src/mediawiki/mediawiki.jqueryMsg.js
index e1681fa..6aec203 100644
--- a/resources/src/mediawiki/mediawiki.jqueryMsg.js
+++ b/resources/src/mediawiki/mediawiki.jqueryMsg.js
@@ -1199,7 +1199,7 @@
}
// Remove explicit plural forms from the forms. They
were set undefined in the above loop.
- forms = $.map( forms, function ( form ) {
+ forms = forms.map( function ( form ) {
return form;
} );
diff --git a/tests/qunit/data/testrunner.js b/tests/qunit/data/testrunner.js
index e944ef0..5943294 100644
--- a/tests/qunit/data/testrunner.js
+++ b/tests/qunit/data/testrunner.js
@@ -309,14 +309,14 @@
// Test should use fake XHR, wait for
requests, or call abort()
$activeLen = $.active;
if ( $activeLen !== undefined &&
$activeLen !== 0 ) {
- pending = $.grep( ajaxRequests,
function ( ajax ) {
+ pending = ajaxRequests.filter(
function ( ajax ) {
return ajax.xhr.state()
=== 'pending';
} );
if ( pending.length !==
$activeLen ) {
mw.log.warn( 'Pending
requests does not match jQuery.active count' );
}
// Force requests to stop to
give the next test a clean start
- $.each( ajaxRequests, function
( i, ajax ) {
+ ajaxRequests.forEach( function
( ajax, i ) {
mw.log.warn(
'AJAX request
#' + i + ' (state: ' + ajax.xhr.state() + ')',
ajax.options
diff --git a/tests/qunit/suites/resources/jquery/jquery.highlightText.test.js
b/tests/qunit/suites/resources/jquery/jquery.highlightText.test.js
index 0dac22e..277ba3f 100644
--- a/tests/qunit/suites/resources/jquery/jquery.highlightText.test.js
+++ b/tests/qunit/suites/resources/jquery/jquery.highlightText.test.js
@@ -222,7 +222,7 @@
}
];
- $.each( cases, function ( i, item ) {
+ cases.forEach( function ( item ) {
$fixture = $( '<p>' ).text( item.text ).highlightText(
item.highlight );
assert.equal(
$fixture.html(),
diff --git
a/tests/qunit/suites/resources/jquery/jquery.tablesorter.parsers.test.js
b/tests/qunit/suites/resources/jquery/jquery.tablesorter.parsers.test.js
index 01589c3..2865cbb 100644
--- a/tests/qunit/suites/resources/jquery/jquery.tablesorter.parsers.test.js
+++ b/tests/qunit/suites/resources/jquery/jquery.tablesorter.parsers.test.js
@@ -62,7 +62,7 @@
}
parser = $.tablesorter.getParser( parserId );
- $.each( data, function ( index, testcase ) {
+ data.forEach( function ( testcase ) {
extractedR = parser.is( testcase[ 0 ] );
extractedF = parser.format( testcase[ 0 ] );
diff --git a/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js
b/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js
index 27d7e8d..1db8c61 100644
--- a/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js
+++ b/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js
@@ -238,7 +238,7 @@
$tbody = $table.find( 'tbody' ),
$tr = $( '<tr>' );
- $.each( header, function ( i, str ) {
+ header.forEach( function ( str ) {
var $th = $( '<th>' );
$th.text( str ).appendTo( $tr );
} );
@@ -247,7 +247,7 @@
for ( i = 0; i < data.length; i++ ) {
$tr = $( '<tr>' );
// eslint-disable-next-line no-loop-func
- $.each( data[ i ], function ( j, str ) {
+ data[ i ].forEach( function ( str ) {
var $td = $( '<td>' );
$td.text( str ).appendTo( $tr );
} );
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 6c2d51e..5a92da4 100644
--- a/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.test.js
+++ b/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.test.js
@@ -449,7 +449,7 @@
} );
this.api.abort();
assert.ok( this.requests.length === 2, 'Check both requests
triggered' );
- $.each( this.requests, function ( i, request ) {
+ this.requests.forEach( function ( request, i ) {
assert.ok( request.abort.calledOnce, 'abort request
number ' + i );
} );
} );
diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.RegExp.test.js
b/tests/qunit/suites/resources/mediawiki/mediawiki.RegExp.test.js
index 97c82fb..d980a1b 100644
--- a/tests/qunit/suites/resources/mediawiki/mediawiki.RegExp.test.js
+++ b/tests/qunit/suites/resources/mediawiki/mediawiki.RegExp.test.js
@@ -28,7 +28,7 @@
'0123456789'
].join( '' );
- $.each( specials, function ( i, str ) {
+ specials.forEach( function ( str ) {
assert.propEqual( str.match( new RegExp(
mw.RegExp.escape( str ) ) ), [ str ], 'Match ' + str );
} );
diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.Uri.test.js
b/tests/qunit/suites/resources/mediawiki/mediawiki.Uri.test.js
index e56c933..48bb98f 100644
--- a/tests/qunit/suites/resources/mediawiki/mediawiki.Uri.test.js
+++ b/tests/qunit/suites/resources/mediawiki/mediawiki.Uri.test.js
@@ -10,7 +10,7 @@
}
} ) );
- $.each( [ true, false ], function ( i, strictMode ) {
+ [ true, false ].forEach( function ( strictMode ) {
QUnit.test( 'Basic construction and properties (' + (
strictMode ? '' : 'non-' ) + 'strict mode)', function ( assert ) {
var uriString, uri;
uriString = 'http://www.ietf.org/rfc/rfc2396.txt';
diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js
b/tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js
index db51fb3..67ee3b8 100644
--- a/tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js
+++ b/tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js
@@ -898,7 +898,7 @@
var queue;
mw.messages.set( 'formatnum-msg', '{{formatnum:$1}}' );
mw.messages.set( 'formatnum-msg-int', '{{formatnum:$1|R}}' );
- queue = $.map( formatnumTests, function ( test ) {
+ queue = formatnumTests.map( function ( test ) {
var done = assert.async();
return function ( next, abort ) {
getMwLanguage( test.lang )
diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js
b/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js
index 1730575..6a15426 100644
--- a/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js
+++ b/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js
@@ -53,7 +53,7 @@
];
Array.prototype.push.apply( IPV6_CASES,
- $.map( [
+ [
'fc:100::',
'fc:100:a::',
'fc:100:a:d::',
@@ -69,7 +69,7 @@
'::fc:100:a:d:1:e',
'::fc:100:a:d:1:e:ac',
'fc:100:a:d:1:e:ac:0'
- ], function ( el ) {
+ ].map( function ( el ) {
return [ [ true, el, el + ' is a valid IP' ] ];
} )
);
@@ -132,7 +132,7 @@
newExperimental = [ 'html5', 'html5-legacy' ];
// Test cases are kept in sync with SanitizerTest.php
- $.each( [
+ [
// Pure legacy: how MW worked before 2017
[ legacy, text, legacyEncoded ],
// Transition to a new world: legacy links with HTML5
fallback
@@ -145,7 +145,7 @@
[ experimentalLegacy, text, html5Experimental ],
// Migration from $wgExperimentalHtmlIds to modern HTML5
[ newExperimental, text, html5Encoded ]
- ], function ( index, testCase ) {
+ ].forEach( function ( testCase ) {
mw.config.set( 'wgFragmentMode', testCase[ 0 ] );
assert.equal( util.escapeIdForAttribute( testCase[ 1 ]
), testCase[ 2 ] );
@@ -166,7 +166,7 @@
experimentalLegacy = [ 'html5-legacy', 'legacy' ],
newExperimental = [ 'html5', 'html5-legacy' ];
- $.each( [
+ [
// Pure legacy: how MW worked before 2017
[ legacy, text, legacyEncoded ],
// Transition to a new world: legacy links with HTML5
fallback
@@ -179,7 +179,7 @@
[ experimentalLegacy, text, html5Experimental ],
// Migration from wgExperimentalHtmlIds to modern HTML5
[ newExperimental, text, html5Encoded ]
- ], function ( index, testCase ) {
+ ].forEach( function ( testCase ) {
mw.config.set( 'wgFragmentMode', testCase[ 0 ] );
assert.equal( util.escapeIdForLink( testCase[ 1 ] ),
testCase[ 2 ] );
@@ -432,23 +432,23 @@
} );
QUnit.test( 'isIPv6Address', function ( assert ) {
- $.each( IPV6_CASES, function ( i, ipCase ) {
+ IPV6_CASES.forEach( function ( ipCase ) {
assert.strictEqual( util.isIPv6Address( ipCase[ 1 ] ),
ipCase[ 0 ], ipCase[ 2 ] );
} );
} );
QUnit.test( 'isIPv4Address', function ( assert ) {
- $.each( IPV4_CASES, function ( i, ipCase ) {
+ IPV4_CASES.forEach(, function ( ipCase ) {
assert.strictEqual( util.isIPv4Address( ipCase[ 1 ] ),
ipCase[ 0 ], ipCase[ 2 ] );
} );
} );
QUnit.test( 'isIPAddress', function ( assert ) {
- $.each( IPV4_CASES, function ( i, ipCase ) {
+ IPV4_CASES.forEach( function ( ipCase ) {
assert.strictEqual( util.isIPv4Address( ipCase[ 1 ] ),
ipCase[ 0 ], ipCase[ 2 ] );
} );
- $.each( IPV6_CASES, function ( i, ipCase ) {
+ IPV6_CASES.forEach( function ( ipCase ) {
assert.strictEqual( util.isIPv6Address( ipCase[ 1 ] ),
ipCase[ 0 ], ipCase[ 2 ] );
} );
} );
diff --git a/tests/qunit/suites/resources/startup.test.js
b/tests/qunit/suites/resources/startup.test.js
index ee1340d..b273f9d 100644
--- a/tests/qunit/suites/resources/startup.test.js
+++ b/tests/qunit/suites/resources/startup.test.js
@@ -146,13 +146,13 @@
QUnit.module( 'startup', QUnit.newMwEnvironment() );
QUnit.test( 'isCompatible( featureTestable )', function ( assert ) {
- $.each( testcases.tested, function ( i, ua ) {
+ testcases.tested.forEach( function ( ua ) {
assert.strictEqual( isCompatible( ua ), true, ua );
} );
} );
QUnit.test( 'isCompatible( blacklisted )', function ( assert ) {
- $.each( testcases.blacklisted, function ( i, ua ) {
+ testcases.blacklisted.forEach( function ( ua ) {
assert.strictEqual( isCompatible( ua ), false, ua );
} );
} );
--
To view, visit https://gerrit.wikimedia.org/r/403689
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8ef9af8c4d2f440faca65ec7c78a977ea7c31ad2
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Fomafix <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits