Debian Codegraph @

extensions/VisualEditor/lib/ve/src/dm/ve.dm.ResizableNode.js

raw symbols SCIP
1 /*!
2 * VisualEditor DataModel Resizable node.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 /**
8 * A mixin class for resizable nodes. This class is mostly a base
9 * interface for resizable nodes to be able to produce scalable
10 * objects for further calculation.
11 *
12 * @class
13 * @abstract
14 * @constructor
15 */
16 ve.dm.ResizableNode = function VeDmResizableNode() {
17 this.scalable = null;
18
19 this.connect( this, { attributeChange: 'onResizableAttributeChange' } );
20 };
21
22 /* Inheritance */
23
24 OO.initClass( ve.dm.ResizableNode );
25
26 /**
27 * Get a scalable object for this node.
28 *
29 * #createScalable is called if one doesn't already exist.
30 *
31 * @return {ve.dm.Scalable}
32 */
33 ve.dm.ResizableNode.prototype.getScalable = function () {
34 if ( !this.scalable ) {
35 this.scalable = this.createScalable();
36 }
37 return this.scalable;
38 };
39
40 /**
41 * Create a scalable object based on the current object's width and height.
42 *
43 * @abstract
44 * @return {ve.dm.Scalable}
45 */
46 ve.dm.ResizableNode.prototype.createScalable = null;
47
48 /**
49 * Handle attribute change events from the model.
50 *
51 * @param {string} key Attribute key
52 * @param {string} from Old value
53 * @param {string} to New value
54 */
55 ve.dm.ResizableNode.prototype.onResizableAttributeChange = function ( key ) {
56 if ( key === 'width' || key === 'height' ) {
57 this.getScalable().setCurrentDimensions( this.getCurrentDimensions() );
58 }
59 };
60
61 /**
62 * Get the current dimensions from the model
63 *
64 * @return {Object} Current dimensions
65 */
66 ve.dm.ResizableNode.prototype.getCurrentDimensions = function () {
67 return {
68 width: this.getAttribute( 'width' ),
69 height: this.getAttribute( 'height' )
70 };
71 };