Debian Codegraph @

extensions/VisualEditor/modules/ve-mw/ui/tools/ve.ui.MWEditModeTool.js

raw symbols SCIP
1 /*!
2 * VisualEditor MediaWiki UserInterface edit mode tool classes.
3 *
4 * @copyright See AUTHORS.txt
5 * @license The MIT License (MIT); see LICENSE.txt
6 */
7
8 /**
9 * MediaWiki UserInterface edit mode tool.
10 *
11 * @class
12 * @abstract
13 */
14 ve.ui.MWEditModeTool = function VeUiMWEditModeTool() {
15 };
16
17 /* Inheritance */
18
19 OO.initClass( ve.ui.MWEditModeTool );
20
21 /* Methods */
22
23 /**
24 * @inheritdoc mw.libs.ve.MWEditModeTool
25 */
26 ve.ui.MWEditModeTool.prototype.getMode = function () {
27 if ( !this.toolbar.getSurface() ) {
28 return 'source';
29 }
30 return this.toolbar.getSurface().getMode();
31 };
32
33 /**
34 * @inheritdoc mw.libs.ve.MWEditModeTool
35 */
36 ve.ui.MWEditModeTool.prototype.isModeAvailable = function ( mode ) {
37 const target = this.toolbar.getTarget();
38 const surface = target.getSurface();
39 const canSwitch = surface && !surface.getModel().isMultiUser();
40
41 // Source mode is always available
42 return canSwitch && (
43 mode === 'source' || target.isModeAvailable( mode )
44 );
45 };
46
47 /**
48 * MediaWiki UserInterface edit mode visual tool.
49 *
50 * @class
51 * @extends mw.libs.ve.MWEditModeVisualTool
52 * @mixes ve.ui.MWEditModeTool
53 * @constructor
54 * @param {OO.ui.ToolGroup} toolGroup
55 * @param {Object} [config] Config options
56 */
57 ve.ui.MWEditModeVisualTool = function VeUiMWEditModeVisualTool() {
58 // Parent constructor
59 ve.ui.MWEditModeVisualTool.super.apply( this, arguments );
60 // Mixin constructor
61 ve.ui.MWEditModeTool.call( this );
62 };
63 OO.inheritClass( ve.ui.MWEditModeVisualTool, mw.libs.ve.MWEditModeVisualTool );
64 OO.mixinClass( ve.ui.MWEditModeVisualTool, ve.ui.MWEditModeTool );
65 /**
66 * @inheritdoc
67 */
68 ve.ui.MWEditModeVisualTool.prototype.switch = function () {
69 this.toolbar.getTarget().switchToVisualEditor();
70 };
71 ve.ui.toolFactory.register( ve.ui.MWEditModeVisualTool );
72
73 /**
74 * MediaWiki UserInterface edit mode source tool.
75 *
76 * @class
77 * @extends mw.libs.ve.MWEditModeSourceTool
78 * @mixes ve.ui.MWEditModeTool
79 * @constructor
80 * @param {OO.ui.ToolGroup} toolGroup
81 * @param {Object} [config] Config options
82 */
83 ve.ui.MWEditModeSourceTool = function VeUiMWEditModeSourceTool() {
84 // Parent constructor
85 ve.ui.MWEditModeSourceTool.super.apply( this, arguments );
86 // Mixin constructor
87 ve.ui.MWEditModeTool.call( this );
88 };
89 OO.inheritClass( ve.ui.MWEditModeSourceTool, mw.libs.ve.MWEditModeSourceTool );
90 OO.mixinClass( ve.ui.MWEditModeSourceTool, ve.ui.MWEditModeTool );
91 /**
92 * @inheritdoc
93 */
94 ve.ui.MWEditModeSourceTool.prototype.switch = function () {
95 this.toolbar.getTarget().editSource();
96 };
97 ve.ui.toolFactory.register( ve.ui.MWEditModeSourceTool );