2013-01-15 20:15:15 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor TriggerRegistry class.
|
|
|
|
*
|
2013-02-19 23:37:34 +00:00
|
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
2013-01-15 20:15:15 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Trigger registry.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends ve.Registry
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
ve.TriggerRegistry = function VeTriggerRegistry() {
|
|
|
|
// Parent constructor
|
|
|
|
ve.Registry.call( this );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
ve.inheritClass( ve.TriggerRegistry, ve.Registry );
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register a constructor with the factory.
|
|
|
|
*
|
2013-01-26 03:29:21 +00:00
|
|
|
* The only supported platforms are 'mac' and 'pc'. All platforms not identified as 'mac' will be
|
|
|
|
* considered to be 'pc', including 'win', 'linux', 'solaris', etc.
|
|
|
|
*
|
2013-01-15 20:15:15 +00:00
|
|
|
* @method
|
2013-01-26 03:29:21 +00:00
|
|
|
* @param {string|string[]} name Symbolic name or list of symbolic names
|
|
|
|
* @param {ve.Trigger|Object} trigger Trigger object, or map of trigger objects keyed by
|
|
|
|
* platform name e.g. 'mac' or 'pc'
|
2013-01-15 20:15:15 +00:00
|
|
|
*/
|
2013-01-26 03:29:21 +00:00
|
|
|
ve.TriggerRegistry.prototype.register = function ( name, trigger ) {
|
2013-01-15 20:15:15 +00:00
|
|
|
var platform = ve.init.platform.getSystemPlatform(),
|
2013-01-26 03:29:21 +00:00
|
|
|
platformKey = platform === 'mac' ? 'mac' : 'pc';
|
2013-01-15 20:15:15 +00:00
|
|
|
|
2013-01-26 03:29:21 +00:00
|
|
|
// Validate arguments
|
|
|
|
if ( typeof name !== 'string' && !ve.isArray( name ) ) {
|
|
|
|
throw new Error( 'name must be a string or array, cannot be a ' + typeof name );
|
2013-01-15 20:15:15 +00:00
|
|
|
}
|
2013-05-06 11:34:32 +00:00
|
|
|
if ( !( trigger instanceof ve.Trigger ) && !ve.isPlainObject( trigger ) ) {
|
2013-01-26 03:29:21 +00:00
|
|
|
throw new Error(
|
|
|
|
'trigger must be an instance of ve.Trigger or an object containing instances of ' +
|
|
|
|
've.Trigger, cannot be a ' + typeof trigger
|
|
|
|
);
|
2013-01-15 20:15:15 +00:00
|
|
|
}
|
2013-01-26 03:29:21 +00:00
|
|
|
|
|
|
|
// Check for platform-specific trigger
|
|
|
|
if ( ve.isPlainObject( trigger ) ) {
|
|
|
|
// Only register if the current platform is supported
|
|
|
|
if ( platformKey in trigger ) {
|
|
|
|
ve.Registry.prototype.register.call( this, name, trigger[platformKey] );
|
2013-01-15 20:15:15 +00:00
|
|
|
}
|
2013-01-26 03:29:21 +00:00
|
|
|
} else {
|
|
|
|
ve.Registry.prototype.register.call( this, name, trigger );
|
|
|
|
}
|
2013-01-15 20:15:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Initialization */
|
|
|
|
|
|
|
|
ve.triggerRegistry = new ve.TriggerRegistry();
|