From d85496a2a829126c90a03306349db3d36d1b2e7f Mon Sep 17 00:00:00 2001 From: thiemowmde Date: Sat, 30 Sep 2023 11:52:20 +0200 Subject: [PATCH] Drop custom forEach loop in favor of native Array.find() Plus a few minor code cleanups in the RevisionListView class. Change-Id: I828eb92936e3a36a3794b38eac80ba50399ffaef --- .../ext.RevisionSlider.RevisionListView.js | 28 ++++++------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/modules/ext.RevisionSlider.RevisionListView.js b/modules/ext.RevisionSlider.RevisionListView.js index f0c243bd..afc1d3b1 100644 --- a/modules/ext.RevisionSlider.RevisionListView.js +++ b/modules/ext.RevisionSlider.RevisionListView.js @@ -254,10 +254,12 @@ $.extend( RevisionListView.prototype, { * @param {jQuery} $revisionWrapper */ showTooltip: function ( $revisionWrapper ) { - const pos = +$revisionWrapper.find( '.mw-revslider-revision' ).attr( 'data-pos' ), - revId = +$revisionWrapper.find( '.mw-revslider-revision' ).attr( 'data-revid' ), - revision = this.getRevisionWithId( revId ); - if ( revision === null ) { + const $revision = $revisionWrapper.find( '.mw-revslider-revision' ); + const revId = +$revision.attr( 'data-revid' ); + const pos = +$revision.attr( 'data-pos' ); + + const revision = this.revisionList.getRevisions().find( ( rev ) => rev.getId() === revId ); + if ( !revision ) { return; } @@ -287,20 +289,6 @@ $.extend( RevisionListView.prototype, { $revisionWrapper.addClass( 'mw-revslider-revision-wrapper-hovered' ); }, - /** - * @param {number} revId - * @return {Revision|null} - */ - getRevisionWithId: function ( revId ) { - let matchedRevision = null; - this.revisionList.revisions.forEach( function ( revision ) { - if ( revision.getId() === revId ) { - matchedRevision = revision; - } - } ); - return matchedRevision; - }, - /** * Sets event handlers on tooltips so they do not disappear when hovering over them */ @@ -368,14 +356,14 @@ $.extend( RevisionListView.prototype, { * @return {string} */ getUserPage: function ( user ) { - return ( mw.util.isIPAddress( user, false ) ? 'Special:Contributions/' : 'User:' ) + this.stripInvalidCharacters( user ); + return ( mw.util.isIPAddress( user ) ? 'Special:Contributions/' : 'User:' ) + this.stripInvalidCharacters( user ); }, /** * Generates the HTML for the user label * * @param {string} userString - * @param {string} userGender + * @param {string} [userGender='unknown'] * @return {string|jQuery} */ makeUserLine: function ( userString, userGender ) {