diff --git a/modules/ve-mw/dm/ve.dm.MWWikitextSurfaceFragment.js b/modules/ve-mw/dm/ve.dm.MWWikitextSurfaceFragment.js index e6f246b75a..791b8f5f66 100644 --- a/modules/ve-mw/dm/ve.dm.MWWikitextSurfaceFragment.js +++ b/modules/ve-mw/dm/ve.dm.MWWikitextSurfaceFragment.js @@ -173,7 +173,7 @@ ve.dm.MWWikitextSurfaceFragment.prototype.convertFromSource = function ( source /* ve.init.target.getSurface().createProgress( parsePromise, ve.msg( 'visualeditor-generating-wikitext-progress' ) - ).done( function ( progressBar, cancelPromise ) { + ).done( ( progressBar, cancelPromise ) => { cancelPromise.fail( () => { parsePromise.abort(); } ); diff --git a/modules/ve-mw/init/targets/ve.init.mw.ArticleTarget.js b/modules/ve-mw/init/targets/ve.init.mw.ArticleTarget.js index 9efbef6841..3a2c1e14ff 100644 --- a/modules/ve-mw/init/targets/ve.init.mw.ArticleTarget.js +++ b/modules/ve-mw/init/targets/ve.init.mw.ArticleTarget.js @@ -1075,9 +1075,9 @@ ve.init.mw.ArticleTarget.prototype.getVisualDiffGeneratorPromise = function () { return mw.libs.ve.diffLoader.getVisualDiffGeneratorPromise( target.originalDmDocPromise, newRevPromise ); } else { - return target.originalDmDocPromise.then( ( originalDmDoc ) => function () { - return new ve.dm.VisualDiff( originalDmDoc, target.getSurface().getModel().getAttachedRoot() ); - } ); + return target.originalDmDocPromise.then( + ( originalDmDoc ) => ve.dm.VisualDiff( originalDmDoc, target.getSurface().getModel().getAttachedRoot() ) + ); } } ); }; @@ -1289,7 +1289,7 @@ ve.init.mw.ArticleTarget.prototype.prepareCacheKey = function ( doc ) { ); } ) .promise( { - abort: function () { + abort: () => { if ( xhr ) { xhr.abort(); } @@ -1705,7 +1705,7 @@ ve.init.mw.ArticleTarget.prototype.submit = function ( wikitext, fields ) { * * This method performs an asynchronous action and uses a callback function to handle the result. * - * target.serialize( doc ).then( function ( data ) { + * target.serialize( doc ).then( ( data ) => { * // Do something with data.content (wikitext) * } ); * diff --git a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js index f6bbcf1d2d..eb326991a0 100644 --- a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js +++ b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js @@ -879,10 +879,10 @@ ve.init.mw.DesktopArticleTarget.prototype.saveComplete = function ( data ) { if ( !data.nocontent ) { // Fix permalinks if ( data.newrevid !== undefined ) { - $( '#t-permalink' ).add( '#coll-download-as-rl' ).find( 'a' ).each( function () { - var permalinkUrl = new URL( this.href ); + $( '#t-permalink' ).add( '#coll-download-as-rl' ).find( 'a' ).each( ( i, el ) => { + var permalinkUrl = new URL( el.href ); permalinkUrl.searchParams.set( 'oldid', data.newrevid ); - $( this ).attr( 'href', permalinkUrl.toString() ); + $( el ).attr( 'href', permalinkUrl.toString() ); } ); } diff --git a/modules/ve-mw/preinit/ve.init.mw.ArticleTargetSaver.js b/modules/ve-mw/preinit/ve.init.mw.ArticleTargetSaver.js index 4d35e934a7..66118c9503 100644 --- a/modules/ve-mw/preinit/ve.init.mw.ArticleTargetSaver.js +++ b/modules/ve-mw/preinit/ve.init.mw.ArticleTargetSaver.js @@ -84,17 +84,17 @@ 'div.donut-container', // Web of Trust (T189148) 'div.shield-container' // Web of Trust (T297862) ].join( ',' ) ) - .each( function () { + .each( ( j, el ) => { function truncate( text, l ) { return text.length > l ? text.slice( 0, l ) + '…' : text; } - var errorMessage = 'DOM content matching deny list found:\n' + truncate( this.outerHTML, 100 ) + - '\nContext:\n' + truncate( this.parentNode.outerHTML, 200 ); + var errorMessage = 'DOM content matching deny list found:\n' + truncate( el.outerHTML, 100 ) + + '\nContext:\n' + truncate( el.parentNode.outerHTML, 200 ); mw.log.error( errorMessage ); var err = new Error( errorMessage ); err.name = 'VeDomDenyListWarning'; mw.errorLogger.logError( err, 'error.visualeditor' ); - $( this ).remove(); + $( el ).remove(); } ); // data-mw-section-id is copied to headings by mw.libs.ve.unwrapParsoidSections diff --git a/modules/ve-mw/preinit/ve.init.mw.DesktopArticleTarget.init.js b/modules/ve-mw/preinit/ve.init.mw.DesktopArticleTarget.init.js index a33dec29cd..d38bda5517 100644 --- a/modules/ve-mw/preinit/ve.init.mw.DesktopArticleTarget.init.js +++ b/modules/ve-mw/preinit/ve.init.mw.DesktopArticleTarget.init.js @@ -505,10 +505,10 @@ } var $heading; - $( '#mw-content-text .mw-editsection a:not( .mw-editsection-visualeditor )' ).each( function () { - var linkUrl = new URL( this.href ); + $( '#mw-content-text .mw-editsection a:not( .mw-editsection-visualeditor )' ).each( ( i, el ) => { + var linkUrl = new URL( el.href ); if ( section === parseSection( linkUrl.searchParams.get( 'section' ) ) ) { - $heading = $( this ).closest( '.mw-heading, h1, h2, h3, h4, h5, h6' ); + $heading = $( el ).closest( '.mw-heading, h1, h2, h3, h4, h5, h6' ); return false; } } ); @@ -617,10 +617,10 @@ var visibleSectionOffset = null; if ( section === null ) { var firstVisibleEditSection = null; - $( '#firstHeading, #mw-content-text .mw-editsection' ).each( function () { - var top = this.getBoundingClientRect().top; + $( '#firstHeading, #mw-content-text .mw-editsection' ).each( ( i, el ) => { + var top = el.getBoundingClientRect().top; if ( top > 0 ) { - firstVisibleEditSection = this; + firstVisibleEditSection = el; // break return false; } @@ -900,14 +900,12 @@ * mw.libs.ve.addPlugin( 'ext.gadget.foobar' ); * * // Register a callback - * mw.libs.ve.addPlugin( function ( target ) { + * mw.libs.ve.addPlugin( ( target ) => { * ve.dm.Foobar = ..... * } ); * * // Register a callback that loads another script - * mw.libs.ve.addPlugin( function () { - * return $.getScript( 'http://example.com/foobar.js' ); - * } ); + * mw.libs.ve.addPlugin( () => $.getScript( 'http://example.com/foobar.js' ) ); * * @param {string|Function} plugin Module name or callback that optionally returns a promise */ @@ -933,17 +931,17 @@ '#ca-edit a,' + // Add section is currently a wikitext-only feature '#ca-addsection a' - ).each( function () { - if ( !this.href ) { + ).each( ( i, el ) => { + if ( !el.href ) { // Not a real link, probably added by a gadget or another extension (T328094) return; } - var linkUrl = new URL( this.href ); + var linkUrl = new URL( el.href ); if ( linkUrl.searchParams.has( 'action' ) ) { linkUrl.searchParams.delete( 'action' ); linkUrl.searchParams.set( 'veaction', 'editsource' ); - $( this ).attr( 'href', linkUrl.toString() ); + $( el ).attr( 'href', linkUrl.toString() ); } } ); } diff --git a/modules/ve-mw/preinit/ve.init.mw.DiffLoader.js b/modules/ve-mw/preinit/ve.init.mw.DiffLoader.js index b7083ee471..7a46c68f4f 100644 --- a/modules/ve-mw/preinit/ve.init.mw.DiffLoader.js +++ b/modules/ve-mw/preinit/ve.init.mw.DiffLoader.js @@ -62,12 +62,15 @@ false, // noMetadata, we only use `content` in getModelFromResponse true - ).then( ( response ) => parseDocumentModulePromise.then( () => mw.libs.ve.diffLoader.getModelFromResponse( response, section ) ), function () { + ).then( + ( response ) => parseDocumentModulePromise.then( () => mw.libs.ve.diffLoader.getModelFromResponse( response, section ) ), + () => { // Clear promise. Do not cache errors. - delete revCache[ cacheKey ]; - // Let caller handle the error code - return $.Deferred().rejectWith( this, arguments ); - } ); + delete revCache[ cacheKey ]; + // Let caller handle the error code + return $.Deferred().rejectWith( this, arguments ); + } + ); return revCache[ cacheKey ]; }, @@ -93,9 +96,7 @@ // TODO: Differ expects newDoc to be derived from oldDoc and contain all its store data. // We may want to remove that assumption from the differ? newDoc.getStore().merge( oldDoc.getStore() ); - return function () { - return new ve.dm.VisualDiff( oldDoc, newDoc ); - }; + return () => new ve.dm.VisualDiff( oldDoc, newDoc ); } ); } diff --git a/modules/ve-mw/tests/dm/annotations/ve.dm.MWInternalLinkAnnotation.test.js b/modules/ve-mw/tests/dm/annotations/ve.dm.MWInternalLinkAnnotation.test.js index f4f9f2bfef..b4fc7a61b9 100644 --- a/modules/ve-mw/tests/dm/annotations/ve.dm.MWInternalLinkAnnotation.test.js +++ b/modules/ve-mw/tests/dm/annotations/ve.dm.MWInternalLinkAnnotation.test.js @@ -181,7 +181,7 @@ QUnit.test( 'toDataElement', ( assert ) => { } ]; - articlePaths.forEach( function ( pathData ) { + articlePaths.forEach( ( pathData ) => { // Set up global state (site configuration) mw.config.set( pathData.config ); @@ -196,14 +196,13 @@ QUnit.test( 'toDataElement', ( assert ) => { converter.fromClipboard = true; // Generate test cases for this site configuration - const cases = getCases(); - for ( let i = 0; i < cases.length; i++ ) { + getCases().forEach( ( caseItem ) => { assert.deepEqual( - ve.dm.MWInternalLinkAnnotation.static.toDataElement( [ cases[ i ].element ], converter ), - cases[ i ].expected, - cases[ i ].msg + ': ' + pathData.msg + ve.dm.MWInternalLinkAnnotation.static.toDataElement( [ caseItem.element ], converter ), + caseItem.expected, + caseItem.msg + ': ' + pathData.msg ); - } + } ); } ); } ); diff --git a/modules/ve-mw/tests/dm/models/ve.dm.MWTemplateSpecModel.test.js b/modules/ve-mw/tests/dm/models/ve.dm.MWTemplateSpecModel.test.js index e403dc0ca2..aede08f4fb 100644 --- a/modules/ve-mw/tests/dm/models/ve.dm.MWTemplateSpecModel.test.js +++ b/modules/ve-mw/tests/dm/models/ve.dm.MWTemplateSpecModel.test.js @@ -12,8 +12,10 @@ } ); return { params, - getTemplateDataQueryTitle: () => null, - getTarget: () => { + getTemplateDataQueryTitle: function () { + return null; + }, + getTarget: function () { return { wt: 'RawTemplateName' }; }, getParameters: function () { diff --git a/modules/ve-mw/ui/widgets/ve.ui.MWExternalLinkAnnotationWidget.js b/modules/ve-mw/ui/widgets/ve.ui.MWExternalLinkAnnotationWidget.js index ab76948e87..e423f52815 100644 --- a/modules/ve-mw/ui/widgets/ve.ui.MWExternalLinkAnnotationWidget.js +++ b/modules/ve-mw/ui/widgets/ve.ui.MWExternalLinkAnnotationWidget.js @@ -54,9 +54,7 @@ ve.ui.MWExternalLinkAnnotationWidget.static.createExternalLinkInputWidget = func var inputWidget = new OO.ui.TextInputWidget( ve.extendObject( {}, config, { icon: 'linkExternal', type: 'url', - validate: function ( text ) { - return !!ve.init.platform.getExternalLinkUrlProtocolsRegExp().exec( text.trim() ); - } + validate: ( text ) => !!ve.init.platform.getExternalLinkUrlProtocolsRegExp().exec( text.trim() ) } ) ); inputWidget.$input.attr( 'aria-label', mw.msg( 'visualeditor-linkinspector-button-link-external' ) );