2013-01-15 20:15:15 +00:00
|
|
|
/*!
|
2013-05-14 23:45:42 +00:00
|
|
|
* VisualEditor UserInterface TriggerRegistry class.
|
2013-01-15 20:15:15 +00:00
|
|
|
*
|
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
|
|
|
|
*/
|
2013-05-14 23:45:42 +00:00
|
|
|
ve.ui.TriggerRegistry = function VeUiTriggerRegistry() {
|
2013-01-15 20:15:15 +00:00
|
|
|
// Parent constructor
|
|
|
|
ve.Registry.call( this );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2013-05-14 23:45:42 +00:00
|
|
|
ve.inheritClass( ve.ui.TriggerRegistry, ve.Registry );
|
2013-01-15 20:15:15 +00:00
|
|
|
|
|
|
|
/* 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
|
2013-05-14 23:45:42 +00:00
|
|
|
* @param {ve.ui.Trigger|Object} trigger Trigger object, or map of trigger objects keyed by
|
2013-01-26 03:29:21 +00:00
|
|
|
* platform name e.g. 'mac' or 'pc'
|
2013-01-15 20:15:15 +00:00
|
|
|
*/
|
2013-05-14 23:45:42 +00:00
|
|
|
ve.ui.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-14 23:45:42 +00:00
|
|
|
if ( !( trigger instanceof ve.ui.Trigger ) && !ve.isPlainObject( trigger ) ) {
|
2013-01-26 03:29:21 +00:00
|
|
|
throw new Error(
|
2013-05-14 23:45:42 +00:00
|
|
|
'trigger must be an instance of ve.ui.Trigger or an object containing instances of ' +
|
|
|
|
've.ui.Trigger, cannot be a ' + typeof trigger
|
2013-01-26 03:29:21 +00:00
|
|
|
);
|
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 */
|
|
|
|
|
2013-05-14 23:45:42 +00:00
|
|
|
ve.ui.triggerRegistry = new ve.ui.TriggerRegistry();
|