From 3f0aae5e73125647a4a7d314b5cd274f17ec5753 Mon Sep 17 00:00:00 2001 From: thiemowmde Date: Tue, 24 Oct 2023 16:08:50 +0200 Subject: [PATCH] Cleanup minor code duplication/complication in various places Change-Id: Icffe9551d633470ccec1b63ea570e138db48dee8 --- modules/ext.RevisionSlider.PointerLine.js | 12 +++++++----- modules/ext.RevisionSlider.Revision.js | 2 +- modules/ext.RevisionSlider.RevisionList.js | 6 ++---- modules/ext.RevisionSlider.init.js | 9 +-------- 4 files changed, 11 insertions(+), 18 deletions(-) diff --git a/modules/ext.RevisionSlider.PointerLine.js b/modules/ext.RevisionSlider.PointerLine.js index 4a91ae08..97d58a3d 100644 --- a/modules/ext.RevisionSlider.PointerLine.js +++ b/modules/ext.RevisionSlider.PointerLine.js @@ -154,18 +154,20 @@ $.extend( PointerLine.prototype, { /** * Adds colored top-borders for the diff columns fitting the line colors between pointers and columns + * + * @param {boolean} [show=true] */ - addColoredColumnBorders: function () { - $( '#mw-diff-otitle1' ).addClass( 'mw-revslider-older-diff-column' ); - $( '#mw-diff-ntitle1' ).addClass( 'mw-revslider-newer-diff-column' ); + addColoredColumnBorders: function ( show ) { + show = show !== false; + $( '#mw-diff-otitle1' ).toggleClass( 'mw-revslider-older-diff-column', show ); + $( '#mw-diff-ntitle1' ).toggleClass( 'mw-revslider-newer-diff-column', show ); }, /** * Remove colored top-borders for the diff columns fitting the line colors between pointers and columns */ removeColoredColumnBorders: function () { - $( '#mw-diff-otitle1' ).removeClass( 'mw-revslider-older-diff-column' ); - $( '#mw-diff-ntitle1' ).removeClass( 'mw-revslider-newer-diff-column' ); + this.addColoredColumnBorders( false ); }, /** diff --git a/modules/ext.RevisionSlider.Revision.js b/modules/ext.RevisionSlider.Revision.js index 773e7388..414c196d 100644 --- a/modules/ext.RevisionSlider.Revision.js +++ b/modules/ext.RevisionSlider.Revision.js @@ -61,7 +61,7 @@ $.extend( Revision.prototype, { userGender: '', /** - * @type {number} + * @type {number} Warning, only set for Revision objects that are part of a RevisionList */ relativeSize: 0, diff --git a/modules/ext.RevisionSlider.RevisionList.js b/modules/ext.RevisionSlider.RevisionList.js index 1ad124e3..50c354cd 100644 --- a/modules/ext.RevisionSlider.RevisionList.js +++ b/modules/ext.RevisionSlider.RevisionList.js @@ -147,13 +147,11 @@ $.extend( RevisionList.prototype, { * Transforms an array of revision data returned by MediaWiki API (including user gender information) into * an array of Revision objects * - * @param {Array} revs + * @param {Object[]} revs * @return {Revision[]} */ function makeRevisions( revs ) { - return revs.map( function ( revData ) { - return new Revision( revData ); - } ); + return revs.map( ( data ) => new Revision( data ) ); } module.exports = { diff --git a/modules/ext.RevisionSlider.init.js b/modules/ext.RevisionSlider.init.js index c136363f..487db260 100644 --- a/modules/ext.RevisionSlider.init.js +++ b/modules/ext.RevisionSlider.init.js @@ -12,7 +12,6 @@ let expanded = autoExpand; function initialize() { const startTime = mw.now(); const api = new RevisionSliderApi( mw.util.wikiScript( 'api' ) ); - let changeTags = []; toggleButton.$element.children().attr( { 'aria-expanded': autoExpand, @@ -29,13 +28,7 @@ function initialize() { HelpDialog.init(); api.fetchAvailableChangeTags().then( function ( data ) { - if ( typeof data === 'object' && - data.query && - data.query.tags && - data.query.tags.length > 0 - ) { - changeTags = data.query.tags; - } + const changeTags = data && data.query && data.query.tags || []; api.fetchRevisionData( mw.config.get( 'wgPageName' ), { startId: Math.max( mw.config.get( 'wgDiffOldId' ), mw.config.get( 'wgDiffNewId' ) ), limit: utils.calculateRevisionsPerWindow( 160, 16 ),