mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-12-03 18:36:20 +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
119 lines
3.4 KiB
JavaScript
119 lines
3.4 KiB
JavaScript
/*!
|
|
* VisualEditor CommandRegistry class.
|
|
*
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* Command registry.
|
|
*
|
|
* @class
|
|
* @extends OO.Registry
|
|
* @constructor
|
|
*/
|
|
ve.ui.CommandRegistry = function VeCommandRegistry() {
|
|
// Parent constructor
|
|
OO.Registry.call( this );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
OO.inheritClass( ve.ui.CommandRegistry, OO.Registry );
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Register a constructor with the factory.
|
|
*
|
|
* @method
|
|
* @param {ve.ui.Command} command Command object
|
|
* @throws {Error} If command is not an instance of ve.ui.Command
|
|
*/
|
|
ve.ui.CommandRegistry.prototype.register = function ( command ) {
|
|
// Validate arguments
|
|
if ( !( command instanceof ve.ui.Command ) ) {
|
|
throw new Error(
|
|
'command must be an instance of ve.ui.Command, cannot be a ' + typeof command
|
|
);
|
|
}
|
|
|
|
OO.Registry.prototype.register.call( this, command.getName(), command );
|
|
};
|
|
|
|
/* Initialization */
|
|
|
|
ve.ui.commandRegistry = new ve.ui.CommandRegistry();
|
|
|
|
/* Registrations */
|
|
|
|
ve.ui.commandRegistry.register(
|
|
new ve.ui.Command( 'undo', 'history', 'undo' )
|
|
);
|
|
ve.ui.commandRegistry.register(
|
|
new ve.ui.Command( 'redo', 'history', 'redo' )
|
|
);
|
|
ve.ui.commandRegistry.register(
|
|
new ve.ui.Command( 'bold', 'annotation', 'toggle', 'textStyle/bold' )
|
|
);
|
|
ve.ui.commandRegistry.register(
|
|
new ve.ui.Command( 'italic', 'annotation', 'toggle', 'textStyle/italic' )
|
|
);
|
|
ve.ui.commandRegistry.register(
|
|
new ve.ui.Command( 'link', 'inspector', 'open', 'link' )
|
|
);
|
|
ve.ui.commandRegistry.register(
|
|
new ve.ui.Command( 'clear', 'annotation', 'clearAll' )
|
|
);
|
|
ve.ui.commandRegistry.register(
|
|
new ve.ui.Command( 'underline', 'annotation', 'toggle', 'textStyle/underline' )
|
|
);
|
|
ve.ui.commandRegistry.register(
|
|
new ve.ui.Command( 'subscript', 'annotation', 'toggle', 'textStyle/subscript' )
|
|
);
|
|
ve.ui.commandRegistry.register(
|
|
new ve.ui.Command( 'superscript', 'annotation', 'toggle', 'textStyle/superscript' )
|
|
);
|
|
ve.ui.commandRegistry.register(
|
|
new ve.ui.Command( 'indent', 'indentation', 'increase' )
|
|
);
|
|
ve.ui.commandRegistry.register(
|
|
new ve.ui.Command( 'outdent', 'indentation', 'decrease' )
|
|
);
|
|
ve.ui.commandRegistry.register(
|
|
new ve.ui.Command( 'code', 'annotation', 'toggle', 'textStyle/code' )
|
|
);
|
|
ve.ui.commandRegistry.register(
|
|
new ve.ui.Command( 'strikethrough', 'annotation', 'toggle', 'textStyle/strike' )
|
|
);
|
|
ve.ui.commandRegistry.register(
|
|
new ve.ui.Command( 'language', 'inspector', 'open', 'language' )
|
|
);
|
|
ve.ui.commandRegistry.register(
|
|
new ve.ui.Command( 'paragraph', 'format', 'convert', 'paragraph' )
|
|
);
|
|
ve.ui.commandRegistry.register(
|
|
new ve.ui.Command( 'heading1', 'format', 'convert', 'heading', { 'level': 1 } )
|
|
);
|
|
ve.ui.commandRegistry.register(
|
|
new ve.ui.Command( 'heading2', 'format', 'convert', 'heading', { 'level': 2 } )
|
|
);
|
|
ve.ui.commandRegistry.register(
|
|
new ve.ui.Command( 'heading3', 'format', 'convert', 'heading', { 'level': 3 } )
|
|
);
|
|
ve.ui.commandRegistry.register(
|
|
new ve.ui.Command( 'heading4', 'format', 'convert', 'heading', { 'level': 4 } )
|
|
);
|
|
ve.ui.commandRegistry.register(
|
|
new ve.ui.Command( 'heading5', 'format', 'convert', 'heading', { 'level': 5 } )
|
|
);
|
|
ve.ui.commandRegistry.register(
|
|
new ve.ui.Command( 'heading6', 'format', 'convert', 'heading', { 'level': 6 } )
|
|
);
|
|
ve.ui.commandRegistry.register(
|
|
new ve.ui.Command( 'preformatted', 'format', 'convert', 'preformatted' )
|
|
);
|
|
ve.ui.commandRegistry.register(
|
|
new ve.ui.Command( 'pasteSpecial', 'content', 'pasteSpecial' )
|
|
);
|