2017-02-24 14:29:21 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor MediaWiki edit mode tool classes.
|
|
|
|
*
|
2020-01-08 17:13:04 +00:00
|
|
|
* @copyright 2011-2020 VisualEditor Team and others; see AUTHORS.txt
|
2017-02-24 14:29:21 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
mw.libs.ve = mw.libs.ve || {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MediaWiki edit mode tool.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @abstract
|
|
|
|
* @extends OO.ui.Tool
|
|
|
|
* @constructor
|
|
|
|
* @param {OO.ui.ToolGroup} toolGroup
|
|
|
|
* @param {Object} [config] Config options
|
|
|
|
*/
|
|
|
|
mw.libs.ve.MWEditModeTool = function VeUiMWEditModeTool() {
|
|
|
|
// Parent constructor
|
|
|
|
mw.libs.ve.MWEditModeTool.super.apply( this, arguments );
|
|
|
|
|
|
|
|
this.modeAvailable = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( mw.libs.ve.MWEditModeTool, OO.ui.Tool );
|
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
|
|
|
mw.libs.ve.MWEditModeTool.static.editMode = null;
|
|
|
|
|
|
|
|
mw.libs.ve.MWEditModeTool.static.group = 'editMode';
|
|
|
|
|
|
|
|
mw.libs.ve.MWEditModeTool.static.autoAddToCatchall = false;
|
|
|
|
|
|
|
|
mw.libs.ve.MWEditModeTool.static.autoAddToGroup = false;
|
|
|
|
|
|
|
|
mw.libs.ve.MWEditModeTool.static.unavailableTooltip = null;
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Switch editors
|
|
|
|
*/
|
|
|
|
mw.libs.ve.MWEditModeTool.prototype.switch = function () {
|
2017-02-28 23:07:54 +00:00
|
|
|
this.toolbar.emit( 'switchEditor', this.constructor.static.editMode );
|
2017-02-24 14:29:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get current edit mode
|
|
|
|
*
|
|
|
|
* @return {string} Current edit mode
|
|
|
|
*/
|
|
|
|
mw.libs.ve.MWEditModeTool.prototype.getMode = function () {
|
|
|
|
return 'source';
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if edit mode is available
|
|
|
|
*
|
|
|
|
* @param {string} Edit mode
|
|
|
|
* @return {boolean} Edit mode is available
|
|
|
|
*/
|
|
|
|
mw.libs.ve.MWEditModeTool.prototype.isModeAvailable = function () {
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
mw.libs.ve.MWEditModeTool.prototype.onSelect = function () {
|
|
|
|
if ( this.getMode() !== this.constructor.static.editMode ) {
|
|
|
|
this.switch();
|
|
|
|
}
|
2017-04-26 17:50:10 +00:00
|
|
|
this.setActive( this.getMode() === this.constructor.static.editMode );
|
2017-02-24 14:29:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
mw.libs.ve.MWEditModeTool.prototype.onUpdateState = function () {
|
2017-04-26 17:50:10 +00:00
|
|
|
var modeAvailable = this.isModeAvailable( this.constructor.static.editMode );
|
2017-02-24 14:29:21 +00:00
|
|
|
|
|
|
|
// Change title if state has changed
|
2017-04-26 17:50:10 +00:00
|
|
|
if ( this.modeAvailable !== modeAvailable ) {
|
|
|
|
this.$link.attr( 'title', modeAvailable ?
|
|
|
|
OO.ui.resolveMsg( this.constructor.static.title ) :
|
|
|
|
OO.ui.resolveMsg( this.constructor.static.unavailableTooltip )
|
|
|
|
);
|
|
|
|
this.setDisabled( !modeAvailable );
|
2017-02-24 14:29:21 +00:00
|
|
|
this.modeAvailable = modeAvailable;
|
|
|
|
}
|
2017-04-26 17:50:10 +00:00
|
|
|
this.setActive( this.getMode() === this.constructor.static.editMode );
|
2017-02-24 14:29:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MediaWiki edit mode source tool.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends mw.libs.ve.MWEditModeTool
|
|
|
|
* @constructor
|
|
|
|
* @param {OO.ui.ToolGroup} toolGroup
|
|
|
|
* @param {Object} [config] Config options
|
|
|
|
*/
|
|
|
|
mw.libs.ve.MWEditModeSourceTool = function VeUiMWEditModeSourceTool() {
|
|
|
|
// Parent constructor
|
|
|
|
mw.libs.ve.MWEditModeSourceTool.super.apply( this, arguments );
|
|
|
|
};
|
|
|
|
OO.inheritClass( mw.libs.ve.MWEditModeSourceTool, mw.libs.ve.MWEditModeTool );
|
|
|
|
mw.libs.ve.MWEditModeSourceTool.static.editMode = 'source';
|
|
|
|
mw.libs.ve.MWEditModeSourceTool.static.name = 'editModeSource';
|
|
|
|
mw.libs.ve.MWEditModeSourceTool.static.icon = 'wikiText';
|
|
|
|
mw.libs.ve.MWEditModeSourceTool.static.title =
|
2017-04-19 18:57:39 +00:00
|
|
|
OO.ui.deferMsg( 'visualeditor-mweditmodesource-tool-current' );
|
2017-02-24 14:29:21 +00:00
|
|
|
mw.libs.ve.MWEditModeSourceTool.static.unavailableTooltip =
|
|
|
|
OO.ui.deferMsg( 'visualeditor-mweditmodesource-tool-unavailable' );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MediaWiki edit mode visual tool.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends mw.libs.ve.MWEditModeTool
|
|
|
|
* @constructor
|
|
|
|
* @param {OO.ui.ToolGroup} toolGroup
|
|
|
|
* @param {Object} [config] Config options
|
|
|
|
*/
|
|
|
|
mw.libs.ve.MWEditModeVisualTool = function VeUiMWEditModeVisualTool() {
|
|
|
|
// Parent constructor
|
|
|
|
mw.libs.ve.MWEditModeVisualTool.super.apply( this, arguments );
|
|
|
|
};
|
|
|
|
OO.inheritClass( mw.libs.ve.MWEditModeVisualTool, mw.libs.ve.MWEditModeTool );
|
|
|
|
mw.libs.ve.MWEditModeVisualTool.static.editMode = 'visual';
|
|
|
|
mw.libs.ve.MWEditModeVisualTool.static.name = 'editModeVisual';
|
2017-02-28 22:59:51 +00:00
|
|
|
mw.libs.ve.MWEditModeVisualTool.static.icon = 'eye';
|
2017-02-24 14:29:21 +00:00
|
|
|
mw.libs.ve.MWEditModeVisualTool.static.title =
|
2017-04-19 18:57:39 +00:00
|
|
|
OO.ui.deferMsg( 'visualeditor-mweditmodeve-tool-current' );
|
2017-02-24 14:29:21 +00:00
|
|
|
mw.libs.ve.MWEditModeVisualTool.static.unavailableTooltip =
|
|
|
|
OO.ui.deferMsg( 'visualeditor-mweditmodeve-tool-unavailable' );
|