mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-29 08:34:54 +00:00
00a109b4a1
A MetaList is a collection of MetaItems representing all of the metadata in a ve.dm.Document, and it updates itself live as the underlying document changes. Currently this interface is read-only, I'll add mutators next. Change-Id: If7bfc9563af37e22dcdca9a682d6decc2f6f1872
72 lines
1.8 KiB
JavaScript
72 lines
1.8 KiB
JavaScript
/*!
|
|
* 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
|
|
* @extends ve.Factory
|
|
* @constructor
|
|
*/
|
|
ve.dm.MetaItemFactory = function VeDmMetaItemFactory() {
|
|
// Parent constructor
|
|
ve.Factory.call( this );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
ve.inheritClass( ve.dm.MetaItemFactory, ve.Factory );
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Check if the item stores HTML attributes in the meta-linmod.
|
|
*
|
|
* @method
|
|
* @param {string} type Meta item type
|
|
* @returns {boolean} Whether the item stores HTML attributes.
|
|
* @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 );
|
|
};
|
|
|
|
/**
|
|
* 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' );
|
|
};
|
|
|
|
/* Initialization */
|
|
|
|
ve.dm.metaItemFactory = new ve.dm.MetaItemFactory();
|