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
|
|
|
|
*/
|
|
|
|
ve.dm.MWImageNode = function VeDmMWImageNode( 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-10 19:56:20 +00:00
|
|
|
ve.inheritClass( ve.dm.MWImageNode, ve.dm.ImageNode );
|
2013-03-27 22:56:54 +00:00
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
|
|
|
ve.dm.MWImageNode.static.name = 'MWimage';
|
|
|
|
|
2013-04-10 19:56:20 +00:00
|
|
|
ve.dm.MWImageNode.static.matchTagNames = null;
|
2013-03-27 22:56:54 +00:00
|
|
|
|
|
|
|
ve.dm.MWImageNode.static.matchRdfaTypes = [ 'mw:Image' ];
|
|
|
|
|
|
|
|
ve.dm.MWImageNode.static.toDataElement = function ( domElements ) {
|
2013-04-10 19:56:20 +00:00
|
|
|
var i, j, childNode, children = Array.prototype.slice.call( domElements[0].children, 0 ),
|
|
|
|
parentResult = ve.dm.ImageNode.static.toDataElement.apply(
|
|
|
|
this, [ children ].concat( Array.prototype.slice.call( arguments, 1 ) )
|
|
|
|
),
|
|
|
|
dataElement = ve.copyObject( parentResult );
|
|
|
|
|
|
|
|
// Preserve the child nodes' attributes in html/0-i/foo
|
|
|
|
for ( i = 0; i < domElements[0].childNodes.length; i++ ) {
|
|
|
|
childNode = domElements[0].childNodes[i];
|
|
|
|
for ( j = 0; j < childNode.attributes.length; j++ ) {
|
|
|
|
dataElement.attributes['html/0-' + i + '/' + childNode.attributes[j].name] =
|
|
|
|
childNode.attributes[j].value;
|
|
|
|
}
|
|
|
|
}
|
2013-03-29 11:57:42 +00:00
|
|
|
|
2013-04-10 19:56:20 +00:00
|
|
|
return ve.extendObject( true, dataElement, {
|
|
|
|
'type': 'MWimage',
|
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-02 20:23:16 +00:00
|
|
|
ve.dm.MWImageNode.static.toDomElements = function ( dataElement, doc ) {
|
2013-04-10 19:56:20 +00:00
|
|
|
var k, wrapper = doc.createElement( dataElement.attributes.isLinked ? 'a' : 'span' ),
|
|
|
|
imageDomElement = ve.dm.ImageNode.static.toDomElements.apply( this, arguments )[0];
|
|
|
|
|
|
|
|
wrapper.appendChild( imageDomElement );
|
|
|
|
// Restore attributes from html/0-0/*
|
|
|
|
for ( k in dataElement.attributes ) {
|
|
|
|
if ( k.indexOf( 'html/0-0/' ) === 0 ) {
|
|
|
|
imageDomElement.setAttribute( k.substr( 9 ), dataElement.attributes[k] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return [ wrapper ];
|
2013-03-29 11:57:42 +00:00
|
|
|
};
|
|
|
|
|
2013-03-27 22:56:54 +00:00
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.dm.modelRegistry.register( ve.dm.MWImageNode );
|