Debian Codegraph @

extensions/VisualEditor/lib/ve/src/dm/nodes/ve.dm.ImageNode.js

raw symbols SCIP
1 /*!
2 * VisualEditor DataModel ImageNode class.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 /**
8 * DataModel image node.
9 *
10 * @class
11 * @abstract
12 * @mixes ve.dm.FocusableNode
13 * @mixes ve.dm.ResizableNode
14 *
15 * @constructor
16 */
17 ve.dm.ImageNode = function VeDmImageNode() {
18 // Mixin constructors
19 ve.dm.FocusableNode.call( this );
20 ve.dm.ResizableNode.call( this );
21 };
22
23 /* Inheritance */
24
25 OO.mixinClass( ve.dm.ImageNode, ve.dm.FocusableNode );
26
27 OO.mixinClass( ve.dm.ImageNode, ve.dm.ResizableNode );
28
29 /* Static Methods */
30
31 // eslint-disable-next-line jsdoc/require-param, jsdoc/require-returns
32 /**
33 * @see ve.dm.Model
34 */
35 ve.dm.ImageNode.static.isDiffComparable = function ( element, other ) {
36 // Images with different src's shouldn't be diffed
37 return element.type === other.type && element.attributes.src === other.attributes.src;
38 };
39
40 // eslint-disable-next-line jsdoc/require-param, jsdoc/require-returns
41 /**
42 * @see ve.dm.Model
43 */
44 ve.dm.ImageNode.static.describeChanges = function ( attributeChanges, attributes ) {
45 const customKeys = [ 'width', 'height' ],
46 descriptions = [];
47
48 function describeSize( width, height ) {
49 return width + ve.msg( 'visualeditor-dimensionswidget-times' ) + height + ve.msg( 'visualeditor-dimensionswidget-px' );
50 }
51
52 if ( 'width' in attributeChanges || 'height' in attributeChanges ) {
53 const sizeFrom = describeSize(
54 'width' in attributeChanges ? attributeChanges.width.from : attributes.width,
55 'height' in attributeChanges ? attributeChanges.height.from : attributes.height
56 );
57 const sizeTo = describeSize(
58 'width' in attributeChanges ? attributeChanges.width.to : attributes.width,
59 'height' in attributeChanges ? attributeChanges.height.to : attributes.height
60 );
61
62 descriptions.push( ve.htmlMsg( 'visualeditor-changedesc-image-size', this.wrapText( 'del', sizeFrom ), this.wrapText( 'ins', sizeTo ) ) );
63 }
64 for ( const key in attributeChanges ) {
65 if ( customKeys.indexOf( key ) === -1 ) {
66 const change = this.describeChange( key, attributeChanges[ key ] );
67 if ( change ) {
68 descriptions.push( change );
69 }
70 }
71 }
72 return descriptions;
73 };
74
75 // eslint-disable-next-line jsdoc/require-param, jsdoc/require-returns
76 /**
77 * @see ve.dm.Node
78 */
79 ve.dm.ImageNode.static.describeChange = function ( key, change ) {
80 switch ( key ) {
81 case 'align':
82 // The following messages are used here:
83 // * visualeditor-align-desc-left
84 // * visualeditor-align-desc-right
85 // * visualeditor-align-desc-center
86 // Also used in ve-mw (consider downstreaming these messages)
87 // * visualeditor-align-desc-default
88 // * visualeditor-align-desc-none
89 return ve.htmlMsg( 'visualeditor-changedesc-align',
90 this.wrapText( 'del', ve.msg( 'visualeditor-align-desc-' + change.from ) ),
91 this.wrapText( 'ins', ve.msg( 'visualeditor-align-desc-' + change.to ) )
92 );
93 // ClassAttributeNode attributes
94 case 'originalClasses':
95 case 'unrecognizedClasses':
96 return;
97 }
98
99 // Parent method
100 return ve.dm.Node.static.describeChange.apply( this, arguments );
101 };
102
103 /* Methods */
104
105 /**
106 * @inheritdoc
107 */
108 ve.dm.ImageNode.prototype.createScalable = function () {
109 return new ve.dm.Scalable( {
110 currentDimensions: {
111 width: this.getAttribute( 'width' ),
112 height: this.getAttribute( 'height' )
113 },
114 minDimensions: {
115 width: 1,
116 height: 1
117 }
118 } );
119 };