2012-09-06 21:07:39 +00:00
|
|
|
/**
|
|
|
|
* VisualEditor data model MetaBlockNode class.
|
|
|
|
*
|
|
|
|
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DataModel node for an alien block node.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @constructor
|
|
|
|
* @extends {ve.dm.BranchNode}
|
|
|
|
* @param {Integer} [length] Length of content data in document
|
|
|
|
* @param {Object} [attributes] Reference to map of attribute key/value pairs
|
|
|
|
*/
|
2012-10-22 21:50:28 +00:00
|
|
|
ve.dm.MetaBlockNode = function VeDmMetaBlockNode( length, attributes ) {
|
2012-09-06 21:07:39 +00:00
|
|
|
// Parent constructor
|
2012-10-22 21:50:28 +00:00
|
|
|
ve.dm.BranchNode.call( this, 'metaBlock', 0, attributes );
|
2012-09-06 21:07:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
ve.inheritClass( ve.dm.MetaBlockNode, ve.dm.BranchNode );
|
|
|
|
|
|
|
|
/* Static Members */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Node rules.
|
|
|
|
*
|
|
|
|
* @see ve.dm.NodeFactory
|
|
|
|
* @static
|
|
|
|
* @member
|
|
|
|
*/
|
|
|
|
ve.dm.MetaBlockNode.rules = {
|
|
|
|
'isWrapped': true,
|
|
|
|
'isContent': false,
|
|
|
|
'canContainContent': false,
|
2012-11-07 20:03:58 +00:00
|
|
|
'hasSignificantWhitespace': false,
|
2012-09-06 21:07:39 +00:00
|
|
|
'childNodeTypes': [],
|
|
|
|
'parentNodeTypes': null
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Node converters.
|
|
|
|
*
|
|
|
|
* @see {ve.dm.Converter}
|
|
|
|
* @static
|
|
|
|
* @member
|
|
|
|
*/
|
|
|
|
ve.dm.MetaBlockNode.converters = {
|
|
|
|
'domElementTypes': ['meta', 'link'],
|
|
|
|
'toDomElement': function ( type, element ) {
|
2012-11-20 04:01:09 +00:00
|
|
|
var isLink, domElement;
|
|
|
|
if ( element.attributes.style === 'comment' ) {
|
|
|
|
domElement = document.createComment( element.attributes.text );
|
|
|
|
} else {
|
|
|
|
isLink = element.attributes.style === 'link';
|
2012-09-06 21:07:39 +00:00
|
|
|
domElement = document.createElement( isLink ? 'link' : 'meta' );
|
2012-11-20 04:01:09 +00:00
|
|
|
if ( element.attributes.key !== null ) {
|
|
|
|
domElement.setAttribute( isLink ? 'rel' : 'property', element.attributes.key );
|
|
|
|
}
|
|
|
|
if ( element.attributes.value ) {
|
|
|
|
domElement.setAttribute( isLink ? 'href' : 'content', element.attributes.value );
|
|
|
|
}
|
2012-09-06 21:07:39 +00:00
|
|
|
}
|
|
|
|
return domElement;
|
|
|
|
},
|
|
|
|
'toDataElement': null // Special handling in ve.dm.Converter
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.dm.nodeFactory.register( 'metaBlock', ve.dm.MetaBlockNode );
|