mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-24 22:35:41 +00:00
3f0f302577
Previously, the ve-mw/init/ directory contained two kinds of files: those that were used when initializing VE, and those that may be loaded even if VE is not going to be initialized at all. The latter kind must not use the `ve` global variable. After moving those files to ve-mw/preinit/ we can enforce this with .eslintrc.json in that directory. This would have prevented T228684. (Technically they merely must not use `ve.init`, and may use `ve`, but that's harder to enforce. We should instead move the few non-init methods out of `ve`: now, track, trackSubscribe, trackSubscribeAll). Also, group some files under ve-mw/init/: targets/ now (only) contains ve.init.mw.Target and its subclasses, apiresponsecache/ now contains ve.init.mw.ApiResponseCache and its subclasses. Bug: T228684 Change-Id: I945249a27f6a0fa10a432d5c5dc57bc7e0461fd8
104 lines
2.5 KiB
JavaScript
104 lines
2.5 KiB
JavaScript
/*!
|
|
* VisualEditor MediaWiki temporary wikitext editor widget
|
|
*
|
|
* @copyright 2011-2019 VisualEditor Team and others; see AUTHORS.txt
|
|
* @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.
|
|
*
|
|
* It has a similar API to OO.ui.TextInputWidget, but is designed to
|
|
* be loaded before any core VE code or dependencies, e.g. OOUI.
|
|
*
|
|
* @class
|
|
*
|
|
* @constructor
|
|
* @param {Object} [config] Configuration options
|
|
* @cfg {string} [value] Initial value
|
|
*/
|
|
mw.libs.ve.MWTempWikitextEditorWidget = function VeUiMwTempWikitextEditorWidget( config ) {
|
|
var conf = mw.config.get( 'wgVisualEditor' ),
|
|
dir = conf.pageLanguageDir,
|
|
lang = conf.pageLanguageCode;
|
|
|
|
config = config || {};
|
|
|
|
this.$element = $( '<textarea>' )
|
|
.addClass( 've-init-mw-tempWikitextEditorWidget ' )
|
|
.addClass( 'mw-editfont-' + mw.user.options.get( 'editfont' ) )
|
|
.addClass( 'mw-content-' + dir )
|
|
.attr( {
|
|
lang: lang,
|
|
dir: dir
|
|
} )
|
|
.val( config.value );
|
|
};
|
|
|
|
/**
|
|
* Focus the input and move the cursor to the start.
|
|
*
|
|
* @return {mw.libs.ve.MWTempWikitextEditorWidget}
|
|
* @chainable
|
|
*/
|
|
mw.libs.ve.MWTempWikitextEditorWidget.prototype.moveCursorToStart = function () {
|
|
// Move cursor to start
|
|
this.$element[ 0 ].setSelectionRange( 0, 0 );
|
|
this.focus();
|
|
return this;
|
|
};
|
|
|
|
/**
|
|
* Expand the height of the text to fit the contents
|
|
*
|
|
* @return {mw.libs.ve.MWTempWikitextEditorWidget}
|
|
* @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
|
|
*
|
|
* @return {mw.libs.ve.MWTempWikitextEditorWidget}
|
|
* @chainable
|
|
*/
|
|
mw.libs.ve.MWTempWikitextEditorWidget.prototype.focus = function () {
|
|
this.$element[ 0 ].focus();
|
|
return this;
|
|
};
|
|
|
|
/**
|
|
* Get the input value
|
|
*
|
|
* @return {string} Value
|
|
*/
|
|
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
|
|
};
|
|
};
|