mediawiki-extensions-Visual.../modules/ve/dm/nodes/ve.dm.ImageNode.js
Trevor Parscal efafed3231 Remove ve.{inheritClass,mixinClass} and use OO instead
Change-Id: I8df9226a358a76b661eab6e967ff0d63d361f691
2013-10-18 18:58:08 +02:00

60 lines
1.5 KiB
JavaScript

/*!
* VisualEditor DataModel ImageNode class.
*
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* DataModel 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.ImageNode = function VeDmImageNode( length, element ) {
// Parent constructor
ve.dm.LeafNode.call( this, 0, element );
};
/* Inheritance */
OO.inheritClass( ve.dm.ImageNode, ve.dm.LeafNode );
/* Static Properties */
ve.dm.ImageNode.static.name = 'image';
ve.dm.ImageNode.static.isContent = true;
ve.dm.ImageNode.static.matchTagNames = [ 'img' ];
ve.dm.ImageNode.static.toDataElement = function ( domElements ) {
var $node = $( domElements[0] ),
alt = $node.attr( 'alt' ),
width = $node.attr( 'width' ),
height = $node.attr( 'height' );
return {
'type': 'image',
'attributes': {
'src': $node.attr( 'src' ),
'alt': alt !== undefined ? alt : null,
'width': width !== undefined && width !== '' ? Number( width ) : null,
'height': height !== undefined && height !== '' ? Number( height ) : null
}
};
};
ve.dm.ImageNode.static.toDomElements = function ( dataElement, doc ) {
var domElement = doc.createElement( 'img' );
ve.setDomAttributes( domElement, dataElement.attributes, [ 'alt', 'src', 'width', 'height' ] );
return [ domElement ];
};
/* Registration */
ve.dm.modelRegistry.register( ve.dm.ImageNode );