diff --git a/modules/.eslintrc.json b/modules/.eslintrc.json
index 2f3b62c4..07eed576 100644
--- a/modules/.eslintrc.json
+++ b/modules/.eslintrc.json
@@ -11,6 +11,6 @@
"rules": {
"max-len": "off",
"no-jquery/no-global-selector": "off",
- "no-var": "off"
+ "prefer-const": "warn"
}
}
diff --git a/modules/ext.wikiEditor.js b/modules/ext.wikiEditor.js
index 2cc0f74a..2333b7f4 100644
--- a/modules/ext.wikiEditor.js
+++ b/modules/ext.wikiEditor.js
@@ -6,7 +6,7 @@
* @module module:ext.wikiEditor
*/
-var editingSessionId;
+let editingSessionId;
// This sets $.wikiEditor and $.fn.wikiEditor
require( './jquery.wikiEditor.js' );
@@ -48,7 +48,7 @@ function logAbort( switchingToVE, unmodified ) {
logEditFeature( 'editor-switch', 'visual-desktop' );
}
- var abortType;
+ let abortType;
if ( switchingToVE && unmodified ) {
abortType = 'switchnochange';
} else if ( switchingToVE ) {
@@ -66,7 +66,7 @@ function logAbort( switchingToVE, unmodified ) {
}
$( () => {
- var $textarea = $( '#wpTextbox1' ),
+ const $textarea = $( '#wpTextbox1' ),
$editingSessionIdInput = $( '#editingStatsId' ),
origText = $textarea.val();
@@ -82,7 +82,7 @@ $( () => {
// fall back to the timestamp when the page loaded for those
// that don't, we just ignore them, so as to not skew the
// results towards better-performance in those cases.
- var readyTime = Date.now();
+ const readyTime = Date.now();
logEditEvent( {
action: 'ready',
timing: readyTime - window.performance.timing.navigationStart
@@ -99,28 +99,28 @@ $( () => {
} );
} );
}
- var $form = $textarea.closest( 'form' );
+ const $form = $textarea.closest( 'form' );
if ( mw.user.options.get( 'uselivepreview' ) ) {
$form.find( '#wpPreview' ).on( 'click', () => {
logEditFeature( 'preview', 'preview-live' );
} );
}
- var submitting;
+ let submitting;
$form.on( 'submit', () => {
submitting = true;
} );
- var onUnloadFallback = window.onunload;
+ const onUnloadFallback = window.onunload;
window.onunload = function () {
- var unmodified = mw.config.get( 'wgAction' ) !== 'submit' && origText === $textarea.val(),
+ const unmodified = mw.config.get( 'wgAction' ) !== 'submit' && origText === $textarea.val(),
caVeEdit = $( '#ca-ve-edit' )[ 0 ],
switchingToVE = caVeEdit && (
document.activeElement === caVeEdit ||
$.contains( caVeEdit, document.activeElement )
);
- var fallbackResult;
+ let fallbackResult;
if ( onUnloadFallback ) {
fallbackResult = onUnloadFallback();
}
@@ -141,7 +141,7 @@ $( () => {
return fallbackResult;
};
$textarea.on( 'wikiEditor-switching-visualeditor', () => {
- var unmodified = mw.config.get( 'wgAction' ) !== 'submit' && origText === $textarea.val();
+ const unmodified = mw.config.get( 'wgAction' ) !== 'submit' && origText === $textarea.val();
// A non-navigation switch to VE has occurred. As such, avoid eventually
// double-logging an abort when VE is done.
window.onunload = onUnloadFallback;
@@ -192,7 +192,7 @@ mw.addWikiEditor = function ( $textarea ) {
'addModule', require( './jquery.wikiEditor.toolbar.config.js' )
);
- var dialogsConfig = require( './jquery.wikiEditor.dialogs.config.js' );
+ const dialogsConfig = require( './jquery.wikiEditor.dialogs.config.js' );
// Replace icons
dialogsConfig.replaceIcons( $textarea );
// Add dialogs module
diff --git a/modules/insertlink/LinkTextField.js b/modules/insertlink/LinkTextField.js
index b1e80724..a0961101 100644
--- a/modules/insertlink/LinkTextField.js
+++ b/modules/insertlink/LinkTextField.js
@@ -4,7 +4,7 @@
* @constructor
*/
function LinkTextField() {
- var input = new OO.ui.TextInputWidget( {
+ const input = new OO.ui.TextInputWidget( {
placeholder: mw.msg( 'wikieditor-toolbar-tool-link-int-text-tooltip' )
} );
@@ -12,7 +12,7 @@ function LinkTextField() {
change: 'onInputChange'
} );
- var config = {
+ const config = {
align: 'top',
label: mw.msg( 'wikieditor-toolbar-tool-link-int-text' ),
classes: [ 'mw-wikiEditor-InsertLink-LinkTextField' ]
diff --git a/modules/insertlink/LinkTypeField.js b/modules/insertlink/LinkTypeField.js
index 849dc917..9f3b0a4b 100644
--- a/modules/insertlink/LinkTypeField.js
+++ b/modules/insertlink/LinkTypeField.js
@@ -14,7 +14,7 @@ function LinkTypeField() {
this.radioExt = new OO.ui.RadioOptionWidget( {
label: mw.msg( 'wikieditor-toolbar-tool-link-ext' )
} );
- var radioSelect = new OO.ui.RadioSelectWidget( {
+ const radioSelect = new OO.ui.RadioSelectWidget( {
items: [
this.radioInt,
this.radioExt
@@ -24,7 +24,7 @@ function LinkTypeField() {
choose: this.onRadioChoose
} );
- var config = {
+ const config = {
align: 'top',
classes: [ 'mw-wikiEditor-InsertLink-LinkTypeField' ]
};
diff --git a/modules/insertlink/TitleInputField.js b/modules/insertlink/TitleInputField.js
index 01be88a5..21c0ddd2 100644
--- a/modules/insertlink/TitleInputField.js
+++ b/modules/insertlink/TitleInputField.js
@@ -1,5 +1,5 @@
-var LinkTypeField = require( './LinkTypeField.js' );
-var TitleInputWidget = require( './TitleInputWidget.js' );
+const LinkTypeField = require( './LinkTypeField.js' );
+const TitleInputWidget = require( './TitleInputWidget.js' );
/* global InsertLinkTitleOptionWidget */
/**
@@ -14,7 +14,7 @@ function TitleInputField() {
// Mixin constructor
OO.EventEmitter.call( this );
- var input = new TitleInputWidget();
+ const input = new TitleInputWidget();
input.connect( this, {
change: this.onChange,
select: this.onSelect
@@ -25,7 +25,7 @@ function TitleInputField() {
// The 'manual' URL mode flag is set when the user changes the mode, and doesn't change again.
this.urlModeManual = false;
- var config = {
+ const config = {
align: 'top',
label: mw.msg( 'wikieditor-toolbar-tool-link-int-target' ),
classes: [ 'mw-wikiEditor-InsertLink-TitleInputField' ]
@@ -131,7 +131,7 @@ TitleInputField.prototype.validate = function ( value ) {
* @param {InsertLinkTitleOptionWidget} item
*/
TitleInputField.prototype.onSelect = function ( item ) {
- var icon, msg;
+ let icon, msg;
if ( this.urlMode === LinkTypeField.static.LINK_MODE_EXTERNAL ||
( !this.urlModeManual && this.urlMode === LinkTypeField.static.LINK_MODE_INTERNAL && item.isExternal() )
) {
diff --git a/modules/insertlink/TitleInputWidget.js b/modules/insertlink/TitleInputWidget.js
index 3e6fb531..0ef43612 100644
--- a/modules/insertlink/TitleInputWidget.js
+++ b/modules/insertlink/TitleInputWidget.js
@@ -1,4 +1,4 @@
-var InsertLinkTitleOptionWidget = require( './TitleOptionWidget.js' );
+const InsertLinkTitleOptionWidget = require( './TitleOptionWidget.js' );
/**
* A custom TitleInputWidget that adds support for external links
@@ -50,13 +50,13 @@ TitleInputWidget.prototype.onLookupInputBlur = function () {
* @public
*/
TitleInputWidget.prototype.selectFirstMatch = function () {
- var that = this;
+ const that = this;
this.getLookupMenuItems().done( ( items ) => {
// The matching item is not always the first,
// because disambiguation pages are moved to the end.
- for ( var i = 0; i < items.length; i++ ) {
- var item = items[ i ];
- var queryVal = that.getQueryValue();
+ for ( let i = 0; i < items.length; i++ ) {
+ const item = items[ i ];
+ const queryVal = that.getQueryValue();
// Check for exact match, or a match with uppercase first character.
if ( item.getData() === queryVal ||
item.getData() === queryVal.charAt( 0 ).toUpperCase() + queryVal.slice( 1 )
@@ -78,7 +78,7 @@ TitleInputWidget.prototype.selectFirstMatch = function () {
* @return {Object} Data for option widget
*/
TitleInputWidget.prototype.getOptionWidgetData = function ( title, data ) {
- var widgetData = TitleInputWidget.super.prototype.getOptionWidgetData.call( this, title, data );
+ const widgetData = TitleInputWidget.super.prototype.getOptionWidgetData.call( this, title, data );
widgetData.external = data.originalData.external;
return widgetData;
};
@@ -101,14 +101,14 @@ TitleInputWidget.prototype.createOptionWidget = function ( data ) {
* @return {Object}
*/
TitleInputWidget.prototype.getLookupCacheDataFromResponse = function ( response ) {
- var res = TitleInputWidget.super.prototype.getLookupCacheDataFromResponse( response );
+ const res = TitleInputWidget.super.prototype.getLookupCacheDataFromResponse( response );
// Guard against zero responses.
if ( res.pages === undefined ) {
return res;
}
- for ( var pageId in res.pages ) {
+ for ( const pageId in res.pages ) {
if ( Object.prototype.hasOwnProperty.call( res.pages, pageId ) ) {
- var page = res.pages[ pageId ];
+ const page = res.pages[ pageId ];
page.external = page.missing !== undefined && this.looksLikeExternalLink( page.title );
}
}
diff --git a/modules/jquery.wikiEditor.dialogs.config.js b/modules/jquery.wikiEditor.dialogs.config.js
index 64edab6d..57145bca 100644
--- a/modules/jquery.wikiEditor.dialogs.config.js
+++ b/modules/jquery.wikiEditor.dialogs.config.js
@@ -3,7 +3,7 @@
*
* @private
*/
-var toolbarModule = require( './jquery.wikiEditor.toolbar.js' ),
+const toolbarModule = require( './jquery.wikiEditor.toolbar.js' ),
InsertLinkTitleInputField = require( './insertlink/TitleInputField.js' ),
LinkTextField = require( './insertlink/LinkTextField.js' ),
LinkTypeField = require( './insertlink/LinkTypeField.js' ),
@@ -14,8 +14,8 @@ var toolbarModule = require( './jquery.wikiEditor.toolbar.js' ),
function triggerButtonClick( element ) {
// The dialog action should always be a DOMElement.
- var dialogAction = $( element ).data( 'dialogaction' );
- var $button = dialogAction ? $( dialogAction ) : $( element ).find( 'button' ).first();
+ const dialogAction = $( element ).data( 'dialogaction' );
+ const $button = dialogAction ? $( dialogAction ) : $( element ).find( 'button' ).first();
// Since we're reading from data attribute, make sure we got an element before clicking.
// Note when closing a dialog this can be false leading to TypeError: $button.trigger is not a function
// (T261529)
@@ -114,7 +114,7 @@ module.exports = {
*
* @param {boolean} enable Whether to enable or disable the button
*/
- var setButtonState = function ( enable ) {
+ const setButtonState = function ( enable ) {
$( '.wikieditor-toolbar-tool-link-insert' ).button( 'option', 'disabled', !enable );
};
// Automatically copy the value of the internal link page title field to the link text field unless the
@@ -133,7 +133,7 @@ module.exports = {
// Tell the title input field when the internal/external radio changes.
insertLinkLinkTypeField.connect( this, {
change: function ( isExternal ) {
- var urlMode = isExternal ?
+ const urlMode = isExternal ?
LinkTypeField.static.LINK_MODE_EXTERNAL :
LinkTypeField.static.LINK_MODE_INTERNAL;
insertLinkTitleInputField.setUrlMode( urlMode );
@@ -148,7 +148,7 @@ module.exports = {
class: 'wikieditor-toolbar-tool-link-insert',
text: mw.msg( 'wikieditor-toolbar-tool-link-insert' ),
click: function () {
- var that = this;
+ const that = this;
function escapeInternalText( s ) {
return s.replace( /(\]{2,})/g, '$1' );
@@ -167,14 +167,14 @@ module.exports = {
return;
}
- var target = insertLinkTitleInputField.getField().getValue();
- var text = insertLinkLinkTextField.getField().getValue();
+ let target = insertLinkTitleInputField.getField().getValue();
+ let text = insertLinkLinkTextField.getField().getValue();
if ( text.trim() === '' ) {
// [[Foo| ]] creates an invisible link
// Instead, generate [[Foo|]]
text = '';
}
- var insertText = '';
+ let insertText = '';
if ( insertLinkLinkTypeField.isInternal() ) {
if ( target === text || !text.length ) {
insertText = '[[' + target + ']]';
@@ -189,12 +189,12 @@ module.exports = {
}
// Detect if this is really an internal link in disguise
- var match = target.match( $( this ).data( 'articlePathRegex' ) );
+ const match = target.match( $( this ).data( 'articlePathRegex' ) );
if ( match && !$( this ).data( 'ignoreLooksInternal' ) ) {
- var buttons = {};
+ const buttons = {};
buttons[ mw.msg( 'wikieditor-toolbar-tool-link-lookslikeinternal-int' ) ] =
function () {
- var titleValue = match[ 1 ];
+ let titleValue = match[ 1 ];
try {
titleValue = decodeURI( titleValue );
} catch ( ex ) {
@@ -221,8 +221,8 @@ module.exports = {
return;
}
- var escTarget = escapeExternalTarget( target );
- var escText = escapeExternalText( text );
+ const escTarget = escapeExternalTarget( target );
+ const escText = escapeExternalText( text );
if ( escTarget === escText ) {
insertText = escTarget;
@@ -233,7 +233,7 @@ module.exports = {
}
}
- var whitespace = $( '#wikieditor-toolbar-link-dialog' ).data( 'whitespace' );
+ const whitespace = $( '#wikieditor-toolbar-link-dialog' ).data( 'whitespace' );
// Preserve whitespace in selection when replacing
if ( whitespace ) {
insertText = whitespace[ 0 ] + insertText + whitespace[ 1 ];
@@ -259,7 +259,7 @@ module.exports = {
open: function () {
// Obtain the server name without the protocol. wgServer may be protocol-relative
- var serverName = mw.config.get( 'wgServer' ).replace( /^(https?:)?\/\//, '' );
+ const serverName = mw.config.get( 'wgServer' ).replace( /^(https?:)?\/\//, '' );
// Cache the articlepath regex
$( this ).data( 'articlePathRegex', new RegExp(
@@ -267,8 +267,8 @@ module.exports = {
.replace( /\\\$1/g, '(.*)' ) + '$'
) );
// Pre-fill the text fields based on the current selection
- var context = $( this ).data( 'context' );
- var selection = context.$textarea.textSelection( 'getSelection' );
+ const context = $( this ).data( 'context' );
+ const selection = context.$textarea.textSelection( 'getSelection' );
insertLinkTitleInputField.getField().focus();
// Trigger the change event, so the link status indicator is up to date.
@@ -277,7 +277,7 @@ module.exports = {
$( '#wikieditor-toolbar-link-dialog' ).data( 'whitespace', [ '', '' ] );
if ( selection !== '' ) {
- var matches, target, text, isExternal;
+ let matches, target, text, isExternal;
if ( ( matches = selection.match( /^(\s*)\[\[([^\]|]+)(\|([^\]|]*))?\]\](\s*)$/ ) ) ) {
// [[foo|bar]] or [[foo]]
target = matches[ 2 ];
@@ -315,7 +315,7 @@ module.exports = {
insertLinkLinkTextField.setTouched( true );
if ( typeof isExternal !== 'undefined' ) {
- var urlMode = isExternal ?
+ const urlMode = isExternal ?
LinkTypeField.static.LINK_MODE_EXTERNAL :
LinkTypeField.static.LINK_MODE_INTERNAL;
insertLinkTitleInputField.setUrlMode( urlMode );
@@ -347,7 +347,7 @@ module.exports = {
id: 'wikieditor-toolbar-file-dialog',
htmlTemplate: 'dialogInsertFile.html',
init: function () {
- var magicWordsI18N = configData.magicWords;
+ const magicWordsI18N = configData.magicWords;
$( this ).find( '[data-i18n-magic]' )
.text( function () {
@@ -355,7 +355,7 @@ module.exports = {
} )
.removeAttr( 'data-i18n-magic' );
- var defaultMsg = mw.msg( 'wikieditor-toolbar-file-default' );
+ const defaultMsg = mw.msg( 'wikieditor-toolbar-file-default' );
$( this ).find( '#wikieditor-toolbar-file-size' )
.attr( 'placeholder', defaultMsg )
// The message may be long in some languages
@@ -367,8 +367,8 @@ module.exports = {
} )
.removeAttr( 'rel' );
- var altHelpText = mw.msg( 'wikieditor-toolbar-file-alt-help' );
- var altHelpLabel = mw.msg( 'wikieditor-toolbar-file-alt-help-label' );
+ const altHelpText = mw.msg( 'wikieditor-toolbar-file-alt-help' );
+ const altHelpLabel = mw.msg( 'wikieditor-toolbar-file-alt-help-label' );
// Expandable help message for 'alt text' field
$( this ).find( '.wikieditor-toolbar-file-alt-help' ).text( altHelpLabel );
$( '.wikieditor-toolbar-file-alt-help' ).on( 'click', function () {
@@ -388,21 +388,21 @@ module.exports = {
width: 590,
buttons: {
'wikieditor-toolbar-tool-file-insert': function () {
- var hasPxRgx = /.+px$/,
+ const hasPxRgx = /.+px$/,
magicWordsI18N = configData.magicWords;
- var fileName = $( '#wikieditor-toolbar-file-target' ).val();
- var caption = $( '#wikieditor-toolbar-file-caption' ).val();
- var fileAlt = $( '#wikieditor-toolbar-file-alt' ).val();
- var fileFloat = $( '#wikieditor-toolbar-file-float' ).val();
- var fileFormat = $( '#wikieditor-toolbar-file-format' ).val();
- var fileSize = $( '#wikieditor-toolbar-file-size' ).val();
- var whitespace = $( '#wikieditor-toolbar-file-dialog' ).data( 'whitespace' );
+ let fileName = $( '#wikieditor-toolbar-file-target' ).val();
+ const caption = $( '#wikieditor-toolbar-file-caption' ).val();
+ const fileAlt = $( '#wikieditor-toolbar-file-alt' ).val();
+ const fileFloat = $( '#wikieditor-toolbar-file-float' ).val();
+ const fileFormat = $( '#wikieditor-toolbar-file-format' ).val();
+ let fileSize = $( '#wikieditor-toolbar-file-size' ).val();
+ const whitespace = $( '#wikieditor-toolbar-file-dialog' ).data( 'whitespace' );
// Append px to end to size if not already contains it
if ( fileSize !== '' && !hasPxRgx.test( fileSize ) ) {
fileSize += 'px';
}
if ( fileName !== '' ) {
- var fileTitle = mw.Title.newFromText( fileName );
+ let fileTitle = mw.Title.newFromText( fileName );
// Append file namespace prefix to filename if not already contains it
if ( fileTitle && fileTitle.getNamespaceId() !== 6 ) {
fileTitle = mw.Title.makeTitle( 6, fileName );
@@ -411,7 +411,7 @@ module.exports = {
fileName = fileTitle.toText();
}
}
- var options = [ fileSize, fileFormat, fileFloat ];
+ let options = [ fileSize, fileFormat, fileFloat ];
// Filter empty values
options = options.filter( ( val ) => val.length && val !== 'default' );
if ( fileAlt.length ) {
@@ -421,7 +421,7 @@ module.exports = {
options.push( caption );
}
- var fileUse = options.length === 0 ? fileName : ( fileName + '|' + options.join( '|' ) );
+ const fileUse = options.length === 0 ? fileName : ( fileName + '|' + options.join( '|' ) );
$( this ).dialog( 'close' );
toolbarModule.fn.doAction(
$( this ).data( 'context' ),
@@ -456,7 +456,7 @@ module.exports = {
'mediawiki.Upload.Dialog',
'oojs-ui-windows'
] ).then( () => {
- var windowManager = new OO.ui.WindowManager(),
+ const windowManager = new OO.ui.WindowManager(),
uploadDialog = new mw.Upload.Dialog( {
bookletClass: mw.ForeignStructuredUpload.BookletLayout
} );
@@ -476,7 +476,7 @@ module.exports = {
}
},
open: function () {
- var magicWordsI18N = configData.magicWords,
+ let magicWordsI18N = configData.magicWords,
fileData = {
pre: '',
post: '',
@@ -488,30 +488,30 @@ module.exports = {
fileFormat: magicWordsI18N.img_thumbnail[ 0 ]
};
- var parseFileSyntax = function ( wikitext ) {
- var escapedPipe = '\u0001';
+ const parseFileSyntax = function ( wikitext ) {
+ const escapedPipe = '\u0001';
if ( wikitext.indexOf( escapedPipe ) !== -1 ) {
return false;
}
- var match = /^(\s*)\[\[(.*)\]\](\s*)$/.exec( wikitext );
+ const match = /^(\s*)\[\[(.*)\]\](\s*)$/.exec( wikitext );
if ( !match ) {
return false;
}
// Escape pipes inside links and templates,
// then split the parameters at the remaining pipes
- var params = match[ 2 ].replace( /\[\[[^[\]]*\]\]|\{\{[^{}]\}\}/g, ( link ) => link.replace( /\|/g, escapedPipe ) ).split( '|' );
- var file = mw.Title.newFromText( params[ 0 ] );
+ const params = match[ 2 ].replace( /\[\[[^[\]]*\]\]|\{\{[^{}]\}\}/g, ( link ) => link.replace( /\|/g, escapedPipe ) ).split( '|' );
+ const file = mw.Title.newFromText( params[ 0 ] );
if ( !file || file.getNamespaceId() !== 6 ) {
return false;
}
- var result = {
+ const result = {
pre: match[ 1 ],
post: match[ 3 ],
fileName: file.getMainText()
};
- for ( var i = 1; i < params.length; i++ ) {
- var paramOrig = params[ i ];
- var param = paramOrig.toLowerCase();
+ for ( let i = 1; i < params.length; i++ ) {
+ const paramOrig = params[ i ];
+ const param = paramOrig.toLowerCase();
if ( magicWordsI18N.img_right.indexOf( param ) !== -1 ) {
result.fileFloat = magicWordsI18N.img_right[ 0 ];
} else if ( magicWordsI18N.img_left.indexOf( param ) !== -1 ) {
@@ -545,8 +545,8 @@ module.exports = {
};
// Retrieve the current selection
- var context = $( this ).data( 'context' );
- var selection = context.$textarea.textSelection( 'getSelection' );
+ const context = $( this ).data( 'context' );
+ const selection = context.$textarea.textSelection( 'getSelection' );
// Pre-fill the text fields based on the current selection
if ( selection !== '' ) {
@@ -631,11 +631,11 @@ module.exports = {
// Instead of show/hiding, switch the HTML around
// We do this because the sortable tables script styles the first row,
// visible or not
- var headerHTML = $( '.wikieditor-toolbar-table-preview-header' ).html(),
+ const headerHTML = $( '.wikieditor-toolbar-table-preview-header' ).html(),
hiddenHTML = $( '.wikieditor-toolbar-table-preview-hidden' ).html();
$( '.wikieditor-toolbar-table-preview-header' ).html( hiddenHTML );
$( '.wikieditor-toolbar-table-preview-hidden' ).html( headerHTML );
- var $sortable = $( '#wikieditor-toolbar-table-preview, #wikieditor-toolbar-table-preview2' )
+ const $sortable = $( '#wikieditor-toolbar-table-preview, #wikieditor-toolbar-table-preview2' )
.filter( '.sortable' );
mw.loader.using( 'jquery.tablesorter', () => {
$sortable.tablesorter();
@@ -648,7 +648,7 @@ module.exports = {
width: 590,
buttons: {
'wikieditor-toolbar-tool-table-insert': function () {
- var rowsVal = $( '#wikieditor-toolbar-table-dimensions-rows' ).val(),
+ const rowsVal = $( '#wikieditor-toolbar-table-dimensions-rows' ).val(),
colsVal = $( '#wikieditor-toolbar-table-dimensions-columns' ).val(),
rows = parseInt( rowsVal, 10 ),
cols = parseInt( colsVal, 10 ),
@@ -668,16 +668,16 @@ module.exports = {
alert( mw.msg( 'wikieditor-toolbar-tool-table-toomany', mw.language.convertNumber( 1000 ) ) );
return;
}
- var captionText = mw.msg( 'wikieditor-toolbar-tool-table-example-caption' );
- var headerText = mw.msg( 'wikieditor-toolbar-tool-table-example-header' );
- var normalText = mw.msg( 'wikieditor-toolbar-tool-table-example' );
- var table = '';
+ const captionText = mw.msg( 'wikieditor-toolbar-tool-table-example-caption' );
+ const headerText = mw.msg( 'wikieditor-toolbar-tool-table-example-header' );
+ const normalText = mw.msg( 'wikieditor-toolbar-tool-table-example' );
+ let table = '';
table += '|+ ' + captionText + '\n';
- for ( var r = 0; r < rows + header; r++ ) {
+ for ( let r = 0; r < rows + header; r++ ) {
table += '|-\n';
- for ( var c = 0; c < cols; c++ ) {
- var isHeader = ( header && r === 0 );
- var delim = isHeader ? '!' : '|';
+ for ( let c = 0; c < cols; c++ ) {
+ const isHeader = ( header && r === 0 );
+ let delim = isHeader ? '!' : '|';
if ( c > 0 ) {
delim += delim;
}
@@ -687,14 +687,14 @@ module.exports = {
// table[table.length - 1] is read-only
table = table.slice( 0, table.length - 1 ) + '\n';
}
- var classes = [];
+ const classes = [];
if ( $( '#wikieditor-toolbar-table-wikitable' ).is( ':checked' ) ) {
classes.push( 'wikitable' );
}
if ( $( '#wikieditor-toolbar-table-sortable' ).is( ':checked' ) ) {
classes.push( 'sortable' );
}
- var classStr = classes.length > 0 ? ' class="' + classes.join( ' ' ) + '"' : '';
+ const classStr = classes.length > 0 ? ' class="' + classes.join( ' ' ) + '"' : '';
$( this ).dialog( 'close' );
toolbarModule.fn.doAction(
$( this ).data( 'context' ),
@@ -766,26 +766,26 @@ module.exports = {
$( '#wikieditor-toolbar-replace-nomatch, #wikieditor-toolbar-replace-success, #wikieditor-toolbar-replace-emptysearch, #wikieditor-toolbar-replace-invalidregex' ).hide();
// Search string cannot be empty
- var searchStr = $( '#wikieditor-toolbar-replace-search' ).val();
+ let searchStr = $( '#wikieditor-toolbar-replace-search' ).val();
if ( searchStr === '' ) {
$( '#wikieditor-toolbar-replace-emptysearch' ).show();
return;
}
// Replace string can be empty
- var replaceStr = $( '#wikieditor-toolbar-replace-replace' ).val();
+ const replaceStr = $( '#wikieditor-toolbar-replace-replace' ).val();
// Prepare the regular expression flags
- var flags = 'm';
- var matchCase = $( '#wikieditor-toolbar-replace-case' ).is( ':checked' );
+ let flags = 'm';
+ const matchCase = $( '#wikieditor-toolbar-replace-case' ).is( ':checked' );
if ( !matchCase ) {
flags += 'i';
}
- var isRegex = $( '#wikieditor-toolbar-replace-regex' ).is( ':checked' );
+ const isRegex = $( '#wikieditor-toolbar-replace-regex' ).is( ':checked' );
if ( !isRegex ) {
searchStr = mw.util.escapeRegExp( searchStr );
}
- var matchWord = $( '#wikieditor-toolbar-replace-word' ).is( ':checked' );
+ const matchWord = $( '#wikieditor-toolbar-replace-word' ).is( ':checked' );
if ( matchWord ) {
searchStr = '\\b(?:' + searchStr + ')\\b';
}
@@ -793,7 +793,7 @@ module.exports = {
flags += 'g';
}
- var regex;
+ let regex;
try {
regex = new RegExp( searchStr, flags );
} catch ( e ) {
@@ -804,10 +804,10 @@ module.exports = {
return;
}
- var $textarea = $( this ).data( 'context' ).$textarea;
- var text = $textarea.textSelection( 'getContents' );
- var match = false;
- var offset, textRemainder;
+ const $textarea = $( this ).data( 'context' ).$textarea;
+ let text = $textarea.textSelection( 'getContents' );
+ let match = false;
+ let offset, textRemainder;
if ( mode !== 'replaceAll' ) {
offset = $( this ).data( mode === 'replace' ? 'matchIndex' : 'offset' );
textRemainder = text.slice( offset );
@@ -831,10 +831,10 @@ module.exports = {
$( this ).data( 'offset', 0 );
} else {
- var start, end;
+ let start, end;
if ( mode === 'replace' ) {
- var actualReplacement;
+ let actualReplacement;
if ( isRegex ) {
// If backreferences (like $1) are used, the actual actual replacement string will be different
actualReplacement = match[ 0 ].replace( regex, replaceStr );
@@ -907,7 +907,7 @@ module.exports = {
}
},
open: function () {
- var that = this;
+ let that = this;
$( this ).data( { offset: 0, matchIndex: 0 } );
$( '#wikieditor-toolbar-replace-search' ).trigger( 'focus' );
@@ -928,7 +928,7 @@ module.exports = {
$( this ).closest( '.ui-dialog' ).data( 'dialogaction', this );
} );
}
- var $dialog = $( this ).closest( '.ui-dialog' );
+ const $dialog = $( this ).closest( '.ui-dialog' );
that = this;
$( this ).data( 'context' ).$textarea
.on( 'keypress.srdialog', ( e ) => {
diff --git a/modules/jquery.wikiEditor.dialogs.js b/modules/jquery.wikiEditor.dialogs.js
index 07933b00..4c45b37f 100644
--- a/modules/jquery.wikiEditor.dialogs.js
+++ b/modules/jquery.wikiEditor.dialogs.js
@@ -3,7 +3,7 @@
*
* @memberof module:ext.wikiEditor
*/
-var dialogsModule = {
+const dialogsModule = {
/**
* API accessible functions
@@ -14,8 +14,8 @@ var dialogsModule = {
},
openDialog: function ( context, module ) {
if ( module in dialogsModule.modules ) {
- var mod = dialogsModule.modules[ module ];
- var $dialog = $( '#' + mod.id );
+ const mod = dialogsModule.modules[ module ];
+ let $dialog = $( '#' + mod.id );
if ( $dialog.length === 0 ) {
dialogsModule.fn.reallyCreate( context, mod, module );
$dialog = $( '#' + mod.id );
@@ -48,12 +48,12 @@ var dialogsModule = {
*/
create: function ( context, config ) {
// Defer building of modules, unless they require immediate creation
- for ( var mod in config ) {
- var module = config[ mod ];
+ for ( const mod in config ) {
+ const module = config[ mod ];
// Only create the dialog if it isn't filtered and doesn't exist yet
- var filtered = false;
+ let filtered = false;
if ( typeof module.filters !== 'undefined' ) {
- for ( var i = 0; i < module.filters.length; i++ ) {
+ for ( let i = 0; i < module.filters.length; i++ ) {
if ( $( module.filters[ i ] ).length === 0 ) {
filtered = true;
break;
@@ -61,7 +61,7 @@ var dialogsModule = {
}
}
// If the dialog already exists, but for another textarea, simply remove it
- var $existingDialog = $( '#' + module.id );
+ let $existingDialog = $( '#' + module.id );
if ( $existingDialog.length > 0 && $existingDialog.data( 'context' ).$textarea !== context.$textarea ) {
$existingDialog.remove();
}
@@ -86,7 +86,7 @@ var dialogsModule = {
* @param {string} name Dialog name (key in dialogsModule.modules)
*/
reallyCreate: function ( context, module, name ) {
- var configuration = module.dialog;
+ const configuration = module.dialog;
// Add some stuff to configuration
configuration.bgiframe = true;
configuration.autoOpen = false;
@@ -99,12 +99,12 @@ var dialogsModule = {
// Stupid JS won't let us do stuff like
// foo = { mw.msg( 'bar' ): baz }
configuration.newButtons = {};
- for ( var msg in configuration.buttons ) {
+ for ( const msg in configuration.buttons ) {
// eslint-disable-next-line mediawiki/msg-doc
configuration.newButtons[ mw.msg( msg ) ] = configuration.buttons[ msg ];
}
configuration.buttons = configuration.newButtons;
- var $content;
+ let $content;
if ( module.htmlTemplate ) {
$content = mw.template.get( 'ext.wikiEditor', module.htmlTemplate ).render();
} else if ( module.html instanceof $ ) {
@@ -113,7 +113,7 @@ var dialogsModule = {
$content = $( $.parseHTML( module.html ) );
}
// Create the dialog