All files / src/dm/nodes ve.dm.InlineImageNode.js

100% Statements 19/19
100% Branches 8/8
100% Functions 3/3
100% Lines 19/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65                                1x   233x     233x         1x   1x       1x   1x   1x   1x 29x 29x 29x 29x   29x                     1x 9x 9x 9x         1x  
/*!
 * VisualEditor DataModel InlineImageNode class.
 *
 * @copyright 2011-2020 VisualEditor Team and others; see http://ve.mit-license.org
 */
 
/**
 * DataModel inline image node.
 *
 * @class
 * @extends ve.dm.LeafNode
 * @mixins ve.dm.ImageNode
 *
 * @constructor
 * @param {Object} [element] Reference to element in linear model
 */
ve.dm.InlineImageNode = function VeDmInlineImageNode() {
	// Parent constructor
	ve.dm.InlineImageNode.super.apply( this, arguments );
 
	// Mixin constructor
	ve.dm.ImageNode.call( this );
};
 
/* Inheritance */
 
OO.inheritClass( ve.dm.InlineImageNode, ve.dm.LeafNode );
 
OO.mixinClass( ve.dm.InlineImageNode, ve.dm.ImageNode );
 
/* Static Properties */
 
ve.dm.InlineImageNode.static.name = 'inlineImage';
 
ve.dm.InlineImageNode.static.isContent = true;
 
ve.dm.InlineImageNode.static.matchTagNames = [ 'img' ];
 
ve.dm.InlineImageNode.static.toDataElement = function ( domElements ) {
	var domElement = domElements[ 0 ],
		alt = domElement.getAttribute( 'alt' ),
		width = domElement.getAttribute( 'width' ),
		height = domElement.getAttribute( 'height' );
 
	return {
		type: this.name,
		attributes: {
			src: domElement.getAttribute( 'src' ),
			alt: alt,
			width: width !== null && width !== '' ? +width : null,
			height: height !== null && height !== '' ? +height : null
		}
	};
};
 
ve.dm.InlineImageNode.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.InlineImageNode );