mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/WikiEditor
synced 2024-11-23 15:57:15 +00:00
ESLint: Enforce no-var and autofix
Change-Id: I6f2a1e11acdcdb70902357316b504f903abe8bca
This commit is contained in:
parent
5fc902bd9c
commit
796d82a7ab
|
@ -11,6 +11,6 @@
|
|||
"rules": {
|
||||
"max-len": "off",
|
||||
"no-jquery/no-global-selector": "off",
|
||||
"no-var": "off"
|
||||
"prefer-const": "warn"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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' ]
|
||||
|
|
|
@ -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' ]
|
||||
};
|
||||
|
|
|
@ -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() )
|
||||
) {
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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, '<nowiki>$1</nowiki>' );
|
||||
|
@ -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 ) => {
|
||||
|
|
|
@ -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 <div>
|
||||
var $dialogDiv = $( '<div>' )
|
||||
const $dialogDiv = $( '<div>' )
|
||||
.attr( 'id', module.id )
|
||||
.append( $content )
|
||||
.data( 'context', context )
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
/**
|
||||
* @private
|
||||
*/
|
||||
var hasOwn = Object.prototype.hasOwnProperty,
|
||||
const hasOwn = Object.prototype.hasOwnProperty,
|
||||
|
||||
/**
|
||||
* Array of language codes.
|
||||
|
@ -20,7 +20,7 @@ var hasOwn = Object.prototype.hasOwnProperty,
|
|||
*/
|
||||
fallbackChain = ( function () {
|
||||
// eslint-disable-next-line no-jquery/no-class-state
|
||||
var isRTL = $( document.body ).hasClass( 'rtl' ),
|
||||
const isRTL = $( document.body ).hasClass( 'rtl' ),
|
||||
chain = mw.language.getFallbackLanguageChain();
|
||||
|
||||
// Do not fallback to 'en'
|
||||
|
@ -43,10 +43,10 @@ var hasOwn = Object.prototype.hasOwnProperty,
|
|||
* @param {string} key
|
||||
*/
|
||||
function deprecateAutoMsg( property, key ) {
|
||||
var searchParam = mw.config.get( 'wgSearchType' ) === 'CirrusSearch' ?
|
||||
const searchParam = mw.config.get( 'wgSearchType' ) === 'CirrusSearch' ?
|
||||
'insource:/' + property + 'Msg: \'' + key + '\'/' :
|
||||
property + 'Msg: ' + key;
|
||||
var searchUri = mw.config.get( 'wgServer' ) +
|
||||
let searchUri = mw.config.get( 'wgServer' ) +
|
||||
mw.util.getUrl(
|
||||
'Special:Search',
|
||||
{ search: searchParam, ns2: 1, ns8: 1 }
|
||||
|
@ -55,13 +55,13 @@ function deprecateAutoMsg( property, key ) {
|
|||
searchUri = location.protocol + searchUri;
|
||||
}
|
||||
|
||||
var messageMethod;
|
||||
let messageMethod;
|
||||
if ( property === 'html' || property === 'text' || property === 'title' ) {
|
||||
messageMethod = 'mw.message( ' + JSON.stringify( key ) + ' ).parse()';
|
||||
} else {
|
||||
messageMethod = 'mw.msg( ' + JSON.stringify( key ) + ' )';
|
||||
}
|
||||
var deprecationMsg = mw.log.makeDeprecated(
|
||||
const deprecationMsg = mw.log.makeDeprecated(
|
||||
'wikiEditor_autoMsg',
|
||||
'WikiEditor: Use `' + property + ': ' + messageMethod + '` instead of `' + property + 'Msg: ' + JSON.stringify( key ) + '`.\nSearch: ' + searchUri
|
||||
);
|
||||
|
@ -110,7 +110,7 @@ $.wikiEditor = {
|
|||
*/
|
||||
isRequired: function ( module, requirement ) {
|
||||
if ( typeof module.req !== 'undefined' ) {
|
||||
for ( var req in module.req ) {
|
||||
for ( const req in module.req ) {
|
||||
if ( module.req[ req ] === requirement ) {
|
||||
return true;
|
||||
}
|
||||
|
@ -138,7 +138,7 @@ $.wikiEditor = {
|
|||
autoMsg: function ( object, property ) {
|
||||
// Accept array of possible properties, of which the first one found will be used
|
||||
if ( typeof property === 'object' ) {
|
||||
for ( var i in property ) {
|
||||
for ( const i in property ) {
|
||||
if ( property[ i ] in object || property[ i ] + 'Msg' in object ) {
|
||||
property = property[ i ];
|
||||
break;
|
||||
|
@ -148,7 +148,7 @@ $.wikiEditor = {
|
|||
if ( property in object ) {
|
||||
return object[ property ];
|
||||
} else if ( property + 'Msg' in object ) {
|
||||
var p = object[ property + 'Msg' ];
|
||||
const p = object[ property + 'Msg' ];
|
||||
if ( Array.isArray( p ) && p.length >= 2 ) {
|
||||
deprecateAutoMsg( property, p[ 0 ] );
|
||||
return mw.message.apply( mw.message, p ).text();
|
||||
|
@ -179,7 +179,7 @@ $.wikiEditor = {
|
|||
autoSafeMsg: function ( object, property ) {
|
||||
// Accept array of possible properties, of which the first one found will be used
|
||||
if ( typeof property === 'object' ) {
|
||||
for ( var i in property ) {
|
||||
for ( const i in property ) {
|
||||
if ( property[ i ] in object || property[ i ] + 'Msg' in object ) {
|
||||
property = property[ i ];
|
||||
break;
|
||||
|
@ -189,7 +189,7 @@ $.wikiEditor = {
|
|||
if ( property in object ) {
|
||||
return object[ property ];
|
||||
} else if ( property + 'Msg' in object ) {
|
||||
var p = object[ property + 'Msg' ];
|
||||
const p = object[ property + 'Msg' ];
|
||||
if ( Array.isArray( p ) && p.length >= 2 ) {
|
||||
deprecateAutoMsg( property, p[ 0 ] );
|
||||
return mw.message.apply( mw.message, p ).escaped();
|
||||
|
@ -213,8 +213,8 @@ $.wikiEditor = {
|
|||
* @return {Object}
|
||||
*/
|
||||
autoLang: function ( object ) {
|
||||
for ( var i = 0; i < fallbackChain.length; i++ ) {
|
||||
var key = fallbackChain[ i ];
|
||||
for ( let i = 0; i < fallbackChain.length; i++ ) {
|
||||
const key = fallbackChain[ i ];
|
||||
if ( hasOwn.call( object, key ) ) {
|
||||
return object[ key ];
|
||||
}
|
||||
|
@ -233,10 +233,10 @@ $.wikiEditor = {
|
|||
autoIcon: function ( icon, path ) {
|
||||
path = path || $.wikiEditor.imgPath;
|
||||
|
||||
for ( var i = 0; i < fallbackChain.length; i++ ) {
|
||||
var key = fallbackChain[ i ];
|
||||
for ( let i = 0; i < fallbackChain.length; i++ ) {
|
||||
const key = fallbackChain[ i ];
|
||||
if ( icon && hasOwn.call( icon, key ) ) {
|
||||
var src = icon[ key ];
|
||||
let src = icon[ key ];
|
||||
|
||||
// Return a data URL immediately
|
||||
if ( src.slice( 0, 5 ) === 'data:' ) {
|
||||
|
@ -264,7 +264,7 @@ $.fn.wikiEditor = function () {
|
|||
|
||||
// The wikiEditor context is stored in the element's data, so when this function gets called again we can pick up right
|
||||
// where we left off
|
||||
var context = $( this ).data( 'wikiEditor-context' );
|
||||
let context = $( this ).data( 'wikiEditor-context' );
|
||||
// On first call, we need to set things up, but on all following calls we can skip right to the API handling
|
||||
if ( !context ) {
|
||||
|
||||
|
@ -303,18 +303,18 @@ $.fn.wikiEditor = function () {
|
|||
* or an object with members keyed with module names and valued with configuration objects.
|
||||
*/
|
||||
addModule: function ( ctx, data ) {
|
||||
var modules = {};
|
||||
let modules = {};
|
||||
if ( typeof data === 'string' ) {
|
||||
modules[ data ] = {};
|
||||
} else if ( typeof data === 'object' ) {
|
||||
modules = data;
|
||||
}
|
||||
for ( var module in modules ) {
|
||||
for ( const module in modules ) {
|
||||
// Check for the existence of an available module with a matching name and a create function
|
||||
if ( typeof module === 'string' && typeof $.wikiEditor.modules[ module ] !== 'undefined' ) {
|
||||
// Extend the context's core API with this module's own API calls
|
||||
if ( 'api' in $.wikiEditor.modules[ module ] ) {
|
||||
for ( var call in $.wikiEditor.modules[ module ].api ) {
|
||||
for ( const call in $.wikiEditor.modules[ module ].api ) {
|
||||
// Modules may not overwrite existing API functions - first come, first serve
|
||||
if ( !( call in ctx.api ) ) {
|
||||
ctx.api[ call ] = $.wikiEditor.modules[ module ].api[ call ];
|
||||
|
@ -369,16 +369,16 @@ $.fn.wikiEditor = function () {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
var returnFromModules = true;
|
||||
let returnFromModules = true;
|
||||
// Pass the event around to all modules activated on this context
|
||||
|
||||
for ( var module in context.modules ) {
|
||||
for ( const module in context.modules ) {
|
||||
if (
|
||||
module in $.wikiEditor.modules &&
|
||||
'evt' in $.wikiEditor.modules[ module ] &&
|
||||
name in $.wikiEditor.modules[ module ].evt
|
||||
) {
|
||||
var ret = $.wikiEditor.modules[ module ].evt[ name ]( context, event );
|
||||
const ret = $.wikiEditor.modules[ module ].evt[ name ]( context, event );
|
||||
if ( ret !== null ) {
|
||||
// if 1 returns false, the end result is false
|
||||
returnFromModules = returnFromModules && ret;
|
||||
|
@ -493,8 +493,8 @@ $.fn.wikiEditor = function () {
|
|||
*/
|
||||
|
||||
/* Preserving cursor and focus state, which will get lost due to wrapAll */
|
||||
var hasFocus = context.$textarea.is( ':focus' );
|
||||
var cursorPos = context.$textarea.textSelection( 'getCaretPosition', { startAndEnd: true } );
|
||||
const hasFocus = context.$textarea.is( ':focus' );
|
||||
const cursorPos = context.$textarea.textSelection( 'getCaretPosition', { startAndEnd: true } );
|
||||
// Encapsulate the textarea with some containers for layout
|
||||
context.$textarea
|
||||
.wrapAll( $( '<div>' ).addClass( 'wikiEditor-ui' ) )
|
||||
|
@ -545,19 +545,19 @@ $.fn.wikiEditor = function () {
|
|||
/* API Execution */
|
||||
|
||||
// Since javascript gives arguments as an object, we need to convert them so they can be used more easily
|
||||
var args = $.makeArray( arguments );
|
||||
const args = $.makeArray( arguments );
|
||||
|
||||
// Dynamically setup core extensions for modules that are required
|
||||
if ( args[ 0 ] === 'addModule' && typeof args[ 1 ] !== 'undefined' ) {
|
||||
var modulesArg = args[ 1 ];
|
||||
let modulesArg = args[ 1 ];
|
||||
if ( typeof modulesArg !== 'object' ) {
|
||||
modulesArg = {};
|
||||
modulesArg[ args[ 1 ] ] = '';
|
||||
}
|
||||
for ( var m in modulesArg ) {
|
||||
for ( const m in modulesArg ) {
|
||||
if ( m in $.wikiEditor.modules ) {
|
||||
// Activate all required core extensions on context
|
||||
for ( var extension in $.wikiEditor.extensions ) {
|
||||
for ( const extension in $.wikiEditor.extensions ) {
|
||||
if (
|
||||
$.wikiEditor.isRequired( $.wikiEditor.modules[ m ], extension ) &&
|
||||
context.extensions.indexOf( extension ) === -1
|
||||
|
@ -574,7 +574,7 @@ $.fn.wikiEditor = function () {
|
|||
// There would need to be some arguments if the API is being called
|
||||
if ( args.length > 0 ) {
|
||||
// Handle API calls
|
||||
var callArg = args.shift();
|
||||
const callArg = args.shift();
|
||||
if ( callArg in context.api ) {
|
||||
context.api[ callArg ]( context, args[ 0 ] || {} );
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* @private
|
||||
*/
|
||||
var configData = require( './data.json' ),
|
||||
let configData = require( './data.json' ),
|
||||
fileNamespace = mw.config.get( 'wgFormattedNamespaces' )[ 6 ],
|
||||
specialCharacterGroups = require( 'mediawiki.language.specialCharacters' ),
|
||||
toolbarConfig;
|
||||
|
@ -18,7 +18,7 @@ var configData = require( './data.json' ),
|
|||
*/
|
||||
function delink( $message ) {
|
||||
// dummy div to append the message to
|
||||
var $div = $( '<div>' );
|
||||
const $div = $( '<div>' );
|
||||
|
||||
$div.append( $message );
|
||||
$div.find( 'a' ).attr( 'href', '#' );
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
*
|
||||
* @memberof module:ext.wikiEditor
|
||||
*/
|
||||
var toolbarModule = {
|
||||
|
||||
const toolbarModule = {
|
||||
|
||||
/**
|
||||
* API accessible functions
|
||||
|
@ -11,13 +12,13 @@ var toolbarModule = {
|
|||
api: {
|
||||
addToToolbar: function ( context, data ) {
|
||||
|
||||
for ( var type in data ) {
|
||||
var i;
|
||||
for ( const type in data ) {
|
||||
let i;
|
||||
switch ( type ) {
|
||||
case 'sections':
|
||||
var $sections = context.modules.toolbar.$toolbar.find( 'div.sections' );
|
||||
var $tabs = context.modules.toolbar.$toolbar.find( 'div.tabs' );
|
||||
for ( var section in data[ type ] ) {
|
||||
case 'sections': {
|
||||
const $sections = context.modules.toolbar.$toolbar.find( 'div.sections' );
|
||||
const $tabs = context.modules.toolbar.$toolbar.find( 'div.tabs' );
|
||||
for ( const section in data[ type ] ) {
|
||||
if ( section === 'main' || section === 'secondary' ) {
|
||||
// Section
|
||||
context.modules.toolbar.$toolbar.prepend(
|
||||
|
@ -37,27 +38,29 @@ var toolbarModule = {
|
|||
);
|
||||
}
|
||||
break;
|
||||
case 'groups':
|
||||
}
|
||||
case 'groups': {
|
||||
if ( !( 'section' in data ) ) {
|
||||
continue;
|
||||
}
|
||||
var $section = context.modules.toolbar.$toolbar.find( 'div[rel="' + data.section + '"].section' );
|
||||
for ( var group in data[ type ] ) {
|
||||
const $section = context.modules.toolbar.$toolbar.find( 'div[rel="' + data.section + '"].section' );
|
||||
for ( const group in data[ type ] ) {
|
||||
// Group
|
||||
$section.append(
|
||||
toolbarModule.fn.buildGroup( context, group, data[ type ][ group ] )
|
||||
);
|
||||
}
|
||||
break;
|
||||
case 'tools':
|
||||
}
|
||||
case 'tools': {
|
||||
if ( !( 'section' in data && 'group' in data ) ) {
|
||||
continue;
|
||||
}
|
||||
var $group = context.modules.toolbar.$toolbar.find(
|
||||
const $group = context.modules.toolbar.$toolbar.find(
|
||||
'div[rel="' + data.section + '"].section ' +
|
||||
'div[rel="' + data.group + '"].group'
|
||||
);
|
||||
for ( var tool in data[ type ] ) {
|
||||
for ( const tool in data[ type ] ) {
|
||||
// Tool
|
||||
$group.append( toolbarModule.fn.buildTool( context, tool, data[ type ][ tool ] ) );
|
||||
}
|
||||
|
@ -65,17 +68,18 @@ var toolbarModule = {
|
|||
$group.removeClass( 'empty' );
|
||||
}
|
||||
break;
|
||||
case 'pages':
|
||||
}
|
||||
case 'pages': {
|
||||
if ( !( 'section' in data ) ) {
|
||||
continue;
|
||||
}
|
||||
var $pages = context.modules.toolbar.$toolbar.find(
|
||||
const $pages = context.modules.toolbar.$toolbar.find(
|
||||
'div[rel="' + data.section + '"].section .pages'
|
||||
);
|
||||
var $index = context.modules.toolbar.$toolbar.find(
|
||||
const $index = context.modules.toolbar.$toolbar.find(
|
||||
'div[rel="' + data.section + '"].section .index'
|
||||
);
|
||||
for ( var page in data[ type ] ) {
|
||||
for ( const page in data[ type ] ) {
|
||||
// Page
|
||||
$pages.append( toolbarModule.fn.buildPage( context, page, data[ type ][ page ] ) );
|
||||
// Index
|
||||
|
@ -85,11 +89,12 @@ var toolbarModule = {
|
|||
}
|
||||
toolbarModule.fn.updateBookletSelection( context, data.section, $pages, $index );
|
||||
break;
|
||||
case 'rows':
|
||||
}
|
||||
case 'rows': {
|
||||
if ( !( 'section' in data && 'page' in data ) ) {
|
||||
continue;
|
||||
}
|
||||
var $table = context.modules.toolbar.$toolbar.find(
|
||||
const $table = context.modules.toolbar.$toolbar.find(
|
||||
'div[rel="' + data.section + '"].section ' +
|
||||
'div[rel="' + data.page + '"].page table'
|
||||
);
|
||||
|
@ -98,15 +103,16 @@ var toolbarModule = {
|
|||
$table.append( toolbarModule.fn.buildRow( context, data.rows[ i ] ) );
|
||||
}
|
||||
break;
|
||||
case 'characters':
|
||||
}
|
||||
case 'characters': {
|
||||
if ( !( 'section' in data && 'page' in data ) ) {
|
||||
continue;
|
||||
}
|
||||
var $characters = context.modules.toolbar.$toolbar.find(
|
||||
const $characters = context.modules.toolbar.$toolbar.find(
|
||||
'div[rel="' + data.section + '"].section ' +
|
||||
'div[rel="' + data.page + '"].page div'
|
||||
);
|
||||
var actions = $characters.data( 'actions' );
|
||||
const actions = $characters.data( 'actions' );
|
||||
for ( i = 0; i < data.characters.length; i++ ) {
|
||||
// Character
|
||||
$characters.append(
|
||||
|
@ -125,6 +131,7 @@ var toolbarModule = {
|
|||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
@ -132,9 +139,9 @@ var toolbarModule = {
|
|||
removeFromToolbar: function ( context, data ) {
|
||||
if ( typeof data.section === 'string' ) {
|
||||
// Section
|
||||
var tab = 'div.tabs span[rel="' + data.section + '"].tab';
|
||||
var target = 'div[rel="' + data.section + '"].section';
|
||||
var group = null;
|
||||
const tab = 'div.tabs span[rel="' + data.section + '"].tab';
|
||||
let target = 'div[rel="' + data.section + '"].section';
|
||||
let group = null;
|
||||
if ( typeof data.group === 'string' ) {
|
||||
// Toolbar group
|
||||
target += ' div[rel="' + data.group + '"].group';
|
||||
|
@ -146,7 +153,7 @@ var toolbarModule = {
|
|||
}
|
||||
} else if ( typeof data.page === 'string' ) {
|
||||
// Booklet page
|
||||
var index = target + ' div.index div[rel="' + data.page + '"]';
|
||||
const index = target + ' div.index div[rel="' + data.page + '"]';
|
||||
target += ' div.pages div[rel="' + data.page + '"].page';
|
||||
if ( typeof data.character === 'string' ) {
|
||||
// Character
|
||||
|
@ -171,7 +178,7 @@ var toolbarModule = {
|
|||
context.modules.toolbar.$toolbar.find( target ).remove();
|
||||
// Hide empty groups
|
||||
if ( group ) {
|
||||
var $group = context.modules.toolbar.$toolbar.find( group );
|
||||
const $group = context.modules.toolbar.$toolbar.find( group );
|
||||
if ( $group.children().length === 0 ) {
|
||||
$group.addClass( 'empty' );
|
||||
}
|
||||
|
@ -209,18 +216,18 @@ var toolbarModule = {
|
|||
doAction: function ( context, action ) {
|
||||
switch ( action.type ) {
|
||||
case 'replace':
|
||||
case 'encapsulate':
|
||||
case 'encapsulate': {
|
||||
if ( context.$textarea.prop( 'readonly' ) ) {
|
||||
break;
|
||||
}
|
||||
var parts = {
|
||||
const parts = {
|
||||
pre: $.wikiEditor.autoMsg( action.options, 'pre' ),
|
||||
peri: $.wikiEditor.autoMsg( action.options, 'peri' ),
|
||||
post: $.wikiEditor.autoMsg( action.options, 'post' )
|
||||
};
|
||||
var replace = action.type === 'replace';
|
||||
let replace = action.type === 'replace';
|
||||
if ( 'regex' in action.options && 'regexReplace' in action.options ) {
|
||||
var selection = context.$textarea.textSelection( 'getSelection' );
|
||||
const selection = context.$textarea.textSelection( 'getSelection' );
|
||||
if ( selection !== '' && action.options.regex.test( selection ) ) {
|
||||
parts.peri = selection.replace( action.options.regex,
|
||||
action.options.regexReplace );
|
||||
|
@ -233,6 +240,7 @@ var toolbarModule = {
|
|||
Object.assign( {}, action.options, parts, { replace: replace } )
|
||||
);
|
||||
break;
|
||||
}
|
||||
case 'callback':
|
||||
if ( typeof action.execute === 'function' ) {
|
||||
action.execute( context );
|
||||
|
@ -246,15 +254,15 @@ var toolbarModule = {
|
|||
}
|
||||
},
|
||||
buildGroup: function ( context, id, group ) {
|
||||
var $group = $( '<div>' ).attr( { class: 'group group-' + id, rel: id } ),
|
||||
const $group = $( '<div>' ).attr( { class: 'group group-' + id, rel: id } ),
|
||||
label = $.wikiEditor.autoMsg( group, 'label' );
|
||||
if ( label ) {
|
||||
$( '<span>' ).addClass( 'label' ).text( label ).appendTo( $group );
|
||||
}
|
||||
var empty = true;
|
||||
let empty = true;
|
||||
if ( 'tools' in group ) {
|
||||
for ( var tool in group.tools ) {
|
||||
var $tool = toolbarModule.fn.buildTool( context, tool, group.tools[ tool ] );
|
||||
for ( const tool in group.tools ) {
|
||||
const $tool = toolbarModule.fn.buildTool( context, tool, group.tools[ tool ] );
|
||||
if ( $tool ) {
|
||||
// Consider a group with only hidden tools empty as well
|
||||
// .is( ':visible' ) always returns false because tool is not attached to the DOM yet
|
||||
|
@ -270,25 +278,25 @@ var toolbarModule = {
|
|||
},
|
||||
buildTool: function ( context, id, tool ) {
|
||||
if ( 'filters' in tool ) {
|
||||
for ( var i = 0; i < tool.filters.length; i++ ) {
|
||||
for ( let i = 0; i < tool.filters.length; i++ ) {
|
||||
if ( $( tool.filters[ i ] ).length === 0 ) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
var label = $.wikiEditor.autoMsg( tool, 'label' );
|
||||
const label = $.wikiEditor.autoMsg( tool, 'label' );
|
||||
switch ( tool.type ) {
|
||||
case 'button':
|
||||
case 'toggle':
|
||||
var $button;
|
||||
case 'toggle': {
|
||||
let $button;
|
||||
if ( tool.oouiIcon ) {
|
||||
var config = {
|
||||
const config = {
|
||||
framed: false,
|
||||
classes: [ 'tool' ],
|
||||
icon: tool.oouiIcon,
|
||||
title: label
|
||||
};
|
||||
var oouiButton;
|
||||
let oouiButton;
|
||||
if ( tool.type === 'button' ) {
|
||||
oouiButton = new OO.ui.ButtonWidget( config );
|
||||
} else if ( tool.type === 'toggle' ) {
|
||||
|
@ -308,7 +316,7 @@ var toolbarModule = {
|
|||
} )
|
||||
.text( label );
|
||||
if ( tool.icon ) {
|
||||
var icon = $.wikiEditor.autoIcon(
|
||||
const icon = $.wikiEditor.autoIcon(
|
||||
tool.icon,
|
||||
$.wikiEditor.imgPath + 'toolbar/'
|
||||
);
|
||||
|
@ -364,14 +372,15 @@ var toolbarModule = {
|
|||
}
|
||||
}
|
||||
return $button;
|
||||
case 'select':
|
||||
var menuId = 'menu-' + Date.now();
|
||||
var $select = $( '<div>' )
|
||||
}
|
||||
case 'select': {
|
||||
const menuId = 'menu-' + Date.now();
|
||||
const $select = $( '<div>' )
|
||||
.attr( { rel: id, class: 'tool tool-select' } );
|
||||
var $options = $( '<div>' ).addClass( 'options' );
|
||||
const $options = $( '<div>' ).addClass( 'options' );
|
||||
if ( 'list' in tool ) {
|
||||
for ( var option in tool.list ) {
|
||||
var optionLabel = $.wikiEditor.autoMsg( tool.list[ option ], 'label' );
|
||||
for ( const option in tool.list ) {
|
||||
const optionLabel = $.wikiEditor.autoMsg( tool.list[ option ], 'label' );
|
||||
$options.append(
|
||||
$( '<a>' )
|
||||
.data( 'action', tool.list[ option ].action )
|
||||
|
@ -416,9 +425,9 @@ var toolbarModule = {
|
|||
e.type === 'click' ||
|
||||
e.type === 'keydown' && e.key === 'Enter'
|
||||
) {
|
||||
var $opts = $( this ).data( 'options' );
|
||||
const $opts = $( this ).data( 'options' );
|
||||
// eslint-disable-next-line no-jquery/no-class-state
|
||||
var canShowOptions = !$opts.closest( '.tool-select' ).hasClass( 'options-shown' );
|
||||
const canShowOptions = !$opts.closest( '.tool-select' ).hasClass( 'options-shown' );
|
||||
$opts.closest( '.tool-select' ).toggleClass( 'options-shown', canShowOptions );
|
||||
$( this ).attr( 'aria-expanded', canShowOptions.toString() );
|
||||
e.preventDefault();
|
||||
|
@ -428,9 +437,10 @@ var toolbarModule = {
|
|||
);
|
||||
$select.append( $( '<div>' ).addClass( 'menu' ).append( $options ) );
|
||||
return $select;
|
||||
case 'element':
|
||||
}
|
||||
case 'element': {
|
||||
// A raw 'element' type can be {htmlString|Element|Text|Array|jQuery|OO.ui.HTMLSnippet|function}.
|
||||
var $element;
|
||||
let $element;
|
||||
if ( tool.element instanceof OO.ui.HtmlSnippet ) {
|
||||
$element = tool.element.toString();
|
||||
} else if ( typeof tool.element === 'function' ) {
|
||||
|
@ -441,12 +451,13 @@ var toolbarModule = {
|
|||
return $( '<div>' )
|
||||
.attr( { rel: id, class: 'tool tool-element' } )
|
||||
.append( $element );
|
||||
}
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
},
|
||||
buildBookmark: function ( context, id, page ) {
|
||||
var label = $.wikiEditor.autoMsg( page, 'label' );
|
||||
const label = $.wikiEditor.autoMsg( page, 'label' );
|
||||
return $( '<div>' )
|
||||
.text( label )
|
||||
.attr( {
|
||||
|
@ -465,7 +476,7 @@ var toolbarModule = {
|
|||
$( this )
|
||||
.addClass( 'current' )
|
||||
.siblings().removeClass( 'current' );
|
||||
var section = $( this ).parent().parent().attr( 'rel' );
|
||||
const section = $( this ).parent().parent().attr( 'rel' );
|
||||
$.cookie(
|
||||
'wikiEditor-' + $( this ).data( 'context' ).instance + '-booklet-' + section + '-page',
|
||||
$( this ).attr( 'rel' ),
|
||||
|
@ -477,7 +488,7 @@ var toolbarModule = {
|
|||
} );
|
||||
},
|
||||
buildPage: function ( context, id, page, deferLoad ) {
|
||||
var $page = $( '<div>' ).attr( {
|
||||
const $page = $( '<div>' ).attr( {
|
||||
class: 'page page-' + id,
|
||||
rel: id
|
||||
} );
|
||||
|
@ -491,11 +502,11 @@ var toolbarModule = {
|
|||
return $page;
|
||||
},
|
||||
reallyBuildPage: function ( context, id, page, $page ) {
|
||||
var i;
|
||||
let i;
|
||||
switch ( page.layout ) {
|
||||
case 'table':
|
||||
case 'table': {
|
||||
$page.addClass( 'page-table' );
|
||||
var html = '';
|
||||
let html = '';
|
||||
if ( 'headings' in page ) {
|
||||
html += toolbarModule.fn.buildHeading( context, page.headings );
|
||||
}
|
||||
|
@ -506,10 +517,11 @@ var toolbarModule = {
|
|||
}
|
||||
$page.html( '<table class="table-' + id + '">' + html + '</table>' );
|
||||
break;
|
||||
case 'characters':
|
||||
}
|
||||
case 'characters': {
|
||||
$page.addClass( 'page-characters' );
|
||||
var $characters = $( '<div>' ).data( 'context', context ).data( 'actions', {} );
|
||||
var actions = $characters.data( 'actions' );
|
||||
const $characters = $( '<div>' ).data( 'context', context ).data( 'actions', {} );
|
||||
const actions = $characters.data( 'actions' );
|
||||
if ( 'language' in page ) {
|
||||
$characters.attr( 'lang', page.language );
|
||||
}
|
||||
|
@ -522,7 +534,7 @@ var toolbarModule = {
|
|||
$characters.attr( 'dir', 'ltr' );
|
||||
}
|
||||
if ( 'characters' in page ) {
|
||||
html = '';
|
||||
let html = '';
|
||||
for ( i = 0; i < page.characters.length; i++ ) {
|
||||
html += toolbarModule.fn.buildCharacter( page.characters[ i ], actions );
|
||||
}
|
||||
|
@ -548,17 +560,18 @@ var toolbarModule = {
|
|||
$page.append( $characters );
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
buildHeading: function ( context, headings ) {
|
||||
var html = '';
|
||||
for ( var i = 0; i < headings.length; i++ ) {
|
||||
let html = '';
|
||||
for ( let i = 0; i < headings.length; i++ ) {
|
||||
html += '<th>' + $.wikiEditor.autoSafeMsg( headings[ i ], [ 'html', 'text' ] ) + '</th>';
|
||||
}
|
||||
return '<tr>' + html + '</tr>';
|
||||
},
|
||||
buildRow: function ( context, row ) {
|
||||
var html = '';
|
||||
for ( var cell in row ) {
|
||||
let html = '';
|
||||
for ( const cell in row ) {
|
||||
// FIXME: This currently needs to use the "unsafe" .text() message because it embeds raw HTML
|
||||
// in the messages (as used exclusively by the 'help' toolbar panel).
|
||||
html += '<td class="cell cell-' + cell + '"><span>' +
|
||||
|
@ -595,7 +608,7 @@ var toolbarModule = {
|
|||
if ( character && 'action' in character && 'label' in character ) {
|
||||
actions[ character.label ] = character.action;
|
||||
// eslint-disable-next-line mediawiki/msg-doc
|
||||
var title = character.titleMsg ? mw.msg( character.titleMsg ) : character.title;
|
||||
const title = character.titleMsg ? mw.msg( character.titleMsg ) : character.title;
|
||||
return mw.html.element(
|
||||
'span',
|
||||
{ rel: character.label, title: title || false },
|
||||
|
@ -607,12 +620,12 @@ var toolbarModule = {
|
|||
return '';
|
||||
},
|
||||
buildTab: function ( context, id, section ) {
|
||||
var selected = $.cookie( 'wikiEditor-' + context.instance + '-toolbar-section' );
|
||||
const selected = $.cookie( 'wikiEditor-' + context.instance + '-toolbar-section' );
|
||||
// Re-save cookie
|
||||
if ( selected !== null ) {
|
||||
$.cookie( 'wikiEditor-' + context.instance + '-toolbar-section', selected, { expires: 30, path: '/' } );
|
||||
}
|
||||
var $link =
|
||||
const $link =
|
||||
$( '<a>' )
|
||||
.addClass( selected === id ? 'current' : null )
|
||||
.addClass( 'skin-invert' )
|
||||
|
@ -647,10 +660,10 @@ var toolbarModule = {
|
|||
$( elem ).attr( 'aria-pressed', 'false' );
|
||||
}
|
||||
} );
|
||||
var $sections = $( this ).data( 'context' ).$ui.find( '.sections' );
|
||||
var $section = $sections.find( '.section-' + $( this ).parent().attr( 'rel' ) );
|
||||
const $sections = $( this ).data( 'context' ).$ui.find( '.sections' );
|
||||
const $section = $sections.find( '.section-' + $( this ).parent().attr( 'rel' ) );
|
||||
// eslint-disable-next-line no-jquery/no-class-state
|
||||
var show = !$section.hasClass( 'section-visible' );
|
||||
const show = !$section.hasClass( 'section-visible' );
|
||||
$sections.find( '.section-visible' )
|
||||
.removeClass( 'section-visible' )
|
||||
.addClass( 'section-hidden' );
|
||||
|
@ -686,13 +699,13 @@ var toolbarModule = {
|
|||
.append( $link );
|
||||
},
|
||||
buildSection: function ( context, id, section ) {
|
||||
var $section = $( '<div>' ).attr( {
|
||||
const $section = $( '<div>' ).attr( {
|
||||
class: section.type + ' section section-' + id,
|
||||
rel: id,
|
||||
id: 'wikiEditor-section-' + id
|
||||
} );
|
||||
var selected = $.cookie( 'wikiEditor-' + context.instance + '-toolbar-section' );
|
||||
var show = selected === id;
|
||||
const selected = $.cookie( 'wikiEditor-' + context.instance + '-toolbar-section' );
|
||||
const show = selected === id;
|
||||
|
||||
toolbarModule.fn.reallyBuildSection( context, id, section, $section, section.deferLoad );
|
||||
|
||||
|
@ -707,29 +720,30 @@ var toolbarModule = {
|
|||
reallyBuildSection: function ( context, id, section, $section, deferLoad ) {
|
||||
context.$textarea.trigger( 'wikiEditor-toolbar-buildSection-' + $section.attr( 'rel' ), [ section ] );
|
||||
switch ( section.type ) {
|
||||
case 'toolbar':
|
||||
case 'toolbar': {
|
||||
if ( 'groups' in section ) {
|
||||
for ( var group in section.groups ) {
|
||||
for ( const group in section.groups ) {
|
||||
$section.append(
|
||||
toolbarModule.fn.buildGroup( context, group, section.groups[ group ] )
|
||||
);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'booklet':
|
||||
var $pages = $( '<div>' )
|
||||
}
|
||||
case 'booklet': {
|
||||
const $pages = $( '<div>' )
|
||||
.addClass( 'pages' )
|
||||
.attr( {
|
||||
tabindex: '0',
|
||||
role: 'listbox'
|
||||
} )
|
||||
.on( 'keydown', ( event ) => {
|
||||
var $selected = $pages.children().filter( function () {
|
||||
const $selected = $pages.children().filter( function () {
|
||||
return $( this ).css( 'display' ) !== 'none';
|
||||
} );
|
||||
$.wikiEditor.modules.toolbar.fn.handleKeyDown( $selected.children().first(), event, $pages );
|
||||
} );
|
||||
var $index = $( '<div>' )
|
||||
const $index = $( '<div>' )
|
||||
.addClass( 'index' )
|
||||
.attr( {
|
||||
tabindex: '0',
|
||||
|
@ -739,7 +753,7 @@ var toolbarModule = {
|
|||
$.wikiEditor.modules.toolbar.fn.handleKeyDown( $index, event, $index );
|
||||
} );
|
||||
if ( 'pages' in section ) {
|
||||
for ( var page in section.pages ) {
|
||||
for ( const page in section.pages ) {
|
||||
$pages.append(
|
||||
toolbarModule.fn.buildPage( context, page, section.pages[ page ], deferLoad )
|
||||
);
|
||||
|
@ -752,15 +766,16 @@ var toolbarModule = {
|
|||
toolbarModule.fn.updateBookletSelection( context, id, $pages, $index );
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
updateBookletSelection: function ( context, id, $pages, $index ) {
|
||||
var cookie = 'wikiEditor-' + context.instance + '-booklet-' + id + '-page',
|
||||
let cookie = 'wikiEditor-' + context.instance + '-booklet-' + id + '-page',
|
||||
selected = $.cookie( cookie );
|
||||
// Re-save cookie
|
||||
if ( selected !== null ) {
|
||||
$.cookie( cookie, selected, { expires: 30, path: '/' } );
|
||||
}
|
||||
var $selectedIndex = $index.find( '*[rel="' + selected + '"]' );
|
||||
let $selectedIndex = $index.find( '*[rel="' + selected + '"]' );
|
||||
if ( $selectedIndex.length === 0 ) {
|
||||
$selectedIndex = $index.children().eq( 0 );
|
||||
selected = $selectedIndex.attr( 'rel' );
|
||||
|
@ -771,10 +786,10 @@ var toolbarModule = {
|
|||
$selectedIndex.addClass( 'current' );
|
||||
},
|
||||
build: function ( context, config ) {
|
||||
var $tabs = $( '<div>' ).addClass( 'tabs' ).appendTo( context.modules.toolbar.$toolbar ),
|
||||
const $tabs = $( '<div>' ).addClass( 'tabs' ).appendTo( context.modules.toolbar.$toolbar ),
|
||||
$sections = $( '<div>' ).addClass( 'sections' ).appendTo( context.modules.toolbar.$toolbar );
|
||||
context.modules.toolbar.$toolbar.append( $( '<div>' ).css( 'clear', 'both' ) );
|
||||
for ( var section in config ) {
|
||||
for ( const section in config ) {
|
||||
if ( section === 'main' || section === 'secondary' ) {
|
||||
context.modules.toolbar.$toolbar.prepend(
|
||||
toolbarModule.fn.buildSection( context, section, config[ section ] )
|
||||
|
@ -793,13 +808,13 @@ var toolbarModule = {
|
|||
},
|
||||
ctrlShortcuts: {},
|
||||
setupShortcuts: function ( context ) {
|
||||
var platform = $.client.profile().platform;
|
||||
var platformModifier = platform === 'mac' ? 'metaKey' : 'ctrlKey';
|
||||
var otherModifier = platform === 'mac' ? 'ctrlKey' : 'metaKey';
|
||||
const platform = $.client.profile().platform;
|
||||
const platformModifier = platform === 'mac' ? 'metaKey' : 'ctrlKey';
|
||||
const otherModifier = platform === 'mac' ? 'ctrlKey' : 'metaKey';
|
||||
|
||||
context.$textarea.on( 'keydown', ( e ) => {
|
||||
// Check if the primary modifier key is pressed and that others aren't
|
||||
var target = e[ platformModifier ] && !e[ otherModifier ] && !e.altKey && !e.shiftKey &&
|
||||
const target = e[ platformModifier ] && !e[ otherModifier ] && !e.altKey && !e.shiftKey &&
|
||||
toolbarModule.fn.ctrlShortcuts[ e.which ];
|
||||
if ( target ) {
|
||||
e.preventDefault();
|
||||
|
@ -808,12 +823,12 @@ var toolbarModule = {
|
|||
} );
|
||||
},
|
||||
handleKeyDown: function ( $element, event, $parent ) {
|
||||
var $currentItem = $element.find( '.wikiEditor-character-highlighted' ),
|
||||
const $currentItem = $element.find( '.wikiEditor-character-highlighted' ),
|
||||
optionOffset = $parent.find( '.wikiEditor-character-highlighted' ).offset(),
|
||||
optionTop = optionOffset ? optionOffset.top : 0,
|
||||
selectTop = $parent.offset().top;
|
||||
|
||||
var $nextItem;
|
||||
let $nextItem;
|
||||
switch ( event.keyCode ) {
|
||||
// Up arrow
|
||||
case 38:
|
||||
|
|
|
@ -10,8 +10,8 @@ function ErrorLayout( config ) {
|
|||
config = config || {};
|
||||
ErrorLayout.super.call( this, config );
|
||||
|
||||
var $image = $( '<div>' ).addClass( 'ext-WikiEditor-image-realtimepreview-error' );
|
||||
var $title = $( '<h3>' ).text( mw.msg( 'wikieditor-realtimepreview-error' ) );
|
||||
const $image = $( '<div>' ).addClass( 'ext-WikiEditor-image-realtimepreview-error' );
|
||||
const $title = $( '<h3>' ).text( mw.msg( 'wikieditor-realtimepreview-error' ) );
|
||||
this.$message = $( '<div>' ).addClass( 'ext-WikiEditor-realtimepreview-error-msg' );
|
||||
this.reloadButton = new OO.ui.ButtonWidget( {
|
||||
icon: 'reload',
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* @param {OO.ui.ButtonWidget} reloadHoverButton
|
||||
*/
|
||||
function ManualWidget( realtimePreview, reloadHoverButton ) {
|
||||
var config = {
|
||||
const config = {
|
||||
classes: [ 'ext-WikiEditor-ManualWidget' ],
|
||||
$element: $( '<a>' )
|
||||
};
|
||||
|
@ -25,9 +25,9 @@ function ManualWidget( realtimePreview, reloadHoverButton ) {
|
|||
this.reloadHoverButton = reloadHoverButton;
|
||||
|
||||
// UI elements.
|
||||
var $reloadLabel = $( '<span>' )
|
||||
const $reloadLabel = $( '<span>' )
|
||||
.text( mw.msg( 'wikieditor-realtimepreview-manual' ) );
|
||||
var $reloadButton = $( '<span>' )
|
||||
const $reloadButton = $( '<span>' )
|
||||
.addClass( 'ext-WikiEditor-realtimepreview-manual-reload' )
|
||||
.text( mw.msg( 'wikieditor-realtimepreview-reload' ) );
|
||||
this.connect( realtimePreview, {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
var ResizingDragBar = require( './ResizingDragBar.js' );
|
||||
var TwoPaneLayout = require( './TwoPaneLayout.js' );
|
||||
var ErrorLayout = require( './ErrorLayout.js' );
|
||||
var ManualWidget = require( './ManualWidget.js' );
|
||||
var localStorage = require( 'mediawiki.storage' ).local;
|
||||
const ResizingDragBar = require( './ResizingDragBar.js' );
|
||||
const TwoPaneLayout = require( './TwoPaneLayout.js' );
|
||||
const ErrorLayout = require( './ErrorLayout.js' );
|
||||
const ManualWidget = require( './ManualWidget.js' );
|
||||
const localStorage = require( 'mediawiki.storage' ).local;
|
||||
|
||||
/**
|
||||
* @class
|
||||
|
@ -18,7 +18,7 @@ function RealtimePreview() {
|
|||
// @todo This shouldn't be required, but the preview element is added in PHP
|
||||
// and can have attributes with values (such as `dir`) that aren't easily accessible from here,
|
||||
// and we need to duplicate here what Live Preview does in core.
|
||||
var $previewContent = $( '#wikiPreview .mw-content-ltr, #wikiPreview .mw-content-rtl' ).first().clone();
|
||||
const $previewContent = $( '#wikiPreview .mw-content-ltr, #wikiPreview .mw-content-rtl' ).first().clone();
|
||||
this.$previewNode = $( '<div>' )
|
||||
.addClass( 'ext-WikiEditor-realtimepreview-preview' )
|
||||
.attr( 'tabindex', '1' ) // T317108
|
||||
|
@ -80,16 +80,16 @@ function RealtimePreview() {
|
|||
*/
|
||||
RealtimePreview.prototype.getToolbarButton = function ( context ) {
|
||||
this.context = context;
|
||||
var $uiText = context.$ui.find( '.wikiEditor-ui-text' );
|
||||
const $uiText = context.$ui.find( '.wikiEditor-ui-text' );
|
||||
|
||||
// Fix the height of the textarea, before adding a resizing bar below it.
|
||||
var height = context.$textarea.height();
|
||||
const height = context.$textarea.height();
|
||||
$uiText.css( 'height', height + 'px' );
|
||||
context.$textarea.removeAttr( 'rows cols' );
|
||||
context.$textarea.addClass( 'ext-WikiEditor-realtimepreview-textbox' );
|
||||
|
||||
// Add the resizing bar.
|
||||
var bottomDragBar = new ResizingDragBar( { isEW: false } );
|
||||
const bottomDragBar = new ResizingDragBar( { isEW: false } );
|
||||
$uiText.after( bottomDragBar.$element );
|
||||
|
||||
// Create and configure the toolbar button.
|
||||
|
@ -156,13 +156,13 @@ RealtimePreview.prototype.saveUserPref = function () {
|
|||
* @private
|
||||
*/
|
||||
RealtimePreview.prototype.toggle = function ( saveUserPref ) {
|
||||
var $uiText = this.context.$ui.find( '.wikiEditor-ui-text' );
|
||||
var $textarea = this.context.$textarea;
|
||||
var $form = $textarea.parents( 'form' );
|
||||
const $uiText = this.context.$ui.find( '.wikiEditor-ui-text' );
|
||||
const $textarea = this.context.$textarea;
|
||||
const $form = $textarea.parents( 'form' );
|
||||
|
||||
// Save the current cursor selection and focused element.
|
||||
var cursorPos = $textarea.textSelection( 'getCaretPosition', { startAndEnd: true } );
|
||||
var focusedElement = document.activeElement;
|
||||
const cursorPos = $textarea.textSelection( 'getCaretPosition', { startAndEnd: true } );
|
||||
const focusedElement = document.activeElement;
|
||||
|
||||
// Remove or add the layout to the DOM.
|
||||
if ( this.enabled ) {
|
||||
|
@ -254,8 +254,8 @@ RealtimePreview.prototype.isScreenWideEnough = function () {
|
|||
* @private
|
||||
*/
|
||||
RealtimePreview.prototype.enableFeatureWhenScreenIsWideEnough = function () {
|
||||
var previewButtonIsVisible = this.button.isVisible();
|
||||
var isScreenWideEnough = this.isScreenWideEnough();
|
||||
const previewButtonIsVisible = this.button.isVisible();
|
||||
const isScreenWideEnough = this.isScreenWideEnough();
|
||||
if ( !isScreenWideEnough && previewButtonIsVisible ) {
|
||||
this.button.toggle( false );
|
||||
this.reloadButton.setDisabled( true );
|
||||
|
@ -301,7 +301,7 @@ RealtimePreview.prototype.checkResponseTimes = function ( time ) {
|
|||
return;
|
||||
}
|
||||
|
||||
var totalResponseTime = this.responseTimes.reduce( ( a, b ) => a + b, 0 );
|
||||
const totalResponseTime = this.responseTimes.reduce( ( a, b ) => a + b, 0 );
|
||||
|
||||
if ( ( totalResponseTime / this.responseTimes.length ) > this.configData.realtimeDisableDuration ) {
|
||||
this.inManualMode = true;
|
||||
|
@ -325,8 +325,8 @@ RealtimePreview.prototype.doRealtimePreview = function ( forceUpdate ) {
|
|||
return;
|
||||
}
|
||||
|
||||
var $textareaNode = $( '#wpTextbox1' );
|
||||
var wikitext = $textareaNode.textSelection( 'getContents' );
|
||||
const $textareaNode = $( '#wpTextbox1' );
|
||||
const wikitext = $textareaNode.textSelection( 'getContents' );
|
||||
if ( !forceUpdate && wikitext === this.lastWikitext ) {
|
||||
// Wikitext unchanged, no update necessary
|
||||
return;
|
||||
|
@ -339,14 +339,14 @@ RealtimePreview.prototype.doRealtimePreview = function ( forceUpdate ) {
|
|||
this.reloadButton.setDisabled( true );
|
||||
this.manualWidget.setDisabled( true );
|
||||
this.errorLayout.toggle( false );
|
||||
var loadingSelectors = this.pagePreview.getLoadingSelectors()
|
||||
const loadingSelectors = this.pagePreview.getLoadingSelectors()
|
||||
// config.$previewNode below is a clone of #wikiPreview with a different selector!
|
||||
// config.$diffNode defaults to #wikiDiff but is disabled below and never updated.
|
||||
.filter( ( selector ) => selector.indexOf( '#wiki' ) !== 0 );
|
||||
loadingSelectors.push( '.ext-WikiEditor-realtimepreview-preview' );
|
||||
loadingSelectors.push( '.ext-WikiEditor-ManualWidget' );
|
||||
loadingSelectors.push( '.ext-WikiEditor-realtimepreview-ErrorLayout' );
|
||||
var time = Date.now();
|
||||
const time = Date.now();
|
||||
|
||||
this.pagePreview.doPreview( {
|
||||
$textareaNode: $textareaNode,
|
||||
|
|
|
@ -12,15 +12,15 @@ function ResizingDragBar( config ) {
|
|||
}, config );
|
||||
ResizingDragBar.super.call( this, config );
|
||||
|
||||
var classNameDir = 'ext-WikiEditor-ResizingDragBar-' + ( config.isEW ? 'ew' : 'ns' );
|
||||
const classNameDir = 'ext-WikiEditor-ResizingDragBar-' + ( config.isEW ? 'ew' : 'ns' );
|
||||
// Possible class names:
|
||||
// * ext-WikiEditor-ResizingDragBar-ew
|
||||
// * ext-WikiEditor-ResizingDragBar-ns
|
||||
this.$element.addClass( classNameDir );
|
||||
|
||||
var resizingDragBar = this;
|
||||
const resizingDragBar = this;
|
||||
// Determine the horizontal direction to move (flexbox automatically reverses but the offset direction doesn't).
|
||||
var rtlFactor = config.isEW && OO.ui.Element.static.getDir( document ) === 'rtl' ? -1 : 1;
|
||||
const rtlFactor = config.isEW && OO.ui.Element.static.getDir( document ) === 'rtl' ? -1 : 1;
|
||||
this.$element.on( 'mousedown', ( eventMousedown ) => {
|
||||
if ( eventMousedown.button !== ResizingDragBar.static.MAIN_MOUSE_BUTTON ) {
|
||||
// If not the main mouse (e.g. left) button, ignore.
|
||||
|
@ -29,19 +29,19 @@ function ResizingDragBar( config ) {
|
|||
// Prevent selecting (or anything else) when dragging over other parts of the page.
|
||||
$( document ).on( 'selectstart.' + classNameDir, false );
|
||||
// Set up parameter names.
|
||||
var xOrY = config.isEW ? 'pageX' : 'pageY';
|
||||
var widthOrHeight = config.isEW ? 'width' : 'height';
|
||||
var lastOffset = eventMousedown[ xOrY ];
|
||||
const xOrY = config.isEW ? 'pageX' : 'pageY';
|
||||
const widthOrHeight = config.isEW ? 'width' : 'height';
|
||||
let lastOffset = eventMousedown[ xOrY ];
|
||||
// Handle the actual dragging.
|
||||
$( document ).on( 'mousemove.' + classNameDir, ( eventMousemove ) => {
|
||||
// Initial width or height of the pane.
|
||||
var startSize = resizingDragBar.getResizedPane()[ widthOrHeight ]();
|
||||
const startSize = resizingDragBar.getResizedPane()[ widthOrHeight ]();
|
||||
// Current position of the mouse (relative to page, not viewport).
|
||||
var newOffset = eventMousemove[ xOrY ];
|
||||
const newOffset = eventMousemove[ xOrY ];
|
||||
// Distance the mouse has moved.
|
||||
var change = rtlFactor * ( lastOffset - newOffset );
|
||||
const change = rtlFactor * ( lastOffset - newOffset );
|
||||
// Set the new size of the pane, and tell others about it.
|
||||
var newSize = Math.max( startSize - change, ResizingDragBar.static.MIN_PANE_SIZE );
|
||||
const newSize = Math.max( startSize - change, ResizingDragBar.static.MIN_PANE_SIZE );
|
||||
resizingDragBar.getResizedPane().css( widthOrHeight, newSize );
|
||||
// Save the new starting point of the mouse, from which to calculate the next move.
|
||||
lastOffset = newOffset;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var ResizingDragBar = require( './ResizingDragBar.js' );
|
||||
const ResizingDragBar = require( './ResizingDragBar.js' );
|
||||
|
||||
/**
|
||||
* This is a layout with two resizable panes.
|
||||
|
@ -14,7 +14,7 @@ function TwoPaneLayout( config ) {
|
|||
TwoPaneLayout.super.call( this, config );
|
||||
|
||||
this.$pane1 = $( '<div>' ).addClass( 'ext-WikiEditor-twopanes-pane1' );
|
||||
var middleDragBar = new ResizingDragBar( { isEW: true } );
|
||||
const middleDragBar = new ResizingDragBar( { isEW: true } );
|
||||
this.$pane2 = $( '<div>' ).addClass( 'ext-WikiEditor-twopanes-pane2' );
|
||||
|
||||
this.$element.addClass( 'ext-WikiEditor-twopanes-TwoPaneLayout' );
|
||||
|
|
|
@ -6,8 +6,8 @@ mw.hook( 'wikiEditor.toolbarReady' ).add( function ( $textarea ) {
|
|||
return;
|
||||
}
|
||||
|
||||
var RealtimePreview = require( './RealtimePreview.js' );
|
||||
var realtimePreview = new RealtimePreview();
|
||||
const RealtimePreview = require( './RealtimePreview.js' );
|
||||
const realtimePreview = new RealtimePreview();
|
||||
$textarea.wikiEditor( 'addToToolbar', {
|
||||
section: 'secondary',
|
||||
group: 'default',
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
QUnit.module( 'ext.wikiEditor.toolbar', ( hooks ) => {
|
||||
hooks.beforeEach( function () {
|
||||
var $target = $( '<textarea>' )
|
||||
const $target = $( '<textarea>' )
|
||||
.attr( 'id', 'wpTextBox1' )
|
||||
.appendTo( '#qunit-fixture' );
|
||||
this.$target = $target;
|
||||
|
@ -10,7 +10,7 @@ QUnit.module( 'ext.wikiEditor.toolbar', ( hooks ) => {
|
|||
|
||||
QUnit.test( 'Toolbars', function ( assert ) {
|
||||
// Add toolbar section
|
||||
var data = {
|
||||
let data = {
|
||||
sections: {
|
||||
emoticons: {
|
||||
type: 'toolbar',
|
||||
|
@ -141,7 +141,7 @@ QUnit.module( 'ext.wikiEditor.toolbar', ( hooks ) => {
|
|||
|
||||
QUnit.test( 'Booklets', function ( assert ) {
|
||||
// Add booklet section
|
||||
var data = {
|
||||
let data = {
|
||||
sections: {
|
||||
info: {
|
||||
type: 'booklet',
|
||||
|
|
Loading…
Reference in a new issue