All files / src/dm ve.dm.ResizableNode.js

100% Statements 14/14
100% Branches 6/6
100% Functions 4/4
100% Lines 14/14

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                              1x 264x   264x         1x                 1x 44x 16x   44x                 1x                 1x 4x 2x                 1x 6x          
/*!
 * VisualEditor DataModel Resizable node.
 *
 * @copyright See AUTHORS.txt
 */
 
/**
 * A mixin class for resizable nodes. This class is mostly a base
 * interface for resizable nodes to be able to produce scalable
 * objects for further calculation.
 *
 * @class
 * @abstract
 * @constructor
 */
ve.dm.ResizableNode = function VeDmResizableNode() {
	this.scalable = null;
 
	this.connect( this, { attributeChange: 'onResizableAttributeChange' } );
};
 
/* Inheritance */
 
OO.initClass( ve.dm.ResizableNode );
 
/**
 * Get a scalable object for this node.
 *
 * #createScalable is called if one doesn't already exist.
 *
 * @return {ve.dm.Scalable}
 */
ve.dm.ResizableNode.prototype.getScalable = function () {
	if ( !this.scalable ) {
		this.scalable = this.createScalable();
	}
	return this.scalable;
};
 
/**
 * Create a scalable object based on the current object's width and height.
 *
 * @abstract
 * @return {ve.dm.Scalable}
 */
ve.dm.ResizableNode.prototype.createScalable = null;
 
/**
 * Handle attribute change events from the model.
 *
 * @param {string} key Attribute key
 * @param {string} from Old value
 * @param {string} to New value
 */
ve.dm.ResizableNode.prototype.onResizableAttributeChange = function ( key ) {
	if ( key === 'width' || key === 'height' ) {
		this.getScalable().setCurrentDimensions( this.getCurrentDimensions() );
	}
};
 
/**
 * Get the current dimensions from the model
 *
 * @return {Object} Current dimensions
 */
ve.dm.ResizableNode.prototype.getCurrentDimensions = function () {
	return {
		width: this.getAttribute( 'width' ),
		height: this.getAttribute( 'height' )
	};
};