2013-03-27 22:56:54 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor DataModel MWEntityNode class.
|
|
|
|
*
|
|
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DataModel MediaWiki image node.
|
|
|
|
*
|
|
|
|
* @class
|
2013-04-10 19:56:20 +00:00
|
|
|
* @extends ve.dm.ImageNode
|
2013-03-27 22:56:54 +00:00
|
|
|
* @constructor
|
|
|
|
* @param {number} [length] Length of content data in document
|
|
|
|
* @param {Object} [element] Reference to element in linear model
|
|
|
|
*/
|
2013-04-24 23:46:34 +00:00
|
|
|
ve.dm.MWInlineImageNode = function VeDmMWInlineImageNode( length, element ) {
|
2013-04-10 19:56:20 +00:00
|
|
|
ve.dm.ImageNode.call( this, 0, element );
|
2013-03-27 22:56:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2013-04-24 23:46:34 +00:00
|
|
|
ve.inheritClass( ve.dm.MWInlineImageNode, ve.dm.ImageNode );
|
2013-03-27 22:56:54 +00:00
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
2013-04-24 23:46:34 +00:00
|
|
|
ve.dm.MWInlineImageNode.static.name = 'MWinlineimage';
|
2013-03-27 22:56:54 +00:00
|
|
|
|
2013-04-24 23:46:34 +00:00
|
|
|
ve.dm.MWInlineImageNode.static.matchTagNames = null;
|
2013-03-27 22:56:54 +00:00
|
|
|
|
2013-04-03 22:59:46 +00:00
|
|
|
// TODO: Develop better method to test for generated content
|
2013-04-24 23:46:34 +00:00
|
|
|
ve.dm.MWInlineImageNode.static.generatedContent = true;
|
2013-04-03 22:59:46 +00:00
|
|
|
|
2013-04-24 23:46:34 +00:00
|
|
|
ve.dm.MWInlineImageNode.static.matchRdfaTypes = [ 'mw:Image' ];
|
2013-03-27 22:56:54 +00:00
|
|
|
|
2013-04-24 23:46:34 +00:00
|
|
|
ve.dm.MWInlineImageNode.static.toDataElement = function ( domElements ) {
|
2013-05-08 04:25:55 +00:00
|
|
|
var children = Array.prototype.slice.call( domElements[0].children, 0 ),
|
2013-04-10 19:56:20 +00:00
|
|
|
parentResult = ve.dm.ImageNode.static.toDataElement.apply(
|
|
|
|
this, [ children ].concat( Array.prototype.slice.call( arguments, 1 ) )
|
2013-05-08 04:25:55 +00:00
|
|
|
);
|
|
|
|
return ve.extendObject( true, parentResult, {
|
2013-04-24 23:46:34 +00:00
|
|
|
'type': 'MWinlineimage',
|
2013-03-27 22:56:54 +00:00
|
|
|
'attributes': {
|
2013-04-10 19:56:20 +00:00
|
|
|
'isLinked': domElements[0].nodeName.toLowerCase() === 'a'
|
|
|
|
}
|
|
|
|
} );
|
2013-03-27 22:56:54 +00:00
|
|
|
};
|
|
|
|
|
2013-04-24 23:46:34 +00:00
|
|
|
ve.dm.MWInlineImageNode.static.toDomElements = function ( dataElement, doc ) {
|
2013-05-08 04:25:55 +00:00
|
|
|
var wrapper = doc.createElement( dataElement.attributes.isLinked ? 'a' : 'span' ),
|
2013-04-10 19:56:20 +00:00
|
|
|
imageDomElement = ve.dm.ImageNode.static.toDomElements.apply( this, arguments )[0];
|
|
|
|
wrapper.appendChild( imageDomElement );
|
|
|
|
return [ wrapper ];
|
2013-03-29 11:57:42 +00:00
|
|
|
};
|
|
|
|
|
2013-03-27 22:56:54 +00:00
|
|
|
/* Registration */
|
|
|
|
|
2013-04-24 23:46:34 +00:00
|
|
|
ve.dm.modelRegistry.register( ve.dm.MWInlineImageNode );
|