mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-29 16:44:51 +00:00
a835c03bc1
Rather than meta-things being special kinds of nodes, they are now a separate class of things (MetaItems) along with Nodes and Annotations. * Created a generic ve.dm.MetaItem that meta items inherit from. There will be actual instances of this class as well in the upcoming meta group code. * Renamed MetaNode to AlienMetaItem, MWMetaNode to MWMetaItem, 'metaBlock'/'metaInline' to 'alienMeta' * Created a MetaItemFactory, handle meta items in the ModelRegistry * Kill ve.dm.Node.static.isMeta, now obsolete ve.dm.Converter: * Pass in the MetaItemFactory * Look up data element types in the ModelRegistry rather than the NodeFactory, because they can be either nodes or meta items * Document createDataElement() and make explicit that modelClass can be either a node or a meta item * Handle meta items in getDataFromDom() * In getDomFromData(), check the MetaItemFactory as well as the NodeFactory Change-Id: I893709c6f3aa00f85c1b905b70f9f4e597bdeada
72 lines
2.1 KiB
JavaScript
72 lines
2.1 KiB
JavaScript
/*!
|
|
* VisualEditor DataModel AlienMetaItem class.
|
|
*
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* DataModel alien meta item.
|
|
*
|
|
* @class
|
|
* @extends ve.dm.MetaItem
|
|
* @constructor
|
|
* @param {Object} element Reference to element in meta-linmod
|
|
*/
|
|
ve.dm.AlienMetaItem = function VeDmAlienMetaItem( element ) {
|
|
// Parent constructor
|
|
ve.dm.MetaItem.call( this, element );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
ve.inheritClass( ve.dm.AlienMetaItem, ve.dm.MetaItem );
|
|
|
|
/* Static Properties */
|
|
|
|
ve.dm.AlienMetaItem.static.name = 'alienMeta';
|
|
|
|
ve.dm.AlienMetaItem.static.matchTagNames = [ 'meta', 'link' ];
|
|
|
|
ve.dm.AlienMetaItem.static.toDataElement = function ( domElements ) {
|
|
var firstDomElement = domElements[0],
|
|
isLink = firstDomElement.nodeName.toLowerCase() === 'link',
|
|
keyAttr = isLink ? 'rel' : 'property',
|
|
valueAttr = isLink ? 'href' : 'content',
|
|
dataElement = {
|
|
'type': 'alienMeta',
|
|
'attributes': {
|
|
'style': isLink ? 'link' : 'meta',
|
|
'key': firstDomElement.getAttribute( keyAttr )
|
|
}
|
|
};
|
|
if ( firstDomElement.hasAttribute( valueAttr ) ) {
|
|
dataElement.attributes.value = firstDomElement.getAttribute( valueAttr );
|
|
}
|
|
return dataElement;
|
|
};
|
|
|
|
ve.dm.AlienMetaItem.static.toDomElements = function ( dataElement ) {
|
|
var style = dataElement.attributes && dataElement.attributes.style || 'meta',
|
|
isLink = style === 'link',
|
|
tag = isLink ? 'link' : 'meta',
|
|
keyAttr = isLink ? 'rel' : 'property',
|
|
valueAttr = isLink ? 'href' : 'content',
|
|
domElement;
|
|
if ( style === 'comment' ) {
|
|
return [ document.createComment( dataElement.attributes && dataElement.attributes.text || '' ) ];
|
|
}
|
|
domElement = document.createElement( tag );
|
|
if ( dataElement.attributes && dataElement.attributes.key !== null ) {
|
|
domElement.setAttribute( keyAttr, dataElement.attributes.key );
|
|
}
|
|
if ( dataElement.attributes && dataElement.attributes.value ) {
|
|
domElement.setAttribute( valueAttr, dataElement.attributes.value );
|
|
}
|
|
return [ domElement ];
|
|
};
|
|
|
|
/* Registration */
|
|
|
|
ve.dm.modelRegistry.register( ve.dm.AlienMetaItem );
|