mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-29 08:34:54 +00:00
8ba81f4d67
Objective: * Put command shortcuts in button title attributes. (Bug 42919) * Provide a registry for platform specific command triggers and their corresponding i18n messages. (Bug 44012) * Enable loading of triggers after ve.Surface is created. (lazy load) Changes: VisualEditor.i18n.php * Add default trigger i18n messags for mac and pc system platforms VisusalEditor.php, demos/ve/index.php * Add links to files ve.init.mw.Platform.js * Define getUserLanguage and getSystemPlatform methods. ve.init.sa.Platform.js * Define getUserLanguage and getSystemPlatform methods. ve.init.Platform.js * Define abstract methods: getUserLangauge, getSystemPlatform ve.ui.BoldBUttonTool.js, ve.ui.IndentButtonTool.js, ve.ui.ItalicButtonTool.js, ve.ui.LinkButtonTool.js, ve.ui.OutdentButtonTool.js, ve.ui.RedoButtonTool.js, ve.ui.UndoButtonTool.js * Add registration for command triggers. ve.Surface.js * Methodize loading of triggers. * Bind register event to ve.triggerRegistry to allow lazy loading of triggers. ve.ui.Tool.js * Init pre-registered tooltip messages. * Update tool titles when new triggers are loaded. ve.CommandRegistry.js * Remove command registration ( moved to buttons themselves ) ve.TriggerRegistry.js * New class for registering triggers. ve.init.mw.ViewPageTarget.js * Changed instance of unindent command to outdent. Change-Id: Id8580a3f81aac751db0b7482422a73912648dfed
57 lines
1.5 KiB
JavaScript
57 lines
1.5 KiB
JavaScript
/*!
|
|
* VisualEditor CommandRegistry class.
|
|
*
|
|
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* Command registry.
|
|
*
|
|
* @class
|
|
* @extends ve.Registry
|
|
* @constructor
|
|
*/
|
|
ve.CommandRegistry = function VeCommandRegistry() {
|
|
// Parent constructor
|
|
ve.Registry.call( this );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
ve.inheritClass( ve.CommandRegistry, ve.Registry );
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Register a constructor with the factory.
|
|
*
|
|
* @method
|
|
* @param {string|string[]} name Symbolic name or list of symbolic names
|
|
* @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
|
|
* @throws {Error} Action must be a string
|
|
* @throws {Error} Method must be a string
|
|
*/
|
|
ve.CommandRegistry.prototype.register = function ( name , action, method ) {
|
|
if ( typeof name !== 'string' && !ve.isArray( name ) ) {
|
|
throw new Error( 'name must be a string or array, cannot be a ' + typeof name );
|
|
}
|
|
if ( typeof action !== 'string' ) {
|
|
throw new Error( 'action must be a string, cannot be a ' + typeof action );
|
|
}
|
|
if ( typeof method !== 'string' ) {
|
|
throw new Error( 'method must be a string, cannot be a ' + typeof method );
|
|
}
|
|
ve.Registry.prototype.register.call(
|
|
this, name, { 'action': Array.prototype.slice.call( arguments, 1 ) }
|
|
);
|
|
};
|
|
|
|
/* Initialization */
|
|
|
|
ve.commandRegistry = new ve.CommandRegistry();
|
|
|
|
|