Debian Codegraph @

extensions/VisualEditor/lib/ve/src/ui/commands/ve.ui.HistoryCommand.js

raw symbols SCIP
1 /*!
2 * VisualEditor UserInterface HistoryCommand class.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 /**
8 * UserInterface history command.
9 *
10 * @class
11 * @extends ve.ui.Command
12 *
13 * @constructor
14 * @param {string} name
15 * @param {string} [method]
16 */
17 ve.ui.HistoryCommand = function VeUiHistoryCommand( name, method ) {
18 method = method || name;
19
20 // Parent constructor
21 ve.ui.HistoryCommand.super.call( this, name, 'history', method );
22
23 this.checkMethod = {
24 undo: 'canUndo',
25 redo: 'canRedo'
26 }[ method ];
27 };
28
29 /* Inheritance */
30
31 OO.inheritClass( ve.ui.HistoryCommand, ve.ui.Command );
32
33 /* Methods */
34
35 /**
36 * @inheritdoc
37 */
38 ve.ui.HistoryCommand.prototype.isExecutable = function ( fragment ) {
39 const surface = fragment.getSurface();
40
41 // Parent method
42 return ve.ui.HistoryCommand.super.prototype.isExecutable.apply( this, arguments ) &&
43 surface[ this.checkMethod ]();
44 };
45
46 /* Registration */
47
48 ve.ui.commandRegistry.register( new ve.ui.HistoryCommand( 'undo' ) );
49
50 ve.ui.commandRegistry.register( new ve.ui.HistoryCommand( 'redo' ) );