File: ve.dm.MWGalleryNode.js

package info (click to toggle)
mediawiki 1%3A1.43.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 417,464 kB
  • sloc: php: 1,062,949; javascript: 664,290; sql: 9,714; python: 5,458; xml: 3,489; sh: 1,131; makefile: 64
file content (131 lines) | stat: -rw-r--r-- 3,383 bytes parent folder | download | duplicates (2)
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*!
 * VisualEditor DataModel MWGalleryNode class.
 *
 * @copyright See AUTHORS.txt
 * @license The MIT License (MIT); see LICENSE.txt
 */

/**
 * DataModel MediaWiki gallery node.
 *
 * @class
 * @extends ve.dm.BranchNode
 * @mixes ve.dm.FocusableNode
 *
 * @constructor
 * @param {Object} [element] Reference to element in linear model
 */
ve.dm.MWGalleryNode = function VeDmMWGalleryNode() {
	// Parent constructor
	ve.dm.MWGalleryNode.super.apply( this, arguments );

	// Mixin constructors
	ve.dm.FocusableNode.call( this );
};

/* Inheritance */

OO.inheritClass( ve.dm.MWGalleryNode, ve.dm.BranchNode );

OO.mixinClass( ve.dm.MWGalleryNode, ve.dm.FocusableNode );

/* Static members */

ve.dm.MWGalleryNode.static.name = 'mwGallery';

ve.dm.MWGalleryNode.static.matchRdfaTypes = [ 'mw:Extension/gallery' ];

ve.dm.MWGalleryNode.static.matchTagNames = [ 'ul' ];

ve.dm.MWGalleryNode.static.childNodeTypes = [ 'mwGalleryCaption', 'mwGalleryImage' ];

ve.dm.MWGalleryNode.static.disallowedAnnotationTypes = [ 'link' ];

ve.dm.MWGalleryNode.static.cloneElement = function () {
	// Parent method
	const clone = ve.dm.LeafNode.static.cloneElement.apply( this, arguments );
	delete clone.attributes.originalMw;
	return clone;
};

ve.dm.MWGalleryNode.static.getHashObject = function ( dataElement ) {
	return {
		type: dataElement.type,
		mw: ve.copy( dataElement.attributes.mw )
	};
};

ve.dm.MWGalleryNode.static.toDataElement = function ( domElements ) {
	const mwDataJSON = domElements[ 0 ].getAttribute( 'data-mw' ),
		mwData = mwDataJSON ? JSON.parse( mwDataJSON ) : {};

	return {
		type: this.name,
		attributes: {
			mw: mwData,
			originalMw: mwDataJSON
		}
	};
};

ve.dm.MWGalleryNode.static.toDomElements = function ( data, doc ) {
	const ul = doc.createElement( 'ul' );

	// Build ul
	ul.setAttribute( 'typeof', 'mw:Extension/gallery' );
	ul.setAttribute( 'data-mw', JSON.stringify( data.attributes.mw ) );

	return [ ul ];
};

ve.dm.MWGalleryNode.static.describeChanges = function ( attributeChanges, attributes, element ) {
	// Only do a comparison on the 'mw.attrs' attribute
	if ( attributeChanges.mw ) {
		return ve.dm.MWGalleryNode.super.static.describeChanges.call(
			this,
			ve.ui.DiffElement.static.compareAttributes( attributeChanges.mw.from.attrs || {}, attributeChanges.mw.to.attrs || {} ),
			attributes,
			element
		);
	}
	return [];
};

ve.dm.MWGalleryNode.static.describeChange = function ( key ) {
	// Caption diff is shown in the DOM
	if ( key === 'caption' ) {
		return null;
	}
	// Parent method
	return ve.dm.MWGalleryNode.super.static.describeChange.apply( this, arguments );
};

/* Methods */

ve.dm.MWGalleryNode.prototype.isDiffedAsDocument = function () {
	return true;
};

/**
 * Get the gallery's caption node.
 *
 * @return {ve.dm.MWImageCaptionNode|null} Caption node, if present
 */
ve.dm.MWGalleryNode.prototype.getCaptionNode = function () {
	const node = this.children[ 0 ];
	return node instanceof ve.dm.MWGalleryCaptionNode ? node : null;
};

/**
 * Get the gallery's image nodes.
 *
 * @return {ve.dm.MWGalleryImageNode[]} Gallery image nodes (may be empty if none are present)
 */
ve.dm.MWGalleryNode.prototype.getImageNodes = function () {
	const images = this.children.filter( ( child ) => child instanceof ve.dm.MWGalleryImageNode );
	return images;
};

/* Registration */

ve.dm.modelRegistry.register( ve.dm.MWGalleryNode );