mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-16 02:51:50 +00:00
6dacc54954
* Create MWTemplateBlockNode & MWTemplateInlineNode (in ce and dm) * Move Alien's 'isInline' code to ve.dm.Node.static.isHybridInline * Move definition of ce.AlienBlock/InlineNode inside ce.Aline.js file to match dm.AlienBlock/InlineNode and MWTemplate * Duplicate AlienBlock/Inline styles for templates * Create test case for inline templates * Count test cases in ve.dm.Converter.test.js automatically Change-Id: Id9bc7f049ea974dd5e7f8b7a66080939e0948bbd
117 lines
3.4 KiB
JavaScript
117 lines
3.4 KiB
JavaScript
/*!
|
|
* VisualEditor DataModel MWTemplateNode class.
|
|
*
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* DataModel MediaWiki template node.
|
|
*
|
|
* @class
|
|
* @abstract
|
|
* @extends ve.dm.GeneratedContentNode
|
|
* @constructor
|
|
* @param {number} [length] Length of content data in document; ignored and overridden to 0
|
|
* @param {Object} [element] Reference to element in linear model
|
|
*/
|
|
ve.dm.MWTemplateNode = function VeDmMWTemplateNode( length, element ) {
|
|
// Parent constructor
|
|
ve.dm.GeneratedContentNode.call( this, 0, element );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
ve.inheritClass( ve.dm.MWTemplateNode, ve.dm.GeneratedContentNode );
|
|
|
|
/* Static members */
|
|
|
|
ve.dm.MWTemplateNode.static.name = 'MWtemplate';
|
|
|
|
ve.dm.MWTemplateNode.static.matchTagNames = null;
|
|
|
|
ve.dm.MWTemplateNode.static.matchRdfaTypes = [ 'mw:Object/Template' ];
|
|
|
|
ve.dm.MWTemplateNode.static.getHashObject = function ( dataElement ) {
|
|
return {
|
|
type: dataElement.type,
|
|
mw: dataElement.mw
|
|
};
|
|
};
|
|
|
|
ve.dm.MWTemplateNode.static.toDataElement = function ( domElements, converter ) {
|
|
var dataElement,
|
|
about = domElements[0].getAttribute( 'about' ),
|
|
mw = JSON.parse( domElements[0].getAttribute( 'data-mw' ) ),
|
|
isInline = this.isHybridInline( domElements, converter ),
|
|
type = isInline ? 'MWtemplateInline' : 'MWtemplateBlock';
|
|
|
|
dataElement = {
|
|
'type': type,
|
|
'mw': mw,
|
|
'about': about
|
|
};
|
|
this.storeHtml( dataElement, domElements, converter.getStore() );
|
|
return dataElement;
|
|
};
|
|
|
|
ve.dm.MWTemplateNode.static.toDomElements = function ( dataElement, doc ) {
|
|
var span = doc.createElement( 'span' );
|
|
// All we need to send back to Parsoid is the original template marker,
|
|
// with a reconstructed data-mw property.
|
|
span.setAttribute( 'about', dataElement.about );
|
|
span.setAttribute( 'typeof', 'mw:Object/Template' );
|
|
span.setAttribute( 'data-mw', JSON.stringify( dataElement.mw ) );
|
|
return [ span ];
|
|
};
|
|
|
|
/* Concrete subclasses */
|
|
|
|
/**
|
|
* DataModel MediaWiki template block node.
|
|
*
|
|
* @class
|
|
* @extends ve.dm.MWTemplateNode
|
|
* @constructor
|
|
* @param {number} [length] Length of content data in document; ignored and overridden to 0
|
|
* @param {Object} [element] Reference to element in linear model
|
|
*/
|
|
ve.dm.MWTemplateBlockNode = function VeDmMWTemplateBlockNode( length, element ) {
|
|
// Parent constructor
|
|
ve.dm.MWTemplateNode.call( this, length, element );
|
|
};
|
|
|
|
ve.inheritClass( ve.dm.MWTemplateBlockNode, ve.dm.MWTemplateNode );
|
|
|
|
ve.dm.MWTemplateBlockNode.static.matchTagNames = [];
|
|
|
|
ve.dm.MWTemplateBlockNode.static.name = 'MWtemplateBlock';
|
|
|
|
/**
|
|
* DataModel MediaWiki template inline node.
|
|
*
|
|
* @class
|
|
* @extends ve.dm.MWTemplateNode
|
|
* @constructor
|
|
* @param {number} [length] Length of content data in document; ignored and overridden to 0
|
|
* @param {Object} [element] Reference to element in linear model
|
|
*/
|
|
ve.dm.MWTemplateInlineNode = function VeDmMWTemplateInlineNode( length, element ) {
|
|
// Parent constructor
|
|
ve.dm.MWTemplateNode.call( this, length, element );
|
|
};
|
|
|
|
ve.inheritClass( ve.dm.MWTemplateInlineNode, ve.dm.MWTemplateNode );
|
|
|
|
ve.dm.MWTemplateInlineNode.static.matchTagNames = [];
|
|
|
|
ve.dm.MWTemplateInlineNode.static.name = 'MWtemplateInline';
|
|
|
|
ve.dm.MWTemplateInlineNode.static.isContent = true;
|
|
|
|
/* Registration */
|
|
|
|
ve.dm.modelRegistry.register( ve.dm.MWTemplateNode );
|
|
ve.dm.modelRegistry.register( ve.dm.MWTemplateBlockNode );
|
|
ve.dm.modelRegistry.register( ve.dm.MWTemplateInlineNode );
|