mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-25 14:56:20 +00:00
edcaaf9edc
Add a static.name property to ce nodes and make sure both ce and dm nodes always use the static.name property in constructors and registration calls. The result of this is that any given node type should now only appear once in the code as a string. Bug: 45701 Change-Id: Ibf31de16ab28ad58209c1443cd74f93dda278998
40 lines
957 B
JavaScript
40 lines
957 B
JavaScript
/*!
|
|
* VisualEditor NodeFactory class.
|
|
*
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* Generic node factory.
|
|
*
|
|
* @abstract
|
|
* @extends ve.Factory
|
|
* @constructor
|
|
*/
|
|
ve.NodeFactory = function VeNodeFactory() {
|
|
// Parent constructor
|
|
ve.Factory.call( this );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
ve.inheritClass( ve.NodeFactory, ve.Factory );
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Register a constructor with the factory.
|
|
*
|
|
* @method
|
|
* @param {Function} constructor Constructor to use when creating object
|
|
* @throws {Error} Node names must be strings and must not be empty
|
|
*/
|
|
ve.NodeFactory.prototype.register = function ( constructor ) {
|
|
var name = constructor.static && constructor.static.name;
|
|
if ( typeof name !== 'string' || name === '' ) {
|
|
throw new Error( 'Node names must be strings and must not be empty' );
|
|
}
|
|
ve.Factory.prototype.register.call( this, name, constructor );
|
|
};
|