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

80.77% Statements 21/26
38.89% Branches 7/18
83.33% Functions 5/6
80.77% Lines 21/26

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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106                                1x   252x 252x         1x   1x             1x   8x           1x 2x 2x           2x                       2x 2x 2x 2x     2x           1x 2x                     2x               1x 11x                      
/*!
 * VisualEditor DataModel ImageNode class.
 *
 * @copyright 2011-2020 VisualEditor Team and others; see http://ve.mit-license.org
 */
 
/**
 * DataModel image node.
 *
 * @class
 * @abstract
 * @mixins ve.dm.FocusableNode
 * @mixins ve.dm.ResizableNode
 *
 * @constructor
 */
ve.dm.ImageNode = function VeDmImageNode() {
	// Mixin constructors
	ve.dm.FocusableNode.call( this );
	ve.dm.ResizableNode.call( this );
};
 
/* Inheritance */
 
OO.mixinClass( ve.dm.ImageNode, ve.dm.FocusableNode );
 
OO.mixinClass( ve.dm.ImageNode, ve.dm.ResizableNode );
 
/* Static Methods */
 
/**
 * @inheritdoc ve.dm.Model
 */
ve.dm.ImageNode.static.isDiffComparable = function ( element, other ) {
	// Images with different src's shouldn't be diffed
	return element.type === other.type && element.attributes.src === other.attributes.src;
};
 
/**
 * @inheritdoc ve.dm.Model
 */
ve.dm.ImageNode.static.describeChanges = function ( attributeChanges, attributes ) {
	var customKeys = [ 'width', 'height' ],
		descriptions = [];
 
	function describeSize( width, height ) {
		return width + ve.msg( 'visualeditor-dimensionswidget-times' ) + height + ve.msg( 'visualeditor-dimensionswidget-px' );
	}
 
	Iif ( 'width' in attributeChanges || 'height' in attributeChanges ) {
		var sizeFrom = describeSize(
			'width' in attributeChanges ? attributeChanges.width.from : attributes.width,
			'height' in attributeChanges ? attributeChanges.height.from : attributes.height
		);
		var sizeTo = describeSize(
			'width' in attributeChanges ? attributeChanges.width.to : attributes.width,
			'height' in attributeChanges ? attributeChanges.height.to : attributes.height
		);
 
		descriptions.push( ve.htmlMsg( 'visualeditor-changedesc-image-size', this.wrapText( 'del', sizeFrom ), this.wrapText( 'ins', sizeTo ) ) );
	}
	for ( var key in attributeChanges ) {
		Eif ( customKeys.indexOf( key ) === -1 ) {
			var change = this.describeChange( key, attributeChanges[ key ] );
			descriptions.push( change );
		}
	}
	return descriptions;
};
 
/**
 * @inheritdoc ve.dm.Node
 */
ve.dm.ImageNode.static.describeChange = function ( key, change ) {
	Iif ( key === 'align' ) {
		// The following messages are used here:
		// * visualeditor-align-desc-left
		// * visualeditor-align-desc-right
		// * visualeditor-align-desc-center
		return ve.htmlMsg( 'visualeditor-changedesc-align',
			this.wrapText( 'del', ve.msg( 'visualeditor-align-desc-' + change.from ) ),
			this.wrapText( 'ins', ve.msg( 'visualeditor-align-desc-' + change.to ) )
		);
	}
	// Parent method
	return ve.dm.Node.static.describeChange.apply( this, arguments );
};
 
/* Methods */
 
/**
 * @inheritdoc
 */
ve.dm.ImageNode.prototype.createScalable = function () {
	return new ve.dm.Scalable( {
		currentDimensions: {
			width: this.getAttribute( 'width' ),
			height: this.getAttribute( 'height' )
		},
		minDimensions: {
			width: 1,
			height: 1
		}
	} );
};