2017-10-18 22:50:31 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor MediaWiki temporary wikitext editor widget
|
|
|
|
*
|
2023-12-01 16:06:11 +00:00
|
|
|
* @copyright See AUTHORS.txt
|
2017-10-18 22:50:31 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
mw.libs.ve = mw.libs.ve || {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MediaWiki temporary wikitext editor widget
|
|
|
|
*
|
|
|
|
* This widget can be used to show the user a basic editing interface
|
|
|
|
* while VE libraries are still loading.
|
|
|
|
*
|
2021-06-08 08:52:38 +00:00
|
|
|
* It has a similar API to OO.ui.InputWidget, but is designed to
|
2017-10-18 22:50:31 +00:00
|
|
|
* be loaded before any core VE code or dependencies, e.g. OOUI.
|
|
|
|
*
|
|
|
|
* @class
|
2019-04-16 15:17:29 +00:00
|
|
|
*
|
2017-10-18 22:50:31 +00:00
|
|
|
* @constructor
|
2021-06-08 08:52:38 +00:00
|
|
|
* @param {Object} config Configuration options
|
|
|
|
* @cfg {string} value Raw wikitext to edit
|
2017-10-18 22:50:31 +00:00
|
|
|
*/
|
|
|
|
mw.libs.ve.MWTempWikitextEditorWidget = function VeUiMwTempWikitextEditorWidget( config ) {
|
|
|
|
var conf = mw.config.get( 'wgVisualEditor' ),
|
|
|
|
dir = conf.pageLanguageDir,
|
|
|
|
lang = conf.pageLanguageCode;
|
|
|
|
|
|
|
|
this.$element = $( '<textarea>' )
|
|
|
|
.addClass( 've-init-mw-tempWikitextEditorWidget ' )
|
2020-04-09 13:33:54 +00:00
|
|
|
// The following classes are used here:
|
|
|
|
// * mw-editfont-monospace
|
|
|
|
// * mw-editfont-sans-serif
|
|
|
|
// * mw-editfont-serif
|
2017-10-18 22:50:31 +00:00
|
|
|
.addClass( 'mw-editfont-' + mw.user.options.get( 'editfont' ) )
|
2020-04-09 13:33:54 +00:00
|
|
|
// The following classes are used here:
|
|
|
|
// * mw-content-ltr
|
|
|
|
// * mw-content-rtl
|
2017-10-18 22:50:31 +00:00
|
|
|
.addClass( 'mw-content-' + dir )
|
|
|
|
.attr( {
|
|
|
|
lang: lang,
|
|
|
|
dir: dir
|
|
|
|
} )
|
2018-01-23 20:51:11 +00:00
|
|
|
.val( config.value );
|
2018-01-22 00:49:49 +00:00
|
|
|
};
|
2017-10-18 22:50:31 +00:00
|
|
|
|
2018-01-22 00:49:49 +00:00
|
|
|
/**
|
|
|
|
* Focus the input and move the cursor to the start.
|
|
|
|
*
|
2019-04-16 15:17:29 +00:00
|
|
|
* @return {mw.libs.ve.MWTempWikitextEditorWidget}
|
2018-01-22 00:49:49 +00:00
|
|
|
* @chainable
|
|
|
|
*/
|
|
|
|
mw.libs.ve.MWTempWikitextEditorWidget.prototype.moveCursorToStart = function () {
|
2017-10-18 22:50:31 +00:00
|
|
|
// Move cursor to start
|
|
|
|
this.$element[ 0 ].setSelectionRange( 0, 0 );
|
2018-01-22 00:49:49 +00:00
|
|
|
this.focus();
|
|
|
|
return this;
|
2017-10-18 22:50:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Expand the height of the text to fit the contents
|
|
|
|
*
|
2019-04-16 15:17:29 +00:00
|
|
|
* @return {mw.libs.ve.MWTempWikitextEditorWidget}
|
2017-10-18 22:50:31 +00:00
|
|
|
* @chainable
|
|
|
|
*/
|
|
|
|
mw.libs.ve.MWTempWikitextEditorWidget.prototype.adjustSize = function () {
|
|
|
|
// Don't bother with reducing height for simplicity
|
|
|
|
this.$element.height( this.$element[ 0 ].scrollHeight );
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Focus the input
|
|
|
|
*
|
2019-04-16 15:17:29 +00:00
|
|
|
* @return {mw.libs.ve.MWTempWikitextEditorWidget}
|
2017-10-18 22:50:31 +00:00
|
|
|
* @chainable
|
|
|
|
*/
|
|
|
|
mw.libs.ve.MWTempWikitextEditorWidget.prototype.focus = function () {
|
|
|
|
this.$element[ 0 ].focus();
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2021-06-08 08:52:38 +00:00
|
|
|
* @return {string} Raw, possibly edited wikitext
|
2017-10-18 22:50:31 +00:00
|
|
|
*/
|
|
|
|
mw.libs.ve.MWTempWikitextEditorWidget.prototype.getValue = function () {
|
|
|
|
return this.$element.val();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the selection range
|
|
|
|
*
|
|
|
|
* @return {Object} Object containing numbers 'from' and 'to'
|
|
|
|
*/
|
|
|
|
mw.libs.ve.MWTempWikitextEditorWidget.prototype.getRange = function () {
|
|
|
|
var input = this.$element[ 0 ],
|
|
|
|
start = input.selectionStart,
|
|
|
|
end = input.selectionEnd,
|
|
|
|
isBackwards = input.selectionDirection === 'backward';
|
|
|
|
|
|
|
|
return {
|
|
|
|
from: isBackwards ? end : start,
|
|
|
|
to: isBackwards ? start : end
|
|
|
|
};
|
|
|
|
};
|