mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-29 00:30:44 +00:00
638e4f65b6
This introduces a small reorginization of how commands are registered so that they are associated with their corresponding symbolic names. This change is mainly to aid with event tracking, but it might be generally useful for other things as well. Change-Id: I2ccf4522f786a54c1f5395008b7b0333a1fa6072
73 lines
1.7 KiB
JavaScript
73 lines
1.7 KiB
JavaScript
/*!
|
|
* VisualEditor UserInterface Command class.
|
|
*
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* Command that executes an action.
|
|
*
|
|
* @class
|
|
*
|
|
* @constructor
|
|
* @param {string} name Symbolic name for the command
|
|
* @param {string} action Action to execute when command is triggered
|
|
* @param {string} method Method to call on action when executing
|
|
* @param {Mixed...} [data] Additional data to pass to the action when executing
|
|
*/
|
|
ve.ui.Command = function VeUiCommand( name, action, method ) {
|
|
this.name = name;
|
|
this.action = action;
|
|
this.method = method;
|
|
this.data = Array.prototype.slice.call( arguments, 3 );
|
|
};
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Execute command on a surface.
|
|
*
|
|
* @param {ve.ui.Surface} surface Surface to execute command on
|
|
* @returns {Mixed} Result of command execution.
|
|
*/
|
|
ve.ui.Command.prototype.execute = function ( surface ) {
|
|
return surface.execute.apply( surface, [ this.action, this.method ].concat( this.data ) );
|
|
};
|
|
|
|
/**
|
|
* Get command action.
|
|
*
|
|
* @returns {string} action Action to execute when command is triggered
|
|
*/
|
|
ve.ui.Command.prototype.getAction = function () {
|
|
return this.action;
|
|
};
|
|
|
|
/**
|
|
* Get command method.
|
|
*
|
|
* @returns {string} method Method to call on action when executing
|
|
*/
|
|
ve.ui.Command.prototype.getMethod = function () {
|
|
return this.method;
|
|
};
|
|
|
|
/**
|
|
* Get command name.
|
|
*
|
|
* @returns {string} name The symbolic name of the command.
|
|
*/
|
|
ve.ui.Command.prototype.getName = function () {
|
|
return this.name;
|
|
};
|
|
|
|
/**
|
|
* Get command data.
|
|
*
|
|
* @returns {Array} data Additional data to pass to the action when executing
|
|
*/
|
|
ve.ui.Command.prototype.getData = function () {
|
|
return this.data;
|
|
};
|