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": {
|
"rules": {
|
||||||
"max-len": "off",
|
"max-len": "off",
|
||||||
"no-jquery/no-global-selector": "off",
|
"no-jquery/no-global-selector": "off",
|
||||||
"no-var": "off"
|
"prefer-const": "warn"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* @module module:ext.wikiEditor
|
* @module module:ext.wikiEditor
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var editingSessionId;
|
let editingSessionId;
|
||||||
|
|
||||||
// This sets $.wikiEditor and $.fn.wikiEditor
|
// This sets $.wikiEditor and $.fn.wikiEditor
|
||||||
require( './jquery.wikiEditor.js' );
|
require( './jquery.wikiEditor.js' );
|
||||||
|
@ -48,7 +48,7 @@ function logAbort( switchingToVE, unmodified ) {
|
||||||
logEditFeature( 'editor-switch', 'visual-desktop' );
|
logEditFeature( 'editor-switch', 'visual-desktop' );
|
||||||
}
|
}
|
||||||
|
|
||||||
var abortType;
|
let abortType;
|
||||||
if ( switchingToVE && unmodified ) {
|
if ( switchingToVE && unmodified ) {
|
||||||
abortType = 'switchnochange';
|
abortType = 'switchnochange';
|
||||||
} else if ( switchingToVE ) {
|
} else if ( switchingToVE ) {
|
||||||
|
@ -66,7 +66,7 @@ function logAbort( switchingToVE, unmodified ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$( () => {
|
$( () => {
|
||||||
var $textarea = $( '#wpTextbox1' ),
|
const $textarea = $( '#wpTextbox1' ),
|
||||||
$editingSessionIdInput = $( '#editingStatsId' ),
|
$editingSessionIdInput = $( '#editingStatsId' ),
|
||||||
origText = $textarea.val();
|
origText = $textarea.val();
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ $( () => {
|
||||||
// fall back to the timestamp when the page loaded for those
|
// fall back to the timestamp when the page loaded for those
|
||||||
// that don't, we just ignore them, so as to not skew the
|
// that don't, we just ignore them, so as to not skew the
|
||||||
// results towards better-performance in those cases.
|
// results towards better-performance in those cases.
|
||||||
var readyTime = Date.now();
|
const readyTime = Date.now();
|
||||||
logEditEvent( {
|
logEditEvent( {
|
||||||
action: 'ready',
|
action: 'ready',
|
||||||
timing: readyTime - window.performance.timing.navigationStart
|
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' ) ) {
|
if ( mw.user.options.get( 'uselivepreview' ) ) {
|
||||||
$form.find( '#wpPreview' ).on( 'click', () => {
|
$form.find( '#wpPreview' ).on( 'click', () => {
|
||||||
logEditFeature( 'preview', 'preview-live' );
|
logEditFeature( 'preview', 'preview-live' );
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
var submitting;
|
let submitting;
|
||||||
$form.on( 'submit', () => {
|
$form.on( 'submit', () => {
|
||||||
submitting = true;
|
submitting = true;
|
||||||
} );
|
} );
|
||||||
var onUnloadFallback = window.onunload;
|
const onUnloadFallback = window.onunload;
|
||||||
|
|
||||||
window.onunload = function () {
|
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 ],
|
caVeEdit = $( '#ca-ve-edit' )[ 0 ],
|
||||||
switchingToVE = caVeEdit && (
|
switchingToVE = caVeEdit && (
|
||||||
document.activeElement === caVeEdit ||
|
document.activeElement === caVeEdit ||
|
||||||
$.contains( caVeEdit, document.activeElement )
|
$.contains( caVeEdit, document.activeElement )
|
||||||
);
|
);
|
||||||
|
|
||||||
var fallbackResult;
|
let fallbackResult;
|
||||||
if ( onUnloadFallback ) {
|
if ( onUnloadFallback ) {
|
||||||
fallbackResult = onUnloadFallback();
|
fallbackResult = onUnloadFallback();
|
||||||
}
|
}
|
||||||
|
@ -141,7 +141,7 @@ $( () => {
|
||||||
return fallbackResult;
|
return fallbackResult;
|
||||||
};
|
};
|
||||||
$textarea.on( 'wikiEditor-switching-visualeditor', () => {
|
$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
|
// A non-navigation switch to VE has occurred. As such, avoid eventually
|
||||||
// double-logging an abort when VE is done.
|
// double-logging an abort when VE is done.
|
||||||
window.onunload = onUnloadFallback;
|
window.onunload = onUnloadFallback;
|
||||||
|
@ -192,7 +192,7 @@ mw.addWikiEditor = function ( $textarea ) {
|
||||||
'addModule', require( './jquery.wikiEditor.toolbar.config.js' )
|
'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
|
// Replace icons
|
||||||
dialogsConfig.replaceIcons( $textarea );
|
dialogsConfig.replaceIcons( $textarea );
|
||||||
// Add dialogs module
|
// Add dialogs module
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function LinkTextField() {
|
function LinkTextField() {
|
||||||
var input = new OO.ui.TextInputWidget( {
|
const input = new OO.ui.TextInputWidget( {
|
||||||
placeholder: mw.msg( 'wikieditor-toolbar-tool-link-int-text-tooltip' )
|
placeholder: mw.msg( 'wikieditor-toolbar-tool-link-int-text-tooltip' )
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ function LinkTextField() {
|
||||||
change: 'onInputChange'
|
change: 'onInputChange'
|
||||||
} );
|
} );
|
||||||
|
|
||||||
var config = {
|
const config = {
|
||||||
align: 'top',
|
align: 'top',
|
||||||
label: mw.msg( 'wikieditor-toolbar-tool-link-int-text' ),
|
label: mw.msg( 'wikieditor-toolbar-tool-link-int-text' ),
|
||||||
classes: [ 'mw-wikiEditor-InsertLink-LinkTextField' ]
|
classes: [ 'mw-wikiEditor-InsertLink-LinkTextField' ]
|
||||||
|
|
|
@ -14,7 +14,7 @@ function LinkTypeField() {
|
||||||
this.radioExt = new OO.ui.RadioOptionWidget( {
|
this.radioExt = new OO.ui.RadioOptionWidget( {
|
||||||
label: mw.msg( 'wikieditor-toolbar-tool-link-ext' )
|
label: mw.msg( 'wikieditor-toolbar-tool-link-ext' )
|
||||||
} );
|
} );
|
||||||
var radioSelect = new OO.ui.RadioSelectWidget( {
|
const radioSelect = new OO.ui.RadioSelectWidget( {
|
||||||
items: [
|
items: [
|
||||||
this.radioInt,
|
this.radioInt,
|
||||||
this.radioExt
|
this.radioExt
|
||||||
|
@ -24,7 +24,7 @@ function LinkTypeField() {
|
||||||
choose: this.onRadioChoose
|
choose: this.onRadioChoose
|
||||||
} );
|
} );
|
||||||
|
|
||||||
var config = {
|
const config = {
|
||||||
align: 'top',
|
align: 'top',
|
||||||
classes: [ 'mw-wikiEditor-InsertLink-LinkTypeField' ]
|
classes: [ 'mw-wikiEditor-InsertLink-LinkTypeField' ]
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
var LinkTypeField = require( './LinkTypeField.js' );
|
const LinkTypeField = require( './LinkTypeField.js' );
|
||||||
var TitleInputWidget = require( './TitleInputWidget.js' );
|
const TitleInputWidget = require( './TitleInputWidget.js' );
|
||||||
/* global InsertLinkTitleOptionWidget */
|
/* global InsertLinkTitleOptionWidget */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -14,7 +14,7 @@ function TitleInputField() {
|
||||||
// Mixin constructor
|
// Mixin constructor
|
||||||
OO.EventEmitter.call( this );
|
OO.EventEmitter.call( this );
|
||||||
|
|
||||||
var input = new TitleInputWidget();
|
const input = new TitleInputWidget();
|
||||||
input.connect( this, {
|
input.connect( this, {
|
||||||
change: this.onChange,
|
change: this.onChange,
|
||||||
select: this.onSelect
|
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.
|
// The 'manual' URL mode flag is set when the user changes the mode, and doesn't change again.
|
||||||
this.urlModeManual = false;
|
this.urlModeManual = false;
|
||||||
|
|
||||||
var config = {
|
const config = {
|
||||||
align: 'top',
|
align: 'top',
|
||||||
label: mw.msg( 'wikieditor-toolbar-tool-link-int-target' ),
|
label: mw.msg( 'wikieditor-toolbar-tool-link-int-target' ),
|
||||||
classes: [ 'mw-wikiEditor-InsertLink-TitleInputField' ]
|
classes: [ 'mw-wikiEditor-InsertLink-TitleInputField' ]
|
||||||
|
@ -131,7 +131,7 @@ TitleInputField.prototype.validate = function ( value ) {
|
||||||
* @param {InsertLinkTitleOptionWidget} item
|
* @param {InsertLinkTitleOptionWidget} item
|
||||||
*/
|
*/
|
||||||
TitleInputField.prototype.onSelect = function ( item ) {
|
TitleInputField.prototype.onSelect = function ( item ) {
|
||||||
var icon, msg;
|
let icon, msg;
|
||||||
if ( this.urlMode === LinkTypeField.static.LINK_MODE_EXTERNAL ||
|
if ( this.urlMode === LinkTypeField.static.LINK_MODE_EXTERNAL ||
|
||||||
( !this.urlModeManual && this.urlMode === LinkTypeField.static.LINK_MODE_INTERNAL && item.isExternal() )
|
( !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
|
* A custom TitleInputWidget that adds support for external links
|
||||||
|
@ -50,13 +50,13 @@ TitleInputWidget.prototype.onLookupInputBlur = function () {
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
TitleInputWidget.prototype.selectFirstMatch = function () {
|
TitleInputWidget.prototype.selectFirstMatch = function () {
|
||||||
var that = this;
|
const that = this;
|
||||||
this.getLookupMenuItems().done( ( items ) => {
|
this.getLookupMenuItems().done( ( items ) => {
|
||||||
// The matching item is not always the first,
|
// The matching item is not always the first,
|
||||||
// because disambiguation pages are moved to the end.
|
// because disambiguation pages are moved to the end.
|
||||||
for ( var i = 0; i < items.length; i++ ) {
|
for ( let i = 0; i < items.length; i++ ) {
|
||||||
var item = items[ i ];
|
const item = items[ i ];
|
||||||
var queryVal = that.getQueryValue();
|
const queryVal = that.getQueryValue();
|
||||||
// Check for exact match, or a match with uppercase first character.
|
// Check for exact match, or a match with uppercase first character.
|
||||||
if ( item.getData() === queryVal ||
|
if ( item.getData() === queryVal ||
|
||||||
item.getData() === queryVal.charAt( 0 ).toUpperCase() + queryVal.slice( 1 )
|
item.getData() === queryVal.charAt( 0 ).toUpperCase() + queryVal.slice( 1 )
|
||||||
|
@ -78,7 +78,7 @@ TitleInputWidget.prototype.selectFirstMatch = function () {
|
||||||
* @return {Object} Data for option widget
|
* @return {Object} Data for option widget
|
||||||
*/
|
*/
|
||||||
TitleInputWidget.prototype.getOptionWidgetData = function ( title, data ) {
|
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;
|
widgetData.external = data.originalData.external;
|
||||||
return widgetData;
|
return widgetData;
|
||||||
};
|
};
|
||||||
|
@ -101,14 +101,14 @@ TitleInputWidget.prototype.createOptionWidget = function ( data ) {
|
||||||
* @return {Object}
|
* @return {Object}
|
||||||
*/
|
*/
|
||||||
TitleInputWidget.prototype.getLookupCacheDataFromResponse = function ( response ) {
|
TitleInputWidget.prototype.getLookupCacheDataFromResponse = function ( response ) {
|
||||||
var res = TitleInputWidget.super.prototype.getLookupCacheDataFromResponse( response );
|
const res = TitleInputWidget.super.prototype.getLookupCacheDataFromResponse( response );
|
||||||
// Guard against zero responses.
|
// Guard against zero responses.
|
||||||
if ( res.pages === undefined ) {
|
if ( res.pages === undefined ) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
for ( var pageId in res.pages ) {
|
for ( const pageId in res.pages ) {
|
||||||
if ( Object.prototype.hasOwnProperty.call( res.pages, pageId ) ) {
|
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 );
|
page.external = page.missing !== undefined && this.looksLikeExternalLink( page.title );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
var toolbarModule = require( './jquery.wikiEditor.toolbar.js' ),
|
const toolbarModule = require( './jquery.wikiEditor.toolbar.js' ),
|
||||||
InsertLinkTitleInputField = require( './insertlink/TitleInputField.js' ),
|
InsertLinkTitleInputField = require( './insertlink/TitleInputField.js' ),
|
||||||
LinkTextField = require( './insertlink/LinkTextField.js' ),
|
LinkTextField = require( './insertlink/LinkTextField.js' ),
|
||||||
LinkTypeField = require( './insertlink/LinkTypeField.js' ),
|
LinkTypeField = require( './insertlink/LinkTypeField.js' ),
|
||||||
|
@ -14,8 +14,8 @@ var toolbarModule = require( './jquery.wikiEditor.toolbar.js' ),
|
||||||
|
|
||||||
function triggerButtonClick( element ) {
|
function triggerButtonClick( element ) {
|
||||||
// The dialog action should always be a DOMElement.
|
// The dialog action should always be a DOMElement.
|
||||||
var dialogAction = $( element ).data( 'dialogaction' );
|
const dialogAction = $( element ).data( 'dialogaction' );
|
||||||
var $button = dialogAction ? $( dialogAction ) : $( element ).find( 'button' ).first();
|
const $button = dialogAction ? $( dialogAction ) : $( element ).find( 'button' ).first();
|
||||||
// Since we're reading from data attribute, make sure we got an element before clicking.
|
// 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
|
// Note when closing a dialog this can be false leading to TypeError: $button.trigger is not a function
|
||||||
// (T261529)
|
// (T261529)
|
||||||
|
@ -114,7 +114,7 @@ module.exports = {
|
||||||
*
|
*
|
||||||
* @param {boolean} enable Whether to enable or disable the button
|
* @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 );
|
$( '.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
|
// 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.
|
// Tell the title input field when the internal/external radio changes.
|
||||||
insertLinkLinkTypeField.connect( this, {
|
insertLinkLinkTypeField.connect( this, {
|
||||||
change: function ( isExternal ) {
|
change: function ( isExternal ) {
|
||||||
var urlMode = isExternal ?
|
const urlMode = isExternal ?
|
||||||
LinkTypeField.static.LINK_MODE_EXTERNAL :
|
LinkTypeField.static.LINK_MODE_EXTERNAL :
|
||||||
LinkTypeField.static.LINK_MODE_INTERNAL;
|
LinkTypeField.static.LINK_MODE_INTERNAL;
|
||||||
insertLinkTitleInputField.setUrlMode( urlMode );
|
insertLinkTitleInputField.setUrlMode( urlMode );
|
||||||
|
@ -148,7 +148,7 @@ module.exports = {
|
||||||
class: 'wikieditor-toolbar-tool-link-insert',
|
class: 'wikieditor-toolbar-tool-link-insert',
|
||||||
text: mw.msg( 'wikieditor-toolbar-tool-link-insert' ),
|
text: mw.msg( 'wikieditor-toolbar-tool-link-insert' ),
|
||||||
click: function () {
|
click: function () {
|
||||||
var that = this;
|
const that = this;
|
||||||
|
|
||||||
function escapeInternalText( s ) {
|
function escapeInternalText( s ) {
|
||||||
return s.replace( /(\]{2,})/g, '<nowiki>$1</nowiki>' );
|
return s.replace( /(\]{2,})/g, '<nowiki>$1</nowiki>' );
|
||||||
|
@ -167,14 +167,14 @@ module.exports = {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var target = insertLinkTitleInputField.getField().getValue();
|
let target = insertLinkTitleInputField.getField().getValue();
|
||||||
var text = insertLinkLinkTextField.getField().getValue();
|
let text = insertLinkLinkTextField.getField().getValue();
|
||||||
if ( text.trim() === '' ) {
|
if ( text.trim() === '' ) {
|
||||||
// [[Foo| ]] creates an invisible link
|
// [[Foo| ]] creates an invisible link
|
||||||
// Instead, generate [[Foo|]]
|
// Instead, generate [[Foo|]]
|
||||||
text = '';
|
text = '';
|
||||||
}
|
}
|
||||||
var insertText = '';
|
let insertText = '';
|
||||||
if ( insertLinkLinkTypeField.isInternal() ) {
|
if ( insertLinkLinkTypeField.isInternal() ) {
|
||||||
if ( target === text || !text.length ) {
|
if ( target === text || !text.length ) {
|
||||||
insertText = '[[' + target + ']]';
|
insertText = '[[' + target + ']]';
|
||||||
|
@ -189,12 +189,12 @@ module.exports = {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Detect if this is really an internal link in disguise
|
// 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' ) ) {
|
if ( match && !$( this ).data( 'ignoreLooksInternal' ) ) {
|
||||||
var buttons = {};
|
const buttons = {};
|
||||||
buttons[ mw.msg( 'wikieditor-toolbar-tool-link-lookslikeinternal-int' ) ] =
|
buttons[ mw.msg( 'wikieditor-toolbar-tool-link-lookslikeinternal-int' ) ] =
|
||||||
function () {
|
function () {
|
||||||
var titleValue = match[ 1 ];
|
let titleValue = match[ 1 ];
|
||||||
try {
|
try {
|
||||||
titleValue = decodeURI( titleValue );
|
titleValue = decodeURI( titleValue );
|
||||||
} catch ( ex ) {
|
} catch ( ex ) {
|
||||||
|
@ -221,8 +221,8 @@ module.exports = {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var escTarget = escapeExternalTarget( target );
|
const escTarget = escapeExternalTarget( target );
|
||||||
var escText = escapeExternalText( text );
|
const escText = escapeExternalText( text );
|
||||||
|
|
||||||
if ( escTarget === escText ) {
|
if ( escTarget === escText ) {
|
||||||
insertText = escTarget;
|
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
|
// Preserve whitespace in selection when replacing
|
||||||
if ( whitespace ) {
|
if ( whitespace ) {
|
||||||
insertText = whitespace[ 0 ] + insertText + whitespace[ 1 ];
|
insertText = whitespace[ 0 ] + insertText + whitespace[ 1 ];
|
||||||
|
@ -259,7 +259,7 @@ module.exports = {
|
||||||
open: function () {
|
open: function () {
|
||||||
// Obtain the server name without the protocol. wgServer may be protocol-relative
|
// 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
|
// Cache the articlepath regex
|
||||||
|
|
||||||
$( this ).data( 'articlePathRegex', new RegExp(
|
$( this ).data( 'articlePathRegex', new RegExp(
|
||||||
|
@ -267,8 +267,8 @@ module.exports = {
|
||||||
.replace( /\\\$1/g, '(.*)' ) + '$'
|
.replace( /\\\$1/g, '(.*)' ) + '$'
|
||||||
) );
|
) );
|
||||||
// Pre-fill the text fields based on the current selection
|
// Pre-fill the text fields based on the current selection
|
||||||
var context = $( this ).data( 'context' );
|
const context = $( this ).data( 'context' );
|
||||||
var selection = context.$textarea.textSelection( 'getSelection' );
|
const selection = context.$textarea.textSelection( 'getSelection' );
|
||||||
|
|
||||||
insertLinkTitleInputField.getField().focus();
|
insertLinkTitleInputField.getField().focus();
|
||||||
// Trigger the change event, so the link status indicator is up to date.
|
// 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', [ '', '' ] );
|
$( '#wikieditor-toolbar-link-dialog' ).data( 'whitespace', [ '', '' ] );
|
||||||
if ( selection !== '' ) {
|
if ( selection !== '' ) {
|
||||||
var matches, target, text, isExternal;
|
let matches, target, text, isExternal;
|
||||||
if ( ( matches = selection.match( /^(\s*)\[\[([^\]|]+)(\|([^\]|]*))?\]\](\s*)$/ ) ) ) {
|
if ( ( matches = selection.match( /^(\s*)\[\[([^\]|]+)(\|([^\]|]*))?\]\](\s*)$/ ) ) ) {
|
||||||
// [[foo|bar]] or [[foo]]
|
// [[foo|bar]] or [[foo]]
|
||||||
target = matches[ 2 ];
|
target = matches[ 2 ];
|
||||||
|
@ -315,7 +315,7 @@ module.exports = {
|
||||||
insertLinkLinkTextField.setTouched( true );
|
insertLinkLinkTextField.setTouched( true );
|
||||||
|
|
||||||
if ( typeof isExternal !== 'undefined' ) {
|
if ( typeof isExternal !== 'undefined' ) {
|
||||||
var urlMode = isExternal ?
|
const urlMode = isExternal ?
|
||||||
LinkTypeField.static.LINK_MODE_EXTERNAL :
|
LinkTypeField.static.LINK_MODE_EXTERNAL :
|
||||||
LinkTypeField.static.LINK_MODE_INTERNAL;
|
LinkTypeField.static.LINK_MODE_INTERNAL;
|
||||||
insertLinkTitleInputField.setUrlMode( urlMode );
|
insertLinkTitleInputField.setUrlMode( urlMode );
|
||||||
|
@ -347,7 +347,7 @@ module.exports = {
|
||||||
id: 'wikieditor-toolbar-file-dialog',
|
id: 'wikieditor-toolbar-file-dialog',
|
||||||
htmlTemplate: 'dialogInsertFile.html',
|
htmlTemplate: 'dialogInsertFile.html',
|
||||||
init: function () {
|
init: function () {
|
||||||
var magicWordsI18N = configData.magicWords;
|
const magicWordsI18N = configData.magicWords;
|
||||||
|
|
||||||
$( this ).find( '[data-i18n-magic]' )
|
$( this ).find( '[data-i18n-magic]' )
|
||||||
.text( function () {
|
.text( function () {
|
||||||
|
@ -355,7 +355,7 @@ module.exports = {
|
||||||
} )
|
} )
|
||||||
.removeAttr( 'data-i18n-magic' );
|
.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' )
|
$( this ).find( '#wikieditor-toolbar-file-size' )
|
||||||
.attr( 'placeholder', defaultMsg )
|
.attr( 'placeholder', defaultMsg )
|
||||||
// The message may be long in some languages
|
// The message may be long in some languages
|
||||||
|
@ -367,8 +367,8 @@ module.exports = {
|
||||||
} )
|
} )
|
||||||
.removeAttr( 'rel' );
|
.removeAttr( 'rel' );
|
||||||
|
|
||||||
var altHelpText = mw.msg( 'wikieditor-toolbar-file-alt-help' );
|
const altHelpText = mw.msg( 'wikieditor-toolbar-file-alt-help' );
|
||||||
var altHelpLabel = mw.msg( 'wikieditor-toolbar-file-alt-help-label' );
|
const altHelpLabel = mw.msg( 'wikieditor-toolbar-file-alt-help-label' );
|
||||||
// Expandable help message for 'alt text' field
|
// Expandable help message for 'alt text' field
|
||||||
$( this ).find( '.wikieditor-toolbar-file-alt-help' ).text( altHelpLabel );
|
$( this ).find( '.wikieditor-toolbar-file-alt-help' ).text( altHelpLabel );
|
||||||
$( '.wikieditor-toolbar-file-alt-help' ).on( 'click', function () {
|
$( '.wikieditor-toolbar-file-alt-help' ).on( 'click', function () {
|
||||||
|
@ -388,21 +388,21 @@ module.exports = {
|
||||||
width: 590,
|
width: 590,
|
||||||
buttons: {
|
buttons: {
|
||||||
'wikieditor-toolbar-tool-file-insert': function () {
|
'wikieditor-toolbar-tool-file-insert': function () {
|
||||||
var hasPxRgx = /.+px$/,
|
const hasPxRgx = /.+px$/,
|
||||||
magicWordsI18N = configData.magicWords;
|
magicWordsI18N = configData.magicWords;
|
||||||
var fileName = $( '#wikieditor-toolbar-file-target' ).val();
|
let fileName = $( '#wikieditor-toolbar-file-target' ).val();
|
||||||
var caption = $( '#wikieditor-toolbar-file-caption' ).val();
|
const caption = $( '#wikieditor-toolbar-file-caption' ).val();
|
||||||
var fileAlt = $( '#wikieditor-toolbar-file-alt' ).val();
|
const fileAlt = $( '#wikieditor-toolbar-file-alt' ).val();
|
||||||
var fileFloat = $( '#wikieditor-toolbar-file-float' ).val();
|
const fileFloat = $( '#wikieditor-toolbar-file-float' ).val();
|
||||||
var fileFormat = $( '#wikieditor-toolbar-file-format' ).val();
|
const fileFormat = $( '#wikieditor-toolbar-file-format' ).val();
|
||||||
var fileSize = $( '#wikieditor-toolbar-file-size' ).val();
|
let fileSize = $( '#wikieditor-toolbar-file-size' ).val();
|
||||||
var whitespace = $( '#wikieditor-toolbar-file-dialog' ).data( 'whitespace' );
|
const whitespace = $( '#wikieditor-toolbar-file-dialog' ).data( 'whitespace' );
|
||||||
// Append px to end to size if not already contains it
|
// Append px to end to size if not already contains it
|
||||||
if ( fileSize !== '' && !hasPxRgx.test( fileSize ) ) {
|
if ( fileSize !== '' && !hasPxRgx.test( fileSize ) ) {
|
||||||
fileSize += 'px';
|
fileSize += 'px';
|
||||||
}
|
}
|
||||||
if ( fileName !== '' ) {
|
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
|
// Append file namespace prefix to filename if not already contains it
|
||||||
if ( fileTitle && fileTitle.getNamespaceId() !== 6 ) {
|
if ( fileTitle && fileTitle.getNamespaceId() !== 6 ) {
|
||||||
fileTitle = mw.Title.makeTitle( 6, fileName );
|
fileTitle = mw.Title.makeTitle( 6, fileName );
|
||||||
|
@ -411,7 +411,7 @@ module.exports = {
|
||||||
fileName = fileTitle.toText();
|
fileName = fileTitle.toText();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var options = [ fileSize, fileFormat, fileFloat ];
|
let options = [ fileSize, fileFormat, fileFloat ];
|
||||||
// Filter empty values
|
// Filter empty values
|
||||||
options = options.filter( ( val ) => val.length && val !== 'default' );
|
options = options.filter( ( val ) => val.length && val !== 'default' );
|
||||||
if ( fileAlt.length ) {
|
if ( fileAlt.length ) {
|
||||||
|
@ -421,7 +421,7 @@ module.exports = {
|
||||||
options.push( caption );
|
options.push( caption );
|
||||||
}
|
}
|
||||||
|
|
||||||
var fileUse = options.length === 0 ? fileName : ( fileName + '|' + options.join( '|' ) );
|
const fileUse = options.length === 0 ? fileName : ( fileName + '|' + options.join( '|' ) );
|
||||||
$( this ).dialog( 'close' );
|
$( this ).dialog( 'close' );
|
||||||
toolbarModule.fn.doAction(
|
toolbarModule.fn.doAction(
|
||||||
$( this ).data( 'context' ),
|
$( this ).data( 'context' ),
|
||||||
|
@ -456,7 +456,7 @@ module.exports = {
|
||||||
'mediawiki.Upload.Dialog',
|
'mediawiki.Upload.Dialog',
|
||||||
'oojs-ui-windows'
|
'oojs-ui-windows'
|
||||||
] ).then( () => {
|
] ).then( () => {
|
||||||
var windowManager = new OO.ui.WindowManager(),
|
const windowManager = new OO.ui.WindowManager(),
|
||||||
uploadDialog = new mw.Upload.Dialog( {
|
uploadDialog = new mw.Upload.Dialog( {
|
||||||
bookletClass: mw.ForeignStructuredUpload.BookletLayout
|
bookletClass: mw.ForeignStructuredUpload.BookletLayout
|
||||||
} );
|
} );
|
||||||
|
@ -476,7 +476,7 @@ module.exports = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
open: function () {
|
open: function () {
|
||||||
var magicWordsI18N = configData.magicWords,
|
let magicWordsI18N = configData.magicWords,
|
||||||
fileData = {
|
fileData = {
|
||||||
pre: '',
|
pre: '',
|
||||||
post: '',
|
post: '',
|
||||||
|
@ -488,30 +488,30 @@ module.exports = {
|
||||||
fileFormat: magicWordsI18N.img_thumbnail[ 0 ]
|
fileFormat: magicWordsI18N.img_thumbnail[ 0 ]
|
||||||
};
|
};
|
||||||
|
|
||||||
var parseFileSyntax = function ( wikitext ) {
|
const parseFileSyntax = function ( wikitext ) {
|
||||||
var escapedPipe = '\u0001';
|
const escapedPipe = '\u0001';
|
||||||
if ( wikitext.indexOf( escapedPipe ) !== -1 ) {
|
if ( wikitext.indexOf( escapedPipe ) !== -1 ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var match = /^(\s*)\[\[(.*)\]\](\s*)$/.exec( wikitext );
|
const match = /^(\s*)\[\[(.*)\]\](\s*)$/.exec( wikitext );
|
||||||
if ( !match ) {
|
if ( !match ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Escape pipes inside links and templates,
|
// Escape pipes inside links and templates,
|
||||||
// then split the parameters at the remaining pipes
|
// then split the parameters at the remaining pipes
|
||||||
var params = match[ 2 ].replace( /\[\[[^[\]]*\]\]|\{\{[^{}]\}\}/g, ( link ) => link.replace( /\|/g, escapedPipe ) ).split( '|' );
|
const params = match[ 2 ].replace( /\[\[[^[\]]*\]\]|\{\{[^{}]\}\}/g, ( link ) => link.replace( /\|/g, escapedPipe ) ).split( '|' );
|
||||||
var file = mw.Title.newFromText( params[ 0 ] );
|
const file = mw.Title.newFromText( params[ 0 ] );
|
||||||
if ( !file || file.getNamespaceId() !== 6 ) {
|
if ( !file || file.getNamespaceId() !== 6 ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var result = {
|
const result = {
|
||||||
pre: match[ 1 ],
|
pre: match[ 1 ],
|
||||||
post: match[ 3 ],
|
post: match[ 3 ],
|
||||||
fileName: file.getMainText()
|
fileName: file.getMainText()
|
||||||
};
|
};
|
||||||
for ( var i = 1; i < params.length; i++ ) {
|
for ( let i = 1; i < params.length; i++ ) {
|
||||||
var paramOrig = params[ i ];
|
const paramOrig = params[ i ];
|
||||||
var param = paramOrig.toLowerCase();
|
const param = paramOrig.toLowerCase();
|
||||||
if ( magicWordsI18N.img_right.indexOf( param ) !== -1 ) {
|
if ( magicWordsI18N.img_right.indexOf( param ) !== -1 ) {
|
||||||
result.fileFloat = magicWordsI18N.img_right[ 0 ];
|
result.fileFloat = magicWordsI18N.img_right[ 0 ];
|
||||||
} else if ( magicWordsI18N.img_left.indexOf( param ) !== -1 ) {
|
} else if ( magicWordsI18N.img_left.indexOf( param ) !== -1 ) {
|
||||||
|
@ -545,8 +545,8 @@ module.exports = {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Retrieve the current selection
|
// Retrieve the current selection
|
||||||
var context = $( this ).data( 'context' );
|
const context = $( this ).data( 'context' );
|
||||||
var selection = context.$textarea.textSelection( 'getSelection' );
|
const selection = context.$textarea.textSelection( 'getSelection' );
|
||||||
|
|
||||||
// Pre-fill the text fields based on the current selection
|
// Pre-fill the text fields based on the current selection
|
||||||
if ( selection !== '' ) {
|
if ( selection !== '' ) {
|
||||||
|
@ -631,11 +631,11 @@ module.exports = {
|
||||||
// Instead of show/hiding, switch the HTML around
|
// Instead of show/hiding, switch the HTML around
|
||||||
// We do this because the sortable tables script styles the first row,
|
// We do this because the sortable tables script styles the first row,
|
||||||
// visible or not
|
// 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();
|
hiddenHTML = $( '.wikieditor-toolbar-table-preview-hidden' ).html();
|
||||||
$( '.wikieditor-toolbar-table-preview-header' ).html( hiddenHTML );
|
$( '.wikieditor-toolbar-table-preview-header' ).html( hiddenHTML );
|
||||||
$( '.wikieditor-toolbar-table-preview-hidden' ).html( headerHTML );
|
$( '.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' );
|
.filter( '.sortable' );
|
||||||
mw.loader.using( 'jquery.tablesorter', () => {
|
mw.loader.using( 'jquery.tablesorter', () => {
|
||||||
$sortable.tablesorter();
|
$sortable.tablesorter();
|
||||||
|
@ -648,7 +648,7 @@ module.exports = {
|
||||||
width: 590,
|
width: 590,
|
||||||
buttons: {
|
buttons: {
|
||||||
'wikieditor-toolbar-tool-table-insert': function () {
|
'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(),
|
colsVal = $( '#wikieditor-toolbar-table-dimensions-columns' ).val(),
|
||||||
rows = parseInt( rowsVal, 10 ),
|
rows = parseInt( rowsVal, 10 ),
|
||||||
cols = parseInt( colsVal, 10 ),
|
cols = parseInt( colsVal, 10 ),
|
||||||
|
@ -668,16 +668,16 @@ module.exports = {
|
||||||
alert( mw.msg( 'wikieditor-toolbar-tool-table-toomany', mw.language.convertNumber( 1000 ) ) );
|
alert( mw.msg( 'wikieditor-toolbar-tool-table-toomany', mw.language.convertNumber( 1000 ) ) );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var captionText = mw.msg( 'wikieditor-toolbar-tool-table-example-caption' );
|
const captionText = mw.msg( 'wikieditor-toolbar-tool-table-example-caption' );
|
||||||
var headerText = mw.msg( 'wikieditor-toolbar-tool-table-example-header' );
|
const headerText = mw.msg( 'wikieditor-toolbar-tool-table-example-header' );
|
||||||
var normalText = mw.msg( 'wikieditor-toolbar-tool-table-example' );
|
const normalText = mw.msg( 'wikieditor-toolbar-tool-table-example' );
|
||||||
var table = '';
|
let table = '';
|
||||||
table += '|+ ' + captionText + '\n';
|
table += '|+ ' + captionText + '\n';
|
||||||
for ( var r = 0; r < rows + header; r++ ) {
|
for ( let r = 0; r < rows + header; r++ ) {
|
||||||
table += '|-\n';
|
table += '|-\n';
|
||||||
for ( var c = 0; c < cols; c++ ) {
|
for ( let c = 0; c < cols; c++ ) {
|
||||||
var isHeader = ( header && r === 0 );
|
const isHeader = ( header && r === 0 );
|
||||||
var delim = isHeader ? '!' : '|';
|
let delim = isHeader ? '!' : '|';
|
||||||
if ( c > 0 ) {
|
if ( c > 0 ) {
|
||||||
delim += delim;
|
delim += delim;
|
||||||
}
|
}
|
||||||
|
@ -687,14 +687,14 @@ module.exports = {
|
||||||
// table[table.length - 1] is read-only
|
// table[table.length - 1] is read-only
|
||||||
table = table.slice( 0, table.length - 1 ) + '\n';
|
table = table.slice( 0, table.length - 1 ) + '\n';
|
||||||
}
|
}
|
||||||
var classes = [];
|
const classes = [];
|
||||||
if ( $( '#wikieditor-toolbar-table-wikitable' ).is( ':checked' ) ) {
|
if ( $( '#wikieditor-toolbar-table-wikitable' ).is( ':checked' ) ) {
|
||||||
classes.push( 'wikitable' );
|
classes.push( 'wikitable' );
|
||||||
}
|
}
|
||||||
if ( $( '#wikieditor-toolbar-table-sortable' ).is( ':checked' ) ) {
|
if ( $( '#wikieditor-toolbar-table-sortable' ).is( ':checked' ) ) {
|
||||||
classes.push( 'sortable' );
|
classes.push( 'sortable' );
|
||||||
}
|
}
|
||||||
var classStr = classes.length > 0 ? ' class="' + classes.join( ' ' ) + '"' : '';
|
const classStr = classes.length > 0 ? ' class="' + classes.join( ' ' ) + '"' : '';
|
||||||
$( this ).dialog( 'close' );
|
$( this ).dialog( 'close' );
|
||||||
toolbarModule.fn.doAction(
|
toolbarModule.fn.doAction(
|
||||||
$( this ).data( 'context' ),
|
$( 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();
|
$( '#wikieditor-toolbar-replace-nomatch, #wikieditor-toolbar-replace-success, #wikieditor-toolbar-replace-emptysearch, #wikieditor-toolbar-replace-invalidregex' ).hide();
|
||||||
|
|
||||||
// Search string cannot be empty
|
// Search string cannot be empty
|
||||||
var searchStr = $( '#wikieditor-toolbar-replace-search' ).val();
|
let searchStr = $( '#wikieditor-toolbar-replace-search' ).val();
|
||||||
if ( searchStr === '' ) {
|
if ( searchStr === '' ) {
|
||||||
$( '#wikieditor-toolbar-replace-emptysearch' ).show();
|
$( '#wikieditor-toolbar-replace-emptysearch' ).show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace string can be empty
|
// Replace string can be empty
|
||||||
var replaceStr = $( '#wikieditor-toolbar-replace-replace' ).val();
|
const replaceStr = $( '#wikieditor-toolbar-replace-replace' ).val();
|
||||||
|
|
||||||
// Prepare the regular expression flags
|
// Prepare the regular expression flags
|
||||||
var flags = 'm';
|
let flags = 'm';
|
||||||
var matchCase = $( '#wikieditor-toolbar-replace-case' ).is( ':checked' );
|
const matchCase = $( '#wikieditor-toolbar-replace-case' ).is( ':checked' );
|
||||||
if ( !matchCase ) {
|
if ( !matchCase ) {
|
||||||
flags += 'i';
|
flags += 'i';
|
||||||
}
|
}
|
||||||
var isRegex = $( '#wikieditor-toolbar-replace-regex' ).is( ':checked' );
|
const isRegex = $( '#wikieditor-toolbar-replace-regex' ).is( ':checked' );
|
||||||
if ( !isRegex ) {
|
if ( !isRegex ) {
|
||||||
searchStr = mw.util.escapeRegExp( searchStr );
|
searchStr = mw.util.escapeRegExp( searchStr );
|
||||||
}
|
}
|
||||||
var matchWord = $( '#wikieditor-toolbar-replace-word' ).is( ':checked' );
|
const matchWord = $( '#wikieditor-toolbar-replace-word' ).is( ':checked' );
|
||||||
if ( matchWord ) {
|
if ( matchWord ) {
|
||||||
searchStr = '\\b(?:' + searchStr + ')\\b';
|
searchStr = '\\b(?:' + searchStr + ')\\b';
|
||||||
}
|
}
|
||||||
|
@ -793,7 +793,7 @@ module.exports = {
|
||||||
flags += 'g';
|
flags += 'g';
|
||||||
}
|
}
|
||||||
|
|
||||||
var regex;
|
let regex;
|
||||||
try {
|
try {
|
||||||
regex = new RegExp( searchStr, flags );
|
regex = new RegExp( searchStr, flags );
|
||||||
} catch ( e ) {
|
} catch ( e ) {
|
||||||
|
@ -804,10 +804,10 @@ module.exports = {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var $textarea = $( this ).data( 'context' ).$textarea;
|
const $textarea = $( this ).data( 'context' ).$textarea;
|
||||||
var text = $textarea.textSelection( 'getContents' );
|
let text = $textarea.textSelection( 'getContents' );
|
||||||
var match = false;
|
let match = false;
|
||||||
var offset, textRemainder;
|
let offset, textRemainder;
|
||||||
if ( mode !== 'replaceAll' ) {
|
if ( mode !== 'replaceAll' ) {
|
||||||
offset = $( this ).data( mode === 'replace' ? 'matchIndex' : 'offset' );
|
offset = $( this ).data( mode === 'replace' ? 'matchIndex' : 'offset' );
|
||||||
textRemainder = text.slice( offset );
|
textRemainder = text.slice( offset );
|
||||||
|
@ -831,10 +831,10 @@ module.exports = {
|
||||||
$( this ).data( 'offset', 0 );
|
$( this ).data( 'offset', 0 );
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
var start, end;
|
let start, end;
|
||||||
if ( mode === 'replace' ) {
|
if ( mode === 'replace' ) {
|
||||||
|
|
||||||
var actualReplacement;
|
let actualReplacement;
|
||||||
if ( isRegex ) {
|
if ( isRegex ) {
|
||||||
// If backreferences (like $1) are used, the actual actual replacement string will be different
|
// If backreferences (like $1) are used, the actual actual replacement string will be different
|
||||||
actualReplacement = match[ 0 ].replace( regex, replaceStr );
|
actualReplacement = match[ 0 ].replace( regex, replaceStr );
|
||||||
|
@ -907,7 +907,7 @@ module.exports = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
open: function () {
|
open: function () {
|
||||||
var that = this;
|
let that = this;
|
||||||
$( this ).data( { offset: 0, matchIndex: 0 } );
|
$( this ).data( { offset: 0, matchIndex: 0 } );
|
||||||
|
|
||||||
$( '#wikieditor-toolbar-replace-search' ).trigger( 'focus' );
|
$( '#wikieditor-toolbar-replace-search' ).trigger( 'focus' );
|
||||||
|
@ -928,7 +928,7 @@ module.exports = {
|
||||||
$( this ).closest( '.ui-dialog' ).data( 'dialogaction', this );
|
$( this ).closest( '.ui-dialog' ).data( 'dialogaction', this );
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
var $dialog = $( this ).closest( '.ui-dialog' );
|
const $dialog = $( this ).closest( '.ui-dialog' );
|
||||||
that = this;
|
that = this;
|
||||||
$( this ).data( 'context' ).$textarea
|
$( this ).data( 'context' ).$textarea
|
||||||
.on( 'keypress.srdialog', ( e ) => {
|
.on( 'keypress.srdialog', ( e ) => {
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
*
|
*
|
||||||
* @memberof module:ext.wikiEditor
|
* @memberof module:ext.wikiEditor
|
||||||
*/
|
*/
|
||||||
var dialogsModule = {
|
const dialogsModule = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API accessible functions
|
* API accessible functions
|
||||||
|
@ -14,8 +14,8 @@ var dialogsModule = {
|
||||||
},
|
},
|
||||||
openDialog: function ( context, module ) {
|
openDialog: function ( context, module ) {
|
||||||
if ( module in dialogsModule.modules ) {
|
if ( module in dialogsModule.modules ) {
|
||||||
var mod = dialogsModule.modules[ module ];
|
const mod = dialogsModule.modules[ module ];
|
||||||
var $dialog = $( '#' + mod.id );
|
let $dialog = $( '#' + mod.id );
|
||||||
if ( $dialog.length === 0 ) {
|
if ( $dialog.length === 0 ) {
|
||||||
dialogsModule.fn.reallyCreate( context, mod, module );
|
dialogsModule.fn.reallyCreate( context, mod, module );
|
||||||
$dialog = $( '#' + mod.id );
|
$dialog = $( '#' + mod.id );
|
||||||
|
@ -48,12 +48,12 @@ var dialogsModule = {
|
||||||
*/
|
*/
|
||||||
create: function ( context, config ) {
|
create: function ( context, config ) {
|
||||||
// Defer building of modules, unless they require immediate creation
|
// Defer building of modules, unless they require immediate creation
|
||||||
for ( var mod in config ) {
|
for ( const mod in config ) {
|
||||||
var module = config[ mod ];
|
const module = config[ mod ];
|
||||||
// Only create the dialog if it isn't filtered and doesn't exist yet
|
// 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' ) {
|
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 ) {
|
if ( $( module.filters[ i ] ).length === 0 ) {
|
||||||
filtered = true;
|
filtered = true;
|
||||||
break;
|
break;
|
||||||
|
@ -61,7 +61,7 @@ var dialogsModule = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If the dialog already exists, but for another textarea, simply remove it
|
// 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 ) {
|
if ( $existingDialog.length > 0 && $existingDialog.data( 'context' ).$textarea !== context.$textarea ) {
|
||||||
$existingDialog.remove();
|
$existingDialog.remove();
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ var dialogsModule = {
|
||||||
* @param {string} name Dialog name (key in dialogsModule.modules)
|
* @param {string} name Dialog name (key in dialogsModule.modules)
|
||||||
*/
|
*/
|
||||||
reallyCreate: function ( context, module, name ) {
|
reallyCreate: function ( context, module, name ) {
|
||||||
var configuration = module.dialog;
|
const configuration = module.dialog;
|
||||||
// Add some stuff to configuration
|
// Add some stuff to configuration
|
||||||
configuration.bgiframe = true;
|
configuration.bgiframe = true;
|
||||||
configuration.autoOpen = false;
|
configuration.autoOpen = false;
|
||||||
|
@ -99,12 +99,12 @@ var dialogsModule = {
|
||||||
// Stupid JS won't let us do stuff like
|
// Stupid JS won't let us do stuff like
|
||||||
// foo = { mw.msg( 'bar' ): baz }
|
// foo = { mw.msg( 'bar' ): baz }
|
||||||
configuration.newButtons = {};
|
configuration.newButtons = {};
|
||||||
for ( var msg in configuration.buttons ) {
|
for ( const msg in configuration.buttons ) {
|
||||||
// eslint-disable-next-line mediawiki/msg-doc
|
// eslint-disable-next-line mediawiki/msg-doc
|
||||||
configuration.newButtons[ mw.msg( msg ) ] = configuration.buttons[ msg ];
|
configuration.newButtons[ mw.msg( msg ) ] = configuration.buttons[ msg ];
|
||||||
}
|
}
|
||||||
configuration.buttons = configuration.newButtons;
|
configuration.buttons = configuration.newButtons;
|
||||||
var $content;
|
let $content;
|
||||||
if ( module.htmlTemplate ) {
|
if ( module.htmlTemplate ) {
|
||||||
$content = mw.template.get( 'ext.wikiEditor', module.htmlTemplate ).render();
|
$content = mw.template.get( 'ext.wikiEditor', module.htmlTemplate ).render();
|
||||||
} else if ( module.html instanceof $ ) {
|
} else if ( module.html instanceof $ ) {
|
||||||
|
@ -113,7 +113,7 @@ var dialogsModule = {
|
||||||
$content = $( $.parseHTML( module.html ) );
|
$content = $( $.parseHTML( module.html ) );
|
||||||
}
|
}
|
||||||
// Create the dialog <div>
|
// Create the dialog <div>
|
||||||
var $dialogDiv = $( '<div>' )
|
const $dialogDiv = $( '<div>' )
|
||||||
.attr( 'id', module.id )
|
.attr( 'id', module.id )
|
||||||
.append( $content )
|
.append( $content )
|
||||||
.data( 'context', context )
|
.data( 'context', context )
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
var hasOwn = Object.prototype.hasOwnProperty,
|
const hasOwn = Object.prototype.hasOwnProperty,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Array of language codes.
|
* Array of language codes.
|
||||||
|
@ -20,7 +20,7 @@ var hasOwn = Object.prototype.hasOwnProperty,
|
||||||
*/
|
*/
|
||||||
fallbackChain = ( function () {
|
fallbackChain = ( function () {
|
||||||
// eslint-disable-next-line no-jquery/no-class-state
|
// 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();
|
chain = mw.language.getFallbackLanguageChain();
|
||||||
|
|
||||||
// Do not fallback to 'en'
|
// Do not fallback to 'en'
|
||||||
|
@ -43,10 +43,10 @@ var hasOwn = Object.prototype.hasOwnProperty,
|
||||||
* @param {string} key
|
* @param {string} key
|
||||||
*/
|
*/
|
||||||
function deprecateAutoMsg( property, key ) {
|
function deprecateAutoMsg( property, key ) {
|
||||||
var searchParam = mw.config.get( 'wgSearchType' ) === 'CirrusSearch' ?
|
const searchParam = mw.config.get( 'wgSearchType' ) === 'CirrusSearch' ?
|
||||||
'insource:/' + property + 'Msg: \'' + key + '\'/' :
|
'insource:/' + property + 'Msg: \'' + key + '\'/' :
|
||||||
property + 'Msg: ' + key;
|
property + 'Msg: ' + key;
|
||||||
var searchUri = mw.config.get( 'wgServer' ) +
|
let searchUri = mw.config.get( 'wgServer' ) +
|
||||||
mw.util.getUrl(
|
mw.util.getUrl(
|
||||||
'Special:Search',
|
'Special:Search',
|
||||||
{ search: searchParam, ns2: 1, ns8: 1 }
|
{ search: searchParam, ns2: 1, ns8: 1 }
|
||||||
|
@ -55,13 +55,13 @@ function deprecateAutoMsg( property, key ) {
|
||||||
searchUri = location.protocol + searchUri;
|
searchUri = location.protocol + searchUri;
|
||||||
}
|
}
|
||||||
|
|
||||||
var messageMethod;
|
let messageMethod;
|
||||||
if ( property === 'html' || property === 'text' || property === 'title' ) {
|
if ( property === 'html' || property === 'text' || property === 'title' ) {
|
||||||
messageMethod = 'mw.message( ' + JSON.stringify( key ) + ' ).parse()';
|
messageMethod = 'mw.message( ' + JSON.stringify( key ) + ' ).parse()';
|
||||||
} else {
|
} else {
|
||||||
messageMethod = 'mw.msg( ' + JSON.stringify( key ) + ' )';
|
messageMethod = 'mw.msg( ' + JSON.stringify( key ) + ' )';
|
||||||
}
|
}
|
||||||
var deprecationMsg = mw.log.makeDeprecated(
|
const deprecationMsg = mw.log.makeDeprecated(
|
||||||
'wikiEditor_autoMsg',
|
'wikiEditor_autoMsg',
|
||||||
'WikiEditor: Use `' + property + ': ' + messageMethod + '` instead of `' + property + 'Msg: ' + JSON.stringify( key ) + '`.\nSearch: ' + searchUri
|
'WikiEditor: Use `' + property + ': ' + messageMethod + '` instead of `' + property + 'Msg: ' + JSON.stringify( key ) + '`.\nSearch: ' + searchUri
|
||||||
);
|
);
|
||||||
|
@ -110,7 +110,7 @@ $.wikiEditor = {
|
||||||
*/
|
*/
|
||||||
isRequired: function ( module, requirement ) {
|
isRequired: function ( module, requirement ) {
|
||||||
if ( typeof module.req !== 'undefined' ) {
|
if ( typeof module.req !== 'undefined' ) {
|
||||||
for ( var req in module.req ) {
|
for ( const req in module.req ) {
|
||||||
if ( module.req[ req ] === requirement ) {
|
if ( module.req[ req ] === requirement ) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -138,7 +138,7 @@ $.wikiEditor = {
|
||||||
autoMsg: function ( object, property ) {
|
autoMsg: function ( object, property ) {
|
||||||
// Accept array of possible properties, of which the first one found will be used
|
// Accept array of possible properties, of which the first one found will be used
|
||||||
if ( typeof property === 'object' ) {
|
if ( typeof property === 'object' ) {
|
||||||
for ( var i in property ) {
|
for ( const i in property ) {
|
||||||
if ( property[ i ] in object || property[ i ] + 'Msg' in object ) {
|
if ( property[ i ] in object || property[ i ] + 'Msg' in object ) {
|
||||||
property = property[ i ];
|
property = property[ i ];
|
||||||
break;
|
break;
|
||||||
|
@ -148,7 +148,7 @@ $.wikiEditor = {
|
||||||
if ( property in object ) {
|
if ( property in object ) {
|
||||||
return object[ property ];
|
return object[ property ];
|
||||||
} else if ( property + 'Msg' in object ) {
|
} else if ( property + 'Msg' in object ) {
|
||||||
var p = object[ property + 'Msg' ];
|
const p = object[ property + 'Msg' ];
|
||||||
if ( Array.isArray( p ) && p.length >= 2 ) {
|
if ( Array.isArray( p ) && p.length >= 2 ) {
|
||||||
deprecateAutoMsg( property, p[ 0 ] );
|
deprecateAutoMsg( property, p[ 0 ] );
|
||||||
return mw.message.apply( mw.message, p ).text();
|
return mw.message.apply( mw.message, p ).text();
|
||||||
|
@ -179,7 +179,7 @@ $.wikiEditor = {
|
||||||
autoSafeMsg: function ( object, property ) {
|
autoSafeMsg: function ( object, property ) {
|
||||||
// Accept array of possible properties, of which the first one found will be used
|
// Accept array of possible properties, of which the first one found will be used
|
||||||
if ( typeof property === 'object' ) {
|
if ( typeof property === 'object' ) {
|
||||||
for ( var i in property ) {
|
for ( const i in property ) {
|
||||||
if ( property[ i ] in object || property[ i ] + 'Msg' in object ) {
|
if ( property[ i ] in object || property[ i ] + 'Msg' in object ) {
|
||||||
property = property[ i ];
|
property = property[ i ];
|
||||||
break;
|
break;
|
||||||
|
@ -189,7 +189,7 @@ $.wikiEditor = {
|
||||||
if ( property in object ) {
|
if ( property in object ) {
|
||||||
return object[ property ];
|
return object[ property ];
|
||||||
} else if ( property + 'Msg' in object ) {
|
} else if ( property + 'Msg' in object ) {
|
||||||
var p = object[ property + 'Msg' ];
|
const p = object[ property + 'Msg' ];
|
||||||
if ( Array.isArray( p ) && p.length >= 2 ) {
|
if ( Array.isArray( p ) && p.length >= 2 ) {
|
||||||
deprecateAutoMsg( property, p[ 0 ] );
|
deprecateAutoMsg( property, p[ 0 ] );
|
||||||
return mw.message.apply( mw.message, p ).escaped();
|
return mw.message.apply( mw.message, p ).escaped();
|
||||||
|
@ -213,8 +213,8 @@ $.wikiEditor = {
|
||||||
* @return {Object}
|
* @return {Object}
|
||||||
*/
|
*/
|
||||||
autoLang: function ( object ) {
|
autoLang: function ( object ) {
|
||||||
for ( var i = 0; i < fallbackChain.length; i++ ) {
|
for ( let i = 0; i < fallbackChain.length; i++ ) {
|
||||||
var key = fallbackChain[ i ];
|
const key = fallbackChain[ i ];
|
||||||
if ( hasOwn.call( object, key ) ) {
|
if ( hasOwn.call( object, key ) ) {
|
||||||
return object[ key ];
|
return object[ key ];
|
||||||
}
|
}
|
||||||
|
@ -233,10 +233,10 @@ $.wikiEditor = {
|
||||||
autoIcon: function ( icon, path ) {
|
autoIcon: function ( icon, path ) {
|
||||||
path = path || $.wikiEditor.imgPath;
|
path = path || $.wikiEditor.imgPath;
|
||||||
|
|
||||||
for ( var i = 0; i < fallbackChain.length; i++ ) {
|
for ( let i = 0; i < fallbackChain.length; i++ ) {
|
||||||
var key = fallbackChain[ i ];
|
const key = fallbackChain[ i ];
|
||||||
if ( icon && hasOwn.call( icon, key ) ) {
|
if ( icon && hasOwn.call( icon, key ) ) {
|
||||||
var src = icon[ key ];
|
let src = icon[ key ];
|
||||||
|
|
||||||
// Return a data URL immediately
|
// Return a data URL immediately
|
||||||
if ( src.slice( 0, 5 ) === 'data:' ) {
|
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
|
// 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
|
// 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
|
// On first call, we need to set things up, but on all following calls we can skip right to the API handling
|
||||||
if ( !context ) {
|
if ( !context ) {
|
||||||
|
|
||||||
|
@ -303,18 +303,18 @@ $.fn.wikiEditor = function () {
|
||||||
* or an object with members keyed with module names and valued with configuration objects.
|
* or an object with members keyed with module names and valued with configuration objects.
|
||||||
*/
|
*/
|
||||||
addModule: function ( ctx, data ) {
|
addModule: function ( ctx, data ) {
|
||||||
var modules = {};
|
let modules = {};
|
||||||
if ( typeof data === 'string' ) {
|
if ( typeof data === 'string' ) {
|
||||||
modules[ data ] = {};
|
modules[ data ] = {};
|
||||||
} else if ( typeof data === 'object' ) {
|
} else if ( typeof data === 'object' ) {
|
||||||
modules = data;
|
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
|
// 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' ) {
|
if ( typeof module === 'string' && typeof $.wikiEditor.modules[ module ] !== 'undefined' ) {
|
||||||
// Extend the context's core API with this module's own API calls
|
// Extend the context's core API with this module's own API calls
|
||||||
if ( 'api' in $.wikiEditor.modules[ module ] ) {
|
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
|
// Modules may not overwrite existing API functions - first come, first serve
|
||||||
if ( !( call in ctx.api ) ) {
|
if ( !( call in ctx.api ) ) {
|
||||||
ctx.api[ call ] = $.wikiEditor.modules[ module ].api[ call ];
|
ctx.api[ call ] = $.wikiEditor.modules[ module ].api[ call ];
|
||||||
|
@ -369,16 +369,16 @@ $.fn.wikiEditor = function () {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var returnFromModules = true;
|
let returnFromModules = true;
|
||||||
// Pass the event around to all modules activated on this context
|
// Pass the event around to all modules activated on this context
|
||||||
|
|
||||||
for ( var module in context.modules ) {
|
for ( const module in context.modules ) {
|
||||||
if (
|
if (
|
||||||
module in $.wikiEditor.modules &&
|
module in $.wikiEditor.modules &&
|
||||||
'evt' in $.wikiEditor.modules[ module ] &&
|
'evt' in $.wikiEditor.modules[ module ] &&
|
||||||
name in $.wikiEditor.modules[ module ].evt
|
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 ( ret !== null ) {
|
||||||
// if 1 returns false, the end result is false
|
// if 1 returns false, the end result is false
|
||||||
returnFromModules = returnFromModules && ret;
|
returnFromModules = returnFromModules && ret;
|
||||||
|
@ -493,8 +493,8 @@ $.fn.wikiEditor = function () {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Preserving cursor and focus state, which will get lost due to wrapAll */
|
/* Preserving cursor and focus state, which will get lost due to wrapAll */
|
||||||
var hasFocus = context.$textarea.is( ':focus' );
|
const hasFocus = context.$textarea.is( ':focus' );
|
||||||
var cursorPos = context.$textarea.textSelection( 'getCaretPosition', { startAndEnd: true } );
|
const cursorPos = context.$textarea.textSelection( 'getCaretPosition', { startAndEnd: true } );
|
||||||
// Encapsulate the textarea with some containers for layout
|
// Encapsulate the textarea with some containers for layout
|
||||||
context.$textarea
|
context.$textarea
|
||||||
.wrapAll( $( '<div>' ).addClass( 'wikiEditor-ui' ) )
|
.wrapAll( $( '<div>' ).addClass( 'wikiEditor-ui' ) )
|
||||||
|
@ -545,19 +545,19 @@ $.fn.wikiEditor = function () {
|
||||||
/* API Execution */
|
/* API Execution */
|
||||||
|
|
||||||
// Since javascript gives arguments as an object, we need to convert them so they can be used more easily
|
// 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
|
// Dynamically setup core extensions for modules that are required
|
||||||
if ( args[ 0 ] === 'addModule' && typeof args[ 1 ] !== 'undefined' ) {
|
if ( args[ 0 ] === 'addModule' && typeof args[ 1 ] !== 'undefined' ) {
|
||||||
var modulesArg = args[ 1 ];
|
let modulesArg = args[ 1 ];
|
||||||
if ( typeof modulesArg !== 'object' ) {
|
if ( typeof modulesArg !== 'object' ) {
|
||||||
modulesArg = {};
|
modulesArg = {};
|
||||||
modulesArg[ args[ 1 ] ] = '';
|
modulesArg[ args[ 1 ] ] = '';
|
||||||
}
|
}
|
||||||
for ( var m in modulesArg ) {
|
for ( const m in modulesArg ) {
|
||||||
if ( m in $.wikiEditor.modules ) {
|
if ( m in $.wikiEditor.modules ) {
|
||||||
// Activate all required core extensions on context
|
// Activate all required core extensions on context
|
||||||
for ( var extension in $.wikiEditor.extensions ) {
|
for ( const extension in $.wikiEditor.extensions ) {
|
||||||
if (
|
if (
|
||||||
$.wikiEditor.isRequired( $.wikiEditor.modules[ m ], extension ) &&
|
$.wikiEditor.isRequired( $.wikiEditor.modules[ m ], extension ) &&
|
||||||
context.extensions.indexOf( extension ) === -1
|
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
|
// There would need to be some arguments if the API is being called
|
||||||
if ( args.length > 0 ) {
|
if ( args.length > 0 ) {
|
||||||
// Handle API calls
|
// Handle API calls
|
||||||
var callArg = args.shift();
|
const callArg = args.shift();
|
||||||
if ( callArg in context.api ) {
|
if ( callArg in context.api ) {
|
||||||
context.api[ callArg ]( context, args[ 0 ] || {} );
|
context.api[ callArg ]( context, args[ 0 ] || {} );
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
var configData = require( './data.json' ),
|
let configData = require( './data.json' ),
|
||||||
fileNamespace = mw.config.get( 'wgFormattedNamespaces' )[ 6 ],
|
fileNamespace = mw.config.get( 'wgFormattedNamespaces' )[ 6 ],
|
||||||
specialCharacterGroups = require( 'mediawiki.language.specialCharacters' ),
|
specialCharacterGroups = require( 'mediawiki.language.specialCharacters' ),
|
||||||
toolbarConfig;
|
toolbarConfig;
|
||||||
|
@ -18,7 +18,7 @@ var configData = require( './data.json' ),
|
||||||
*/
|
*/
|
||||||
function delink( $message ) {
|
function delink( $message ) {
|
||||||
// dummy div to append the message to
|
// dummy div to append the message to
|
||||||
var $div = $( '<div>' );
|
const $div = $( '<div>' );
|
||||||
|
|
||||||
$div.append( $message );
|
$div.append( $message );
|
||||||
$div.find( 'a' ).attr( 'href', '#' );
|
$div.find( 'a' ).attr( 'href', '#' );
|
||||||
|
|
|
@ -3,7 +3,8 @@
|
||||||
*
|
*
|
||||||
* @memberof module:ext.wikiEditor
|
* @memberof module:ext.wikiEditor
|
||||||
*/
|
*/
|
||||||
var toolbarModule = {
|
|
||||||
|
const toolbarModule = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API accessible functions
|
* API accessible functions
|
||||||
|
@ -11,13 +12,13 @@ var toolbarModule = {
|
||||||
api: {
|
api: {
|
||||||
addToToolbar: function ( context, data ) {
|
addToToolbar: function ( context, data ) {
|
||||||
|
|
||||||
for ( var type in data ) {
|
for ( const type in data ) {
|
||||||
var i;
|
let i;
|
||||||
switch ( type ) {
|
switch ( type ) {
|
||||||
case 'sections':
|
case 'sections': {
|
||||||
var $sections = context.modules.toolbar.$toolbar.find( 'div.sections' );
|
const $sections = context.modules.toolbar.$toolbar.find( 'div.sections' );
|
||||||
var $tabs = context.modules.toolbar.$toolbar.find( 'div.tabs' );
|
const $tabs = context.modules.toolbar.$toolbar.find( 'div.tabs' );
|
||||||
for ( var section in data[ type ] ) {
|
for ( const section in data[ type ] ) {
|
||||||
if ( section === 'main' || section === 'secondary' ) {
|
if ( section === 'main' || section === 'secondary' ) {
|
||||||
// Section
|
// Section
|
||||||
context.modules.toolbar.$toolbar.prepend(
|
context.modules.toolbar.$toolbar.prepend(
|
||||||
|
@ -37,27 +38,29 @@ var toolbarModule = {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'groups':
|
}
|
||||||
|
case 'groups': {
|
||||||
if ( !( 'section' in data ) ) {
|
if ( !( 'section' in data ) ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
var $section = context.modules.toolbar.$toolbar.find( 'div[rel="' + data.section + '"].section' );
|
const $section = context.modules.toolbar.$toolbar.find( 'div[rel="' + data.section + '"].section' );
|
||||||
for ( var group in data[ type ] ) {
|
for ( const group in data[ type ] ) {
|
||||||
// Group
|
// Group
|
||||||
$section.append(
|
$section.append(
|
||||||
toolbarModule.fn.buildGroup( context, group, data[ type ][ group ] )
|
toolbarModule.fn.buildGroup( context, group, data[ type ][ group ] )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'tools':
|
}
|
||||||
|
case 'tools': {
|
||||||
if ( !( 'section' in data && 'group' in data ) ) {
|
if ( !( 'section' in data && 'group' in data ) ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
var $group = context.modules.toolbar.$toolbar.find(
|
const $group = context.modules.toolbar.$toolbar.find(
|
||||||
'div[rel="' + data.section + '"].section ' +
|
'div[rel="' + data.section + '"].section ' +
|
||||||
'div[rel="' + data.group + '"].group'
|
'div[rel="' + data.group + '"].group'
|
||||||
);
|
);
|
||||||
for ( var tool in data[ type ] ) {
|
for ( const tool in data[ type ] ) {
|
||||||
// Tool
|
// Tool
|
||||||
$group.append( toolbarModule.fn.buildTool( context, tool, data[ type ][ tool ] ) );
|
$group.append( toolbarModule.fn.buildTool( context, tool, data[ type ][ tool ] ) );
|
||||||
}
|
}
|
||||||
|
@ -65,17 +68,18 @@ var toolbarModule = {
|
||||||
$group.removeClass( 'empty' );
|
$group.removeClass( 'empty' );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'pages':
|
}
|
||||||
|
case 'pages': {
|
||||||
if ( !( 'section' in data ) ) {
|
if ( !( 'section' in data ) ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
var $pages = context.modules.toolbar.$toolbar.find(
|
const $pages = context.modules.toolbar.$toolbar.find(
|
||||||
'div[rel="' + data.section + '"].section .pages'
|
'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'
|
'div[rel="' + data.section + '"].section .index'
|
||||||
);
|
);
|
||||||
for ( var page in data[ type ] ) {
|
for ( const page in data[ type ] ) {
|
||||||
// Page
|
// Page
|
||||||
$pages.append( toolbarModule.fn.buildPage( context, page, data[ type ][ page ] ) );
|
$pages.append( toolbarModule.fn.buildPage( context, page, data[ type ][ page ] ) );
|
||||||
// Index
|
// Index
|
||||||
|
@ -85,11 +89,12 @@ var toolbarModule = {
|
||||||
}
|
}
|
||||||
toolbarModule.fn.updateBookletSelection( context, data.section, $pages, $index );
|
toolbarModule.fn.updateBookletSelection( context, data.section, $pages, $index );
|
||||||
break;
|
break;
|
||||||
case 'rows':
|
}
|
||||||
|
case 'rows': {
|
||||||
if ( !( 'section' in data && 'page' in data ) ) {
|
if ( !( 'section' in data && 'page' in data ) ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
var $table = context.modules.toolbar.$toolbar.find(
|
const $table = context.modules.toolbar.$toolbar.find(
|
||||||
'div[rel="' + data.section + '"].section ' +
|
'div[rel="' + data.section + '"].section ' +
|
||||||
'div[rel="' + data.page + '"].page table'
|
'div[rel="' + data.page + '"].page table'
|
||||||
);
|
);
|
||||||
|
@ -98,15 +103,16 @@ var toolbarModule = {
|
||||||
$table.append( toolbarModule.fn.buildRow( context, data.rows[ i ] ) );
|
$table.append( toolbarModule.fn.buildRow( context, data.rows[ i ] ) );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'characters':
|
}
|
||||||
|
case 'characters': {
|
||||||
if ( !( 'section' in data && 'page' in data ) ) {
|
if ( !( 'section' in data && 'page' in data ) ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
var $characters = context.modules.toolbar.$toolbar.find(
|
const $characters = context.modules.toolbar.$toolbar.find(
|
||||||
'div[rel="' + data.section + '"].section ' +
|
'div[rel="' + data.section + '"].section ' +
|
||||||
'div[rel="' + data.page + '"].page div'
|
'div[rel="' + data.page + '"].page div'
|
||||||
);
|
);
|
||||||
var actions = $characters.data( 'actions' );
|
const actions = $characters.data( 'actions' );
|
||||||
for ( i = 0; i < data.characters.length; i++ ) {
|
for ( i = 0; i < data.characters.length; i++ ) {
|
||||||
// Character
|
// Character
|
||||||
$characters.append(
|
$characters.append(
|
||||||
|
@ -125,6 +131,7 @@ var toolbarModule = {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,9 +139,9 @@ var toolbarModule = {
|
||||||
removeFromToolbar: function ( context, data ) {
|
removeFromToolbar: function ( context, data ) {
|
||||||
if ( typeof data.section === 'string' ) {
|
if ( typeof data.section === 'string' ) {
|
||||||
// Section
|
// Section
|
||||||
var tab = 'div.tabs span[rel="' + data.section + '"].tab';
|
const tab = 'div.tabs span[rel="' + data.section + '"].tab';
|
||||||
var target = 'div[rel="' + data.section + '"].section';
|
let target = 'div[rel="' + data.section + '"].section';
|
||||||
var group = null;
|
let group = null;
|
||||||
if ( typeof data.group === 'string' ) {
|
if ( typeof data.group === 'string' ) {
|
||||||
// Toolbar group
|
// Toolbar group
|
||||||
target += ' div[rel="' + data.group + '"].group';
|
target += ' div[rel="' + data.group + '"].group';
|
||||||
|
@ -146,7 +153,7 @@ var toolbarModule = {
|
||||||
}
|
}
|
||||||
} else if ( typeof data.page === 'string' ) {
|
} else if ( typeof data.page === 'string' ) {
|
||||||
// Booklet page
|
// 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';
|
target += ' div.pages div[rel="' + data.page + '"].page';
|
||||||
if ( typeof data.character === 'string' ) {
|
if ( typeof data.character === 'string' ) {
|
||||||
// Character
|
// Character
|
||||||
|
@ -171,7 +178,7 @@ var toolbarModule = {
|
||||||
context.modules.toolbar.$toolbar.find( target ).remove();
|
context.modules.toolbar.$toolbar.find( target ).remove();
|
||||||
// Hide empty groups
|
// Hide empty groups
|
||||||
if ( group ) {
|
if ( group ) {
|
||||||
var $group = context.modules.toolbar.$toolbar.find( group );
|
const $group = context.modules.toolbar.$toolbar.find( group );
|
||||||
if ( $group.children().length === 0 ) {
|
if ( $group.children().length === 0 ) {
|
||||||
$group.addClass( 'empty' );
|
$group.addClass( 'empty' );
|
||||||
}
|
}
|
||||||
|
@ -209,18 +216,18 @@ var toolbarModule = {
|
||||||
doAction: function ( context, action ) {
|
doAction: function ( context, action ) {
|
||||||
switch ( action.type ) {
|
switch ( action.type ) {
|
||||||
case 'replace':
|
case 'replace':
|
||||||
case 'encapsulate':
|
case 'encapsulate': {
|
||||||
if ( context.$textarea.prop( 'readonly' ) ) {
|
if ( context.$textarea.prop( 'readonly' ) ) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
var parts = {
|
const parts = {
|
||||||
pre: $.wikiEditor.autoMsg( action.options, 'pre' ),
|
pre: $.wikiEditor.autoMsg( action.options, 'pre' ),
|
||||||
peri: $.wikiEditor.autoMsg( action.options, 'peri' ),
|
peri: $.wikiEditor.autoMsg( action.options, 'peri' ),
|
||||||
post: $.wikiEditor.autoMsg( action.options, 'post' )
|
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 ) {
|
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 ) ) {
|
if ( selection !== '' && action.options.regex.test( selection ) ) {
|
||||||
parts.peri = selection.replace( action.options.regex,
|
parts.peri = selection.replace( action.options.regex,
|
||||||
action.options.regexReplace );
|
action.options.regexReplace );
|
||||||
|
@ -233,6 +240,7 @@ var toolbarModule = {
|
||||||
Object.assign( {}, action.options, parts, { replace: replace } )
|
Object.assign( {}, action.options, parts, { replace: replace } )
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case 'callback':
|
case 'callback':
|
||||||
if ( typeof action.execute === 'function' ) {
|
if ( typeof action.execute === 'function' ) {
|
||||||
action.execute( context );
|
action.execute( context );
|
||||||
|
@ -246,15 +254,15 @@ var toolbarModule = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
buildGroup: function ( context, id, group ) {
|
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' );
|
label = $.wikiEditor.autoMsg( group, 'label' );
|
||||||
if ( label ) {
|
if ( label ) {
|
||||||
$( '<span>' ).addClass( 'label' ).text( label ).appendTo( $group );
|
$( '<span>' ).addClass( 'label' ).text( label ).appendTo( $group );
|
||||||
}
|
}
|
||||||
var empty = true;
|
let empty = true;
|
||||||
if ( 'tools' in group ) {
|
if ( 'tools' in group ) {
|
||||||
for ( var tool in group.tools ) {
|
for ( const tool in group.tools ) {
|
||||||
var $tool = toolbarModule.fn.buildTool( context, tool, group.tools[ tool ] );
|
const $tool = toolbarModule.fn.buildTool( context, tool, group.tools[ tool ] );
|
||||||
if ( $tool ) {
|
if ( $tool ) {
|
||||||
// Consider a group with only hidden tools empty as well
|
// Consider a group with only hidden tools empty as well
|
||||||
// .is( ':visible' ) always returns false because tool is not attached to the DOM yet
|
// .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 ) {
|
buildTool: function ( context, id, tool ) {
|
||||||
if ( 'filters' in 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 ) {
|
if ( $( tool.filters[ i ] ).length === 0 ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var label = $.wikiEditor.autoMsg( tool, 'label' );
|
const label = $.wikiEditor.autoMsg( tool, 'label' );
|
||||||
switch ( tool.type ) {
|
switch ( tool.type ) {
|
||||||
case 'button':
|
case 'button':
|
||||||
case 'toggle':
|
case 'toggle': {
|
||||||
var $button;
|
let $button;
|
||||||
if ( tool.oouiIcon ) {
|
if ( tool.oouiIcon ) {
|
||||||
var config = {
|
const config = {
|
||||||
framed: false,
|
framed: false,
|
||||||
classes: [ 'tool' ],
|
classes: [ 'tool' ],
|
||||||
icon: tool.oouiIcon,
|
icon: tool.oouiIcon,
|
||||||
title: label
|
title: label
|
||||||
};
|
};
|
||||||
var oouiButton;
|
let oouiButton;
|
||||||
if ( tool.type === 'button' ) {
|
if ( tool.type === 'button' ) {
|
||||||
oouiButton = new OO.ui.ButtonWidget( config );
|
oouiButton = new OO.ui.ButtonWidget( config );
|
||||||
} else if ( tool.type === 'toggle' ) {
|
} else if ( tool.type === 'toggle' ) {
|
||||||
|
@ -308,7 +316,7 @@ var toolbarModule = {
|
||||||
} )
|
} )
|
||||||
.text( label );
|
.text( label );
|
||||||
if ( tool.icon ) {
|
if ( tool.icon ) {
|
||||||
var icon = $.wikiEditor.autoIcon(
|
const icon = $.wikiEditor.autoIcon(
|
||||||
tool.icon,
|
tool.icon,
|
||||||
$.wikiEditor.imgPath + 'toolbar/'
|
$.wikiEditor.imgPath + 'toolbar/'
|
||||||
);
|
);
|
||||||
|
@ -364,14 +372,15 @@ var toolbarModule = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $button;
|
return $button;
|
||||||
case 'select':
|
}
|
||||||
var menuId = 'menu-' + Date.now();
|
case 'select': {
|
||||||
var $select = $( '<div>' )
|
const menuId = 'menu-' + Date.now();
|
||||||
|
const $select = $( '<div>' )
|
||||||
.attr( { rel: id, class: 'tool tool-select' } );
|
.attr( { rel: id, class: 'tool tool-select' } );
|
||||||
var $options = $( '<div>' ).addClass( 'options' );
|
const $options = $( '<div>' ).addClass( 'options' );
|
||||||
if ( 'list' in tool ) {
|
if ( 'list' in tool ) {
|
||||||
for ( var option in tool.list ) {
|
for ( const option in tool.list ) {
|
||||||
var optionLabel = $.wikiEditor.autoMsg( tool.list[ option ], 'label' );
|
const optionLabel = $.wikiEditor.autoMsg( tool.list[ option ], 'label' );
|
||||||
$options.append(
|
$options.append(
|
||||||
$( '<a>' )
|
$( '<a>' )
|
||||||
.data( 'action', tool.list[ option ].action )
|
.data( 'action', tool.list[ option ].action )
|
||||||
|
@ -416,9 +425,9 @@ var toolbarModule = {
|
||||||
e.type === 'click' ||
|
e.type === 'click' ||
|
||||||
e.type === 'keydown' && e.key === 'Enter'
|
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
|
// 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 );
|
$opts.closest( '.tool-select' ).toggleClass( 'options-shown', canShowOptions );
|
||||||
$( this ).attr( 'aria-expanded', canShowOptions.toString() );
|
$( this ).attr( 'aria-expanded', canShowOptions.toString() );
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
@ -428,9 +437,10 @@ var toolbarModule = {
|
||||||
);
|
);
|
||||||
$select.append( $( '<div>' ).addClass( 'menu' ).append( $options ) );
|
$select.append( $( '<div>' ).addClass( 'menu' ).append( $options ) );
|
||||||
return $select;
|
return $select;
|
||||||
case 'element':
|
}
|
||||||
|
case 'element': {
|
||||||
// A raw 'element' type can be {htmlString|Element|Text|Array|jQuery|OO.ui.HTMLSnippet|function}.
|
// 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 ) {
|
if ( tool.element instanceof OO.ui.HtmlSnippet ) {
|
||||||
$element = tool.element.toString();
|
$element = tool.element.toString();
|
||||||
} else if ( typeof tool.element === 'function' ) {
|
} else if ( typeof tool.element === 'function' ) {
|
||||||
|
@ -441,12 +451,13 @@ var toolbarModule = {
|
||||||
return $( '<div>' )
|
return $( '<div>' )
|
||||||
.attr( { rel: id, class: 'tool tool-element' } )
|
.attr( { rel: id, class: 'tool tool-element' } )
|
||||||
.append( $element );
|
.append( $element );
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
buildBookmark: function ( context, id, page ) {
|
buildBookmark: function ( context, id, page ) {
|
||||||
var label = $.wikiEditor.autoMsg( page, 'label' );
|
const label = $.wikiEditor.autoMsg( page, 'label' );
|
||||||
return $( '<div>' )
|
return $( '<div>' )
|
||||||
.text( label )
|
.text( label )
|
||||||
.attr( {
|
.attr( {
|
||||||
|
@ -465,7 +476,7 @@ var toolbarModule = {
|
||||||
$( this )
|
$( this )
|
||||||
.addClass( 'current' )
|
.addClass( 'current' )
|
||||||
.siblings().removeClass( 'current' );
|
.siblings().removeClass( 'current' );
|
||||||
var section = $( this ).parent().parent().attr( 'rel' );
|
const section = $( this ).parent().parent().attr( 'rel' );
|
||||||
$.cookie(
|
$.cookie(
|
||||||
'wikiEditor-' + $( this ).data( 'context' ).instance + '-booklet-' + section + '-page',
|
'wikiEditor-' + $( this ).data( 'context' ).instance + '-booklet-' + section + '-page',
|
||||||
$( this ).attr( 'rel' ),
|
$( this ).attr( 'rel' ),
|
||||||
|
@ -477,7 +488,7 @@ var toolbarModule = {
|
||||||
} );
|
} );
|
||||||
},
|
},
|
||||||
buildPage: function ( context, id, page, deferLoad ) {
|
buildPage: function ( context, id, page, deferLoad ) {
|
||||||
var $page = $( '<div>' ).attr( {
|
const $page = $( '<div>' ).attr( {
|
||||||
class: 'page page-' + id,
|
class: 'page page-' + id,
|
||||||
rel: id
|
rel: id
|
||||||
} );
|
} );
|
||||||
|
@ -491,11 +502,11 @@ var toolbarModule = {
|
||||||
return $page;
|
return $page;
|
||||||
},
|
},
|
||||||
reallyBuildPage: function ( context, id, page, $page ) {
|
reallyBuildPage: function ( context, id, page, $page ) {
|
||||||
var i;
|
let i;
|
||||||
switch ( page.layout ) {
|
switch ( page.layout ) {
|
||||||
case 'table':
|
case 'table': {
|
||||||
$page.addClass( 'page-table' );
|
$page.addClass( 'page-table' );
|
||||||
var html = '';
|
let html = '';
|
||||||
if ( 'headings' in page ) {
|
if ( 'headings' in page ) {
|
||||||
html += toolbarModule.fn.buildHeading( context, page.headings );
|
html += toolbarModule.fn.buildHeading( context, page.headings );
|
||||||
}
|
}
|
||||||
|
@ -506,10 +517,11 @@ var toolbarModule = {
|
||||||
}
|
}
|
||||||
$page.html( '<table class="table-' + id + '">' + html + '</table>' );
|
$page.html( '<table class="table-' + id + '">' + html + '</table>' );
|
||||||
break;
|
break;
|
||||||
case 'characters':
|
}
|
||||||
|
case 'characters': {
|
||||||
$page.addClass( 'page-characters' );
|
$page.addClass( 'page-characters' );
|
||||||
var $characters = $( '<div>' ).data( 'context', context ).data( 'actions', {} );
|
const $characters = $( '<div>' ).data( 'context', context ).data( 'actions', {} );
|
||||||
var actions = $characters.data( 'actions' );
|
const actions = $characters.data( 'actions' );
|
||||||
if ( 'language' in page ) {
|
if ( 'language' in page ) {
|
||||||
$characters.attr( 'lang', page.language );
|
$characters.attr( 'lang', page.language );
|
||||||
}
|
}
|
||||||
|
@ -522,7 +534,7 @@ var toolbarModule = {
|
||||||
$characters.attr( 'dir', 'ltr' );
|
$characters.attr( 'dir', 'ltr' );
|
||||||
}
|
}
|
||||||
if ( 'characters' in page ) {
|
if ( 'characters' in page ) {
|
||||||
html = '';
|
let html = '';
|
||||||
for ( i = 0; i < page.characters.length; i++ ) {
|
for ( i = 0; i < page.characters.length; i++ ) {
|
||||||
html += toolbarModule.fn.buildCharacter( page.characters[ i ], actions );
|
html += toolbarModule.fn.buildCharacter( page.characters[ i ], actions );
|
||||||
}
|
}
|
||||||
|
@ -547,18 +559,19 @@ var toolbarModule = {
|
||||||
}
|
}
|
||||||
$page.append( $characters );
|
$page.append( $characters );
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
buildHeading: function ( context, headings ) {
|
buildHeading: function ( context, headings ) {
|
||||||
var html = '';
|
let html = '';
|
||||||
for ( var i = 0; i < headings.length; i++ ) {
|
for ( let i = 0; i < headings.length; i++ ) {
|
||||||
html += '<th>' + $.wikiEditor.autoSafeMsg( headings[ i ], [ 'html', 'text' ] ) + '</th>';
|
html += '<th>' + $.wikiEditor.autoSafeMsg( headings[ i ], [ 'html', 'text' ] ) + '</th>';
|
||||||
}
|
}
|
||||||
return '<tr>' + html + '</tr>';
|
return '<tr>' + html + '</tr>';
|
||||||
},
|
},
|
||||||
buildRow: function ( context, row ) {
|
buildRow: function ( context, row ) {
|
||||||
var html = '';
|
let html = '';
|
||||||
for ( var cell in row ) {
|
for ( const cell in row ) {
|
||||||
// FIXME: This currently needs to use the "unsafe" .text() message because it embeds raw HTML
|
// 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).
|
// in the messages (as used exclusively by the 'help' toolbar panel).
|
||||||
html += '<td class="cell cell-' + cell + '"><span>' +
|
html += '<td class="cell cell-' + cell + '"><span>' +
|
||||||
|
@ -595,7 +608,7 @@ var toolbarModule = {
|
||||||
if ( character && 'action' in character && 'label' in character ) {
|
if ( character && 'action' in character && 'label' in character ) {
|
||||||
actions[ character.label ] = character.action;
|
actions[ character.label ] = character.action;
|
||||||
// eslint-disable-next-line mediawiki/msg-doc
|
// 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(
|
return mw.html.element(
|
||||||
'span',
|
'span',
|
||||||
{ rel: character.label, title: title || false },
|
{ rel: character.label, title: title || false },
|
||||||
|
@ -607,12 +620,12 @@ var toolbarModule = {
|
||||||
return '';
|
return '';
|
||||||
},
|
},
|
||||||
buildTab: function ( context, id, section ) {
|
buildTab: function ( context, id, section ) {
|
||||||
var selected = $.cookie( 'wikiEditor-' + context.instance + '-toolbar-section' );
|
const selected = $.cookie( 'wikiEditor-' + context.instance + '-toolbar-section' );
|
||||||
// Re-save cookie
|
// Re-save cookie
|
||||||
if ( selected !== null ) {
|
if ( selected !== null ) {
|
||||||
$.cookie( 'wikiEditor-' + context.instance + '-toolbar-section', selected, { expires: 30, path: '/' } );
|
$.cookie( 'wikiEditor-' + context.instance + '-toolbar-section', selected, { expires: 30, path: '/' } );
|
||||||
}
|
}
|
||||||
var $link =
|
const $link =
|
||||||
$( '<a>' )
|
$( '<a>' )
|
||||||
.addClass( selected === id ? 'current' : null )
|
.addClass( selected === id ? 'current' : null )
|
||||||
.addClass( 'skin-invert' )
|
.addClass( 'skin-invert' )
|
||||||
|
@ -647,10 +660,10 @@ var toolbarModule = {
|
||||||
$( elem ).attr( 'aria-pressed', 'false' );
|
$( elem ).attr( 'aria-pressed', 'false' );
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
var $sections = $( this ).data( 'context' ).$ui.find( '.sections' );
|
const $sections = $( this ).data( 'context' ).$ui.find( '.sections' );
|
||||||
var $section = $sections.find( '.section-' + $( this ).parent().attr( 'rel' ) );
|
const $section = $sections.find( '.section-' + $( this ).parent().attr( 'rel' ) );
|
||||||
// eslint-disable-next-line no-jquery/no-class-state
|
// 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' )
|
$sections.find( '.section-visible' )
|
||||||
.removeClass( 'section-visible' )
|
.removeClass( 'section-visible' )
|
||||||
.addClass( 'section-hidden' );
|
.addClass( 'section-hidden' );
|
||||||
|
@ -686,13 +699,13 @@ var toolbarModule = {
|
||||||
.append( $link );
|
.append( $link );
|
||||||
},
|
},
|
||||||
buildSection: function ( context, id, section ) {
|
buildSection: function ( context, id, section ) {
|
||||||
var $section = $( '<div>' ).attr( {
|
const $section = $( '<div>' ).attr( {
|
||||||
class: section.type + ' section section-' + id,
|
class: section.type + ' section section-' + id,
|
||||||
rel: id,
|
rel: id,
|
||||||
id: 'wikiEditor-section-' + id
|
id: 'wikiEditor-section-' + id
|
||||||
} );
|
} );
|
||||||
var selected = $.cookie( 'wikiEditor-' + context.instance + '-toolbar-section' );
|
const selected = $.cookie( 'wikiEditor-' + context.instance + '-toolbar-section' );
|
||||||
var show = selected === id;
|
const show = selected === id;
|
||||||
|
|
||||||
toolbarModule.fn.reallyBuildSection( context, id, section, $section, section.deferLoad );
|
toolbarModule.fn.reallyBuildSection( context, id, section, $section, section.deferLoad );
|
||||||
|
|
||||||
|
@ -707,29 +720,30 @@ var toolbarModule = {
|
||||||
reallyBuildSection: function ( context, id, section, $section, deferLoad ) {
|
reallyBuildSection: function ( context, id, section, $section, deferLoad ) {
|
||||||
context.$textarea.trigger( 'wikiEditor-toolbar-buildSection-' + $section.attr( 'rel' ), [ section ] );
|
context.$textarea.trigger( 'wikiEditor-toolbar-buildSection-' + $section.attr( 'rel' ), [ section ] );
|
||||||
switch ( section.type ) {
|
switch ( section.type ) {
|
||||||
case 'toolbar':
|
case 'toolbar': {
|
||||||
if ( 'groups' in section ) {
|
if ( 'groups' in section ) {
|
||||||
for ( var group in section.groups ) {
|
for ( const group in section.groups ) {
|
||||||
$section.append(
|
$section.append(
|
||||||
toolbarModule.fn.buildGroup( context, group, section.groups[ group ] )
|
toolbarModule.fn.buildGroup( context, group, section.groups[ group ] )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'booklet':
|
}
|
||||||
var $pages = $( '<div>' )
|
case 'booklet': {
|
||||||
|
const $pages = $( '<div>' )
|
||||||
.addClass( 'pages' )
|
.addClass( 'pages' )
|
||||||
.attr( {
|
.attr( {
|
||||||
tabindex: '0',
|
tabindex: '0',
|
||||||
role: 'listbox'
|
role: 'listbox'
|
||||||
} )
|
} )
|
||||||
.on( 'keydown', ( event ) => {
|
.on( 'keydown', ( event ) => {
|
||||||
var $selected = $pages.children().filter( function () {
|
const $selected = $pages.children().filter( function () {
|
||||||
return $( this ).css( 'display' ) !== 'none';
|
return $( this ).css( 'display' ) !== 'none';
|
||||||
} );
|
} );
|
||||||
$.wikiEditor.modules.toolbar.fn.handleKeyDown( $selected.children().first(), event, $pages );
|
$.wikiEditor.modules.toolbar.fn.handleKeyDown( $selected.children().first(), event, $pages );
|
||||||
} );
|
} );
|
||||||
var $index = $( '<div>' )
|
const $index = $( '<div>' )
|
||||||
.addClass( 'index' )
|
.addClass( 'index' )
|
||||||
.attr( {
|
.attr( {
|
||||||
tabindex: '0',
|
tabindex: '0',
|
||||||
|
@ -739,7 +753,7 @@ var toolbarModule = {
|
||||||
$.wikiEditor.modules.toolbar.fn.handleKeyDown( $index, event, $index );
|
$.wikiEditor.modules.toolbar.fn.handleKeyDown( $index, event, $index );
|
||||||
} );
|
} );
|
||||||
if ( 'pages' in section ) {
|
if ( 'pages' in section ) {
|
||||||
for ( var page in section.pages ) {
|
for ( const page in section.pages ) {
|
||||||
$pages.append(
|
$pages.append(
|
||||||
toolbarModule.fn.buildPage( context, page, section.pages[ page ], deferLoad )
|
toolbarModule.fn.buildPage( context, page, section.pages[ page ], deferLoad )
|
||||||
);
|
);
|
||||||
|
@ -751,16 +765,17 @@ var toolbarModule = {
|
||||||
$section.append( $index, $pages );
|
$section.append( $index, $pages );
|
||||||
toolbarModule.fn.updateBookletSelection( context, id, $pages, $index );
|
toolbarModule.fn.updateBookletSelection( context, id, $pages, $index );
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
updateBookletSelection: function ( context, id, $pages, $index ) {
|
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 );
|
selected = $.cookie( cookie );
|
||||||
// Re-save cookie
|
// Re-save cookie
|
||||||
if ( selected !== null ) {
|
if ( selected !== null ) {
|
||||||
$.cookie( cookie, selected, { expires: 30, path: '/' } );
|
$.cookie( cookie, selected, { expires: 30, path: '/' } );
|
||||||
}
|
}
|
||||||
var $selectedIndex = $index.find( '*[rel="' + selected + '"]' );
|
let $selectedIndex = $index.find( '*[rel="' + selected + '"]' );
|
||||||
if ( $selectedIndex.length === 0 ) {
|
if ( $selectedIndex.length === 0 ) {
|
||||||
$selectedIndex = $index.children().eq( 0 );
|
$selectedIndex = $index.children().eq( 0 );
|
||||||
selected = $selectedIndex.attr( 'rel' );
|
selected = $selectedIndex.attr( 'rel' );
|
||||||
|
@ -771,10 +786,10 @@ var toolbarModule = {
|
||||||
$selectedIndex.addClass( 'current' );
|
$selectedIndex.addClass( 'current' );
|
||||||
},
|
},
|
||||||
build: function ( context, config ) {
|
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 );
|
$sections = $( '<div>' ).addClass( 'sections' ).appendTo( context.modules.toolbar.$toolbar );
|
||||||
context.modules.toolbar.$toolbar.append( $( '<div>' ).css( 'clear', 'both' ) );
|
context.modules.toolbar.$toolbar.append( $( '<div>' ).css( 'clear', 'both' ) );
|
||||||
for ( var section in config ) {
|
for ( const section in config ) {
|
||||||
if ( section === 'main' || section === 'secondary' ) {
|
if ( section === 'main' || section === 'secondary' ) {
|
||||||
context.modules.toolbar.$toolbar.prepend(
|
context.modules.toolbar.$toolbar.prepend(
|
||||||
toolbarModule.fn.buildSection( context, section, config[ section ] )
|
toolbarModule.fn.buildSection( context, section, config[ section ] )
|
||||||
|
@ -793,13 +808,13 @@ var toolbarModule = {
|
||||||
},
|
},
|
||||||
ctrlShortcuts: {},
|
ctrlShortcuts: {},
|
||||||
setupShortcuts: function ( context ) {
|
setupShortcuts: function ( context ) {
|
||||||
var platform = $.client.profile().platform;
|
const platform = $.client.profile().platform;
|
||||||
var platformModifier = platform === 'mac' ? 'metaKey' : 'ctrlKey';
|
const platformModifier = platform === 'mac' ? 'metaKey' : 'ctrlKey';
|
||||||
var otherModifier = platform === 'mac' ? 'ctrlKey' : 'metaKey';
|
const otherModifier = platform === 'mac' ? 'ctrlKey' : 'metaKey';
|
||||||
|
|
||||||
context.$textarea.on( 'keydown', ( e ) => {
|
context.$textarea.on( 'keydown', ( e ) => {
|
||||||
// Check if the primary modifier key is pressed and that others aren't
|
// 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 ];
|
toolbarModule.fn.ctrlShortcuts[ e.which ];
|
||||||
if ( target ) {
|
if ( target ) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
@ -808,12 +823,12 @@ var toolbarModule = {
|
||||||
} );
|
} );
|
||||||
},
|
},
|
||||||
handleKeyDown: function ( $element, event, $parent ) {
|
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(),
|
optionOffset = $parent.find( '.wikiEditor-character-highlighted' ).offset(),
|
||||||
optionTop = optionOffset ? optionOffset.top : 0,
|
optionTop = optionOffset ? optionOffset.top : 0,
|
||||||
selectTop = $parent.offset().top;
|
selectTop = $parent.offset().top;
|
||||||
|
|
||||||
var $nextItem;
|
let $nextItem;
|
||||||
switch ( event.keyCode ) {
|
switch ( event.keyCode ) {
|
||||||
// Up arrow
|
// Up arrow
|
||||||
case 38:
|
case 38:
|
||||||
|
|
|
@ -10,8 +10,8 @@ function ErrorLayout( config ) {
|
||||||
config = config || {};
|
config = config || {};
|
||||||
ErrorLayout.super.call( this, config );
|
ErrorLayout.super.call( this, config );
|
||||||
|
|
||||||
var $image = $( '<div>' ).addClass( 'ext-WikiEditor-image-realtimepreview-error' );
|
const $image = $( '<div>' ).addClass( 'ext-WikiEditor-image-realtimepreview-error' );
|
||||||
var $title = $( '<h3>' ).text( mw.msg( 'wikieditor-realtimepreview-error' ) );
|
const $title = $( '<h3>' ).text( mw.msg( 'wikieditor-realtimepreview-error' ) );
|
||||||
this.$message = $( '<div>' ).addClass( 'ext-WikiEditor-realtimepreview-error-msg' );
|
this.$message = $( '<div>' ).addClass( 'ext-WikiEditor-realtimepreview-error-msg' );
|
||||||
this.reloadButton = new OO.ui.ButtonWidget( {
|
this.reloadButton = new OO.ui.ButtonWidget( {
|
||||||
icon: 'reload',
|
icon: 'reload',
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* @param {OO.ui.ButtonWidget} reloadHoverButton
|
* @param {OO.ui.ButtonWidget} reloadHoverButton
|
||||||
*/
|
*/
|
||||||
function ManualWidget( realtimePreview, reloadHoverButton ) {
|
function ManualWidget( realtimePreview, reloadHoverButton ) {
|
||||||
var config = {
|
const config = {
|
||||||
classes: [ 'ext-WikiEditor-ManualWidget' ],
|
classes: [ 'ext-WikiEditor-ManualWidget' ],
|
||||||
$element: $( '<a>' )
|
$element: $( '<a>' )
|
||||||
};
|
};
|
||||||
|
@ -25,9 +25,9 @@ function ManualWidget( realtimePreview, reloadHoverButton ) {
|
||||||
this.reloadHoverButton = reloadHoverButton;
|
this.reloadHoverButton = reloadHoverButton;
|
||||||
|
|
||||||
// UI elements.
|
// UI elements.
|
||||||
var $reloadLabel = $( '<span>' )
|
const $reloadLabel = $( '<span>' )
|
||||||
.text( mw.msg( 'wikieditor-realtimepreview-manual' ) );
|
.text( mw.msg( 'wikieditor-realtimepreview-manual' ) );
|
||||||
var $reloadButton = $( '<span>' )
|
const $reloadButton = $( '<span>' )
|
||||||
.addClass( 'ext-WikiEditor-realtimepreview-manual-reload' )
|
.addClass( 'ext-WikiEditor-realtimepreview-manual-reload' )
|
||||||
.text( mw.msg( 'wikieditor-realtimepreview-reload' ) );
|
.text( mw.msg( 'wikieditor-realtimepreview-reload' ) );
|
||||||
this.connect( realtimePreview, {
|
this.connect( realtimePreview, {
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
var ResizingDragBar = require( './ResizingDragBar.js' );
|
const ResizingDragBar = require( './ResizingDragBar.js' );
|
||||||
var TwoPaneLayout = require( './TwoPaneLayout.js' );
|
const TwoPaneLayout = require( './TwoPaneLayout.js' );
|
||||||
var ErrorLayout = require( './ErrorLayout.js' );
|
const ErrorLayout = require( './ErrorLayout.js' );
|
||||||
var ManualWidget = require( './ManualWidget.js' );
|
const ManualWidget = require( './ManualWidget.js' );
|
||||||
var localStorage = require( 'mediawiki.storage' ).local;
|
const localStorage = require( 'mediawiki.storage' ).local;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class
|
* @class
|
||||||
|
@ -18,7 +18,7 @@ function RealtimePreview() {
|
||||||
// @todo This shouldn't be required, but the preview element is added in PHP
|
// @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 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.
|
// 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>' )
|
this.$previewNode = $( '<div>' )
|
||||||
.addClass( 'ext-WikiEditor-realtimepreview-preview' )
|
.addClass( 'ext-WikiEditor-realtimepreview-preview' )
|
||||||
.attr( 'tabindex', '1' ) // T317108
|
.attr( 'tabindex', '1' ) // T317108
|
||||||
|
@ -80,16 +80,16 @@ function RealtimePreview() {
|
||||||
*/
|
*/
|
||||||
RealtimePreview.prototype.getToolbarButton = function ( context ) {
|
RealtimePreview.prototype.getToolbarButton = function ( context ) {
|
||||||
this.context = 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.
|
// 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' );
|
$uiText.css( 'height', height + 'px' );
|
||||||
context.$textarea.removeAttr( 'rows cols' );
|
context.$textarea.removeAttr( 'rows cols' );
|
||||||
context.$textarea.addClass( 'ext-WikiEditor-realtimepreview-textbox' );
|
context.$textarea.addClass( 'ext-WikiEditor-realtimepreview-textbox' );
|
||||||
|
|
||||||
// Add the resizing bar.
|
// Add the resizing bar.
|
||||||
var bottomDragBar = new ResizingDragBar( { isEW: false } );
|
const bottomDragBar = new ResizingDragBar( { isEW: false } );
|
||||||
$uiText.after( bottomDragBar.$element );
|
$uiText.after( bottomDragBar.$element );
|
||||||
|
|
||||||
// Create and configure the toolbar button.
|
// Create and configure the toolbar button.
|
||||||
|
@ -156,13 +156,13 @@ RealtimePreview.prototype.saveUserPref = function () {
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
RealtimePreview.prototype.toggle = function ( saveUserPref ) {
|
RealtimePreview.prototype.toggle = function ( saveUserPref ) {
|
||||||
var $uiText = this.context.$ui.find( '.wikiEditor-ui-text' );
|
const $uiText = this.context.$ui.find( '.wikiEditor-ui-text' );
|
||||||
var $textarea = this.context.$textarea;
|
const $textarea = this.context.$textarea;
|
||||||
var $form = $textarea.parents( 'form' );
|
const $form = $textarea.parents( 'form' );
|
||||||
|
|
||||||
// Save the current cursor selection and focused element.
|
// Save the current cursor selection and focused element.
|
||||||
var cursorPos = $textarea.textSelection( 'getCaretPosition', { startAndEnd: true } );
|
const cursorPos = $textarea.textSelection( 'getCaretPosition', { startAndEnd: true } );
|
||||||
var focusedElement = document.activeElement;
|
const focusedElement = document.activeElement;
|
||||||
|
|
||||||
// Remove or add the layout to the DOM.
|
// Remove or add the layout to the DOM.
|
||||||
if ( this.enabled ) {
|
if ( this.enabled ) {
|
||||||
|
@ -254,8 +254,8 @@ RealtimePreview.prototype.isScreenWideEnough = function () {
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
RealtimePreview.prototype.enableFeatureWhenScreenIsWideEnough = function () {
|
RealtimePreview.prototype.enableFeatureWhenScreenIsWideEnough = function () {
|
||||||
var previewButtonIsVisible = this.button.isVisible();
|
const previewButtonIsVisible = this.button.isVisible();
|
||||||
var isScreenWideEnough = this.isScreenWideEnough();
|
const isScreenWideEnough = this.isScreenWideEnough();
|
||||||
if ( !isScreenWideEnough && previewButtonIsVisible ) {
|
if ( !isScreenWideEnough && previewButtonIsVisible ) {
|
||||||
this.button.toggle( false );
|
this.button.toggle( false );
|
||||||
this.reloadButton.setDisabled( true );
|
this.reloadButton.setDisabled( true );
|
||||||
|
@ -301,7 +301,7 @@ RealtimePreview.prototype.checkResponseTimes = function ( time ) {
|
||||||
return;
|
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 ) {
|
if ( ( totalResponseTime / this.responseTimes.length ) > this.configData.realtimeDisableDuration ) {
|
||||||
this.inManualMode = true;
|
this.inManualMode = true;
|
||||||
|
@ -325,8 +325,8 @@ RealtimePreview.prototype.doRealtimePreview = function ( forceUpdate ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var $textareaNode = $( '#wpTextbox1' );
|
const $textareaNode = $( '#wpTextbox1' );
|
||||||
var wikitext = $textareaNode.textSelection( 'getContents' );
|
const wikitext = $textareaNode.textSelection( 'getContents' );
|
||||||
if ( !forceUpdate && wikitext === this.lastWikitext ) {
|
if ( !forceUpdate && wikitext === this.lastWikitext ) {
|
||||||
// Wikitext unchanged, no update necessary
|
// Wikitext unchanged, no update necessary
|
||||||
return;
|
return;
|
||||||
|
@ -339,14 +339,14 @@ RealtimePreview.prototype.doRealtimePreview = function ( forceUpdate ) {
|
||||||
this.reloadButton.setDisabled( true );
|
this.reloadButton.setDisabled( true );
|
||||||
this.manualWidget.setDisabled( true );
|
this.manualWidget.setDisabled( true );
|
||||||
this.errorLayout.toggle( false );
|
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.$previewNode below is a clone of #wikiPreview with a different selector!
|
||||||
// config.$diffNode defaults to #wikiDiff but is disabled below and never updated.
|
// config.$diffNode defaults to #wikiDiff but is disabled below and never updated.
|
||||||
.filter( ( selector ) => selector.indexOf( '#wiki' ) !== 0 );
|
.filter( ( selector ) => selector.indexOf( '#wiki' ) !== 0 );
|
||||||
loadingSelectors.push( '.ext-WikiEditor-realtimepreview-preview' );
|
loadingSelectors.push( '.ext-WikiEditor-realtimepreview-preview' );
|
||||||
loadingSelectors.push( '.ext-WikiEditor-ManualWidget' );
|
loadingSelectors.push( '.ext-WikiEditor-ManualWidget' );
|
||||||
loadingSelectors.push( '.ext-WikiEditor-realtimepreview-ErrorLayout' );
|
loadingSelectors.push( '.ext-WikiEditor-realtimepreview-ErrorLayout' );
|
||||||
var time = Date.now();
|
const time = Date.now();
|
||||||
|
|
||||||
this.pagePreview.doPreview( {
|
this.pagePreview.doPreview( {
|
||||||
$textareaNode: $textareaNode,
|
$textareaNode: $textareaNode,
|
||||||
|
|
|
@ -12,15 +12,15 @@ function ResizingDragBar( config ) {
|
||||||
}, config );
|
}, config );
|
||||||
ResizingDragBar.super.call( this, 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:
|
// Possible class names:
|
||||||
// * ext-WikiEditor-ResizingDragBar-ew
|
// * ext-WikiEditor-ResizingDragBar-ew
|
||||||
// * ext-WikiEditor-ResizingDragBar-ns
|
// * ext-WikiEditor-ResizingDragBar-ns
|
||||||
this.$element.addClass( classNameDir );
|
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).
|
// 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 ) => {
|
this.$element.on( 'mousedown', ( eventMousedown ) => {
|
||||||
if ( eventMousedown.button !== ResizingDragBar.static.MAIN_MOUSE_BUTTON ) {
|
if ( eventMousedown.button !== ResizingDragBar.static.MAIN_MOUSE_BUTTON ) {
|
||||||
// If not the main mouse (e.g. left) button, ignore.
|
// 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.
|
// Prevent selecting (or anything else) when dragging over other parts of the page.
|
||||||
$( document ).on( 'selectstart.' + classNameDir, false );
|
$( document ).on( 'selectstart.' + classNameDir, false );
|
||||||
// Set up parameter names.
|
// Set up parameter names.
|
||||||
var xOrY = config.isEW ? 'pageX' : 'pageY';
|
const xOrY = config.isEW ? 'pageX' : 'pageY';
|
||||||
var widthOrHeight = config.isEW ? 'width' : 'height';
|
const widthOrHeight = config.isEW ? 'width' : 'height';
|
||||||
var lastOffset = eventMousedown[ xOrY ];
|
let lastOffset = eventMousedown[ xOrY ];
|
||||||
// Handle the actual dragging.
|
// Handle the actual dragging.
|
||||||
$( document ).on( 'mousemove.' + classNameDir, ( eventMousemove ) => {
|
$( document ).on( 'mousemove.' + classNameDir, ( eventMousemove ) => {
|
||||||
// Initial width or height of the pane.
|
// 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).
|
// Current position of the mouse (relative to page, not viewport).
|
||||||
var newOffset = eventMousemove[ xOrY ];
|
const newOffset = eventMousemove[ xOrY ];
|
||||||
// Distance the mouse has moved.
|
// 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.
|
// 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 );
|
resizingDragBar.getResizedPane().css( widthOrHeight, newSize );
|
||||||
// Save the new starting point of the mouse, from which to calculate the next move.
|
// Save the new starting point of the mouse, from which to calculate the next move.
|
||||||
lastOffset = newOffset;
|
lastOffset = newOffset;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
var ResizingDragBar = require( './ResizingDragBar.js' );
|
const ResizingDragBar = require( './ResizingDragBar.js' );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a layout with two resizable panes.
|
* This is a layout with two resizable panes.
|
||||||
|
@ -14,7 +14,7 @@ function TwoPaneLayout( config ) {
|
||||||
TwoPaneLayout.super.call( this, config );
|
TwoPaneLayout.super.call( this, config );
|
||||||
|
|
||||||
this.$pane1 = $( '<div>' ).addClass( 'ext-WikiEditor-twopanes-pane1' );
|
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.$pane2 = $( '<div>' ).addClass( 'ext-WikiEditor-twopanes-pane2' );
|
||||||
|
|
||||||
this.$element.addClass( 'ext-WikiEditor-twopanes-TwoPaneLayout' );
|
this.$element.addClass( 'ext-WikiEditor-twopanes-TwoPaneLayout' );
|
||||||
|
|
|
@ -6,8 +6,8 @@ mw.hook( 'wikiEditor.toolbarReady' ).add( function ( $textarea ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var RealtimePreview = require( './RealtimePreview.js' );
|
const RealtimePreview = require( './RealtimePreview.js' );
|
||||||
var realtimePreview = new RealtimePreview();
|
const realtimePreview = new RealtimePreview();
|
||||||
$textarea.wikiEditor( 'addToToolbar', {
|
$textarea.wikiEditor( 'addToToolbar', {
|
||||||
section: 'secondary',
|
section: 'secondary',
|
||||||
group: 'default',
|
group: 'default',
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
QUnit.module( 'ext.wikiEditor.toolbar', ( hooks ) => {
|
QUnit.module( 'ext.wikiEditor.toolbar', ( hooks ) => {
|
||||||
hooks.beforeEach( function () {
|
hooks.beforeEach( function () {
|
||||||
var $target = $( '<textarea>' )
|
const $target = $( '<textarea>' )
|
||||||
.attr( 'id', 'wpTextBox1' )
|
.attr( 'id', 'wpTextBox1' )
|
||||||
.appendTo( '#qunit-fixture' );
|
.appendTo( '#qunit-fixture' );
|
||||||
this.$target = $target;
|
this.$target = $target;
|
||||||
|
@ -10,7 +10,7 @@ QUnit.module( 'ext.wikiEditor.toolbar', ( hooks ) => {
|
||||||
|
|
||||||
QUnit.test( 'Toolbars', function ( assert ) {
|
QUnit.test( 'Toolbars', function ( assert ) {
|
||||||
// Add toolbar section
|
// Add toolbar section
|
||||||
var data = {
|
let data = {
|
||||||
sections: {
|
sections: {
|
||||||
emoticons: {
|
emoticons: {
|
||||||
type: 'toolbar',
|
type: 'toolbar',
|
||||||
|
@ -141,7 +141,7 @@ QUnit.module( 'ext.wikiEditor.toolbar', ( hooks ) => {
|
||||||
|
|
||||||
QUnit.test( 'Booklets', function ( assert ) {
|
QUnit.test( 'Booklets', function ( assert ) {
|
||||||
// Add booklet section
|
// Add booklet section
|
||||||
var data = {
|
let data = {
|
||||||
sections: {
|
sections: {
|
||||||
info: {
|
info: {
|
||||||
type: 'booklet',
|
type: 'booklet',
|
||||||
|
|
Loading…
Reference in a new issue