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
|
|
|
|
* @extends ve.dm.LeafNode
|
|
|
|
* @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 ) {
|
|
|
|
ve.dm.LeafNode.call( this, 0, element );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
ve.inheritClass( ve.dm.MWImageNode, ve.dm.LeafNode );
|
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
|
|
|
ve.dm.MWImageNode.static.name = 'MWimage';
|
|
|
|
|
|
|
|
ve.dm.MWImageNode.static.isContent = true;
|
|
|
|
|
|
|
|
ve.dm.MWImageNode.static.matchRdfaTypes = [ 'mw:Image' ];
|
|
|
|
|
2013-03-29 11:57:42 +00:00
|
|
|
ve.dm.MWImageNode.static.storeHtmlAttributes = false;
|
|
|
|
|
2013-03-27 22:56:54 +00:00
|
|
|
ve.dm.MWImageNode.static.toDataElement = function ( domElements ) {
|
2013-03-29 11:57:42 +00:00
|
|
|
var $node = $( domElements[0].childNodes[0] ),
|
|
|
|
width = $node.attr( 'width' ),
|
|
|
|
height = $node.attr( 'height' ),
|
|
|
|
html = $( '<div>', domElements[0].ownerDocument ).append( $( domElements ).clone() ).html();
|
|
|
|
|
2013-03-27 22:56:54 +00:00
|
|
|
return {
|
2013-03-29 11:57:42 +00:00
|
|
|
'type': this.name,
|
2013-03-27 22:56:54 +00:00
|
|
|
'attributes': {
|
2013-03-29 11:57:42 +00:00
|
|
|
'src': $node.attr( 'src' ),
|
|
|
|
'width': width !== '' ? Number( width ) : null,
|
|
|
|
'height': height !== '' ? Number( height ) : null,
|
|
|
|
// TODO: don't store html, just enough attributes to rebuild
|
|
|
|
'html': html
|
|
|
|
},
|
2013-03-27 22:56:54 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2013-03-29 11:57:42 +00:00
|
|
|
ve.dm.MWImageNode.static.toDomElements = function ( dataElement ) {
|
|
|
|
//TODO: rebuild html from attributes
|
|
|
|
var wrapper = document.createElement( 'div' );
|
|
|
|
wrapper.innerHTML = dataElement.attributes.html;
|
|
|
|
// Convert wrapper.children to an array
|
|
|
|
return Array.prototype.slice.call( wrapper.childNodes, 0 );
|
|
|
|
};
|
|
|
|
|
2013-03-27 22:56:54 +00:00
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.dm.modelRegistry.register( ve.dm.MWImageNode );
|