2013-02-21 23:01:04 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor DataModel MetaItemFactory class.
|
|
|
|
*
|
|
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DataModel meta item factory.
|
|
|
|
*
|
|
|
|
* @class
|
2013-04-02 18:44:23 +00:00
|
|
|
* @extends ve.NamedClassFactory
|
2013-02-21 23:01:04 +00:00
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
ve.dm.MetaItemFactory = function VeDmMetaItemFactory() {
|
|
|
|
// Parent constructor
|
2013-04-02 18:44:23 +00:00
|
|
|
ve.NamedClassFactory.call( this );
|
2013-02-21 23:01:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2013-04-02 18:44:23 +00:00
|
|
|
ve.inheritClass( ve.dm.MetaItemFactory, ve.NamedClassFactory );
|
2013-02-21 23:01:04 +00:00
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the item stores HTML attributes in the meta-linmod.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {string} type Meta item type
|
2013-03-20 17:03:27 +00:00
|
|
|
* @returns {boolean} Whether the item stores HTML attributes
|
2013-02-21 23:01:04 +00:00
|
|
|
* @throws {Error} Unknown item type
|
|
|
|
*/
|
|
|
|
ve.dm.MetaItemFactory.prototype.doesItemStoreHtmlAttributes = function ( type ) {
|
|
|
|
if ( type in this.registry ) {
|
|
|
|
return this.registry[type].static.storeHtmlAttributes;
|
|
|
|
}
|
|
|
|
throw new Error( 'Unknown item type: ' + type );
|
|
|
|
};
|
|
|
|
|
2013-03-15 04:07:23 +00:00
|
|
|
/**
|
|
|
|
* Get the group a given item type belongs to.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {string} type Meta item type
|
|
|
|
* @returns {string} Group
|
|
|
|
* @throws {Error} Unknown item type
|
|
|
|
*/
|
|
|
|
ve.dm.MetaItemFactory.prototype.getGroup = function ( type ) {
|
|
|
|
if ( type in this.registry ) {
|
|
|
|
return this.registry[type].static.group;
|
|
|
|
}
|
|
|
|
throw new Error( 'Unknown item type: ' + type );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new item from a metadata element
|
|
|
|
* @param {Object} element Metadata element
|
|
|
|
* @returns {ve.dm.MetaItem} MetaItem constructed from element
|
|
|
|
* @throws {Error} Element must have a .type property
|
|
|
|
*/
|
|
|
|
ve.dm.MetaItemFactory.prototype.createFromElement = function ( element ) {
|
|
|
|
if ( element && element.type ) {
|
|
|
|
return this.create( element.type, element );
|
|
|
|
}
|
|
|
|
throw new Error( 'Element must have a .type property' );
|
|
|
|
};
|
2013-02-21 23:01:04 +00:00
|
|
|
|
|
|
|
/* Initialization */
|
|
|
|
|
|
|
|
ve.dm.metaItemFactory = new ve.dm.MetaItemFactory();
|