mediawiki-extensions-Visual.../modules/ve/dm/nodes/ve.dm.MetaBlockNode.js
Catrope 819b3ded33 Move matching code from AnnotationFactory to ModelRegistry
ModelRegistry registers both annotations and nodes, and performs
matching on both at the same time. It also registers annotations with
the AnnotationFactory, and nodes with the NodeFactory.

Change-Id: I5e68e506a0e573cc0afe6304ccea058ffc20d1c8
2013-01-22 15:51:37 -08:00

56 lines
1.7 KiB
JavaScript

/*!
* VisualEditor DataModel MetaBlockNode class.
*
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* DataModel meta block node.
*
* @class
* @extends ve.dm.BranchNode
* @constructor
* @param {number} [length] Length of content data in document
* @param {Object} [element] Reference to element in linear model
*/
ve.dm.MetaBlockNode = function VeDmMetaBlockNode( length, element ) {
// Parent constructor
ve.dm.BranchNode.call( this, 'metaBlock', 0, element );
};
/* Inheritance */
ve.inheritClass( ve.dm.MetaBlockNode, ve.dm.LeafNode );
/* Static Properties */
ve.dm.MetaBlockNode.static.name = 'metaBlock';
ve.dm.MetaBlockNode.static.matchTagNames = [ 'meta' ];
ve.dm.MetaBlockNode.static.toDataElement = function () {
throw new Error( 'No toDataElement for metaBlock, supposed to be handled by converter hack' );
};
ve.dm.MetaBlockNode.static.toDomElement = function ( dataElement ) {
var style = dataElement.attributes && dataElement.attributes.style || 'meta',
isLink = style === 'link',
domElement;
if ( style === 'comment' ) {
return document.createComment( dataElement.attributes && dataElement.attributes.text || '' );
}
domElement = document.createElement( isLink ? 'link' : 'meta' );
if ( dataElement.attributes && dataElement.attributes.key !== null ) {
domElement.setAttribute( isLink ? 'rel' : 'property', dataElement.attributes.key );
}
if ( dataElement.attributes && dataElement.attributes.value ) {
domElement.setAttribute( isLink ? 'href' : 'content', dataElement.attributes.value );
}
return domElement;
};
/* Registration */
ve.dm.modelRegistry.register( 'metaBlock', ve.dm.MetaBlockNode );