2014-01-15 03:04:58 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor DataModel MWGalleryNode class.
|
|
|
|
*
|
2023-12-01 16:06:11 +00:00
|
|
|
* @copyright See AUTHORS.txt
|
2014-01-15 03:04:58 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DataModel MediaWiki gallery node.
|
|
|
|
*
|
|
|
|
* @class
|
2016-11-19 23:11:06 +00:00
|
|
|
* @extends ve.dm.BranchNode
|
2024-04-29 17:51:41 +00:00
|
|
|
* @mixes ve.dm.FocusableNode
|
2014-01-15 03:04:58 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
2014-06-07 03:17:26 +00:00
|
|
|
* @param {Object} [element] Reference to element in linear model
|
2014-01-15 03:04:58 +00:00
|
|
|
*/
|
2014-06-07 03:17:26 +00:00
|
|
|
ve.dm.MWGalleryNode = function VeDmMWGalleryNode() {
|
2014-01-15 03:04:58 +00:00
|
|
|
// Parent constructor
|
2016-08-22 21:44:59 +00:00
|
|
|
ve.dm.MWGalleryNode.super.apply( this, arguments );
|
2016-11-19 23:11:06 +00:00
|
|
|
|
|
|
|
// Mixin constructors
|
|
|
|
ve.dm.FocusableNode.call( this );
|
2014-01-15 03:04:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2016-11-19 23:11:06 +00:00
|
|
|
OO.inheritClass( ve.dm.MWGalleryNode, ve.dm.BranchNode );
|
|
|
|
|
|
|
|
OO.mixinClass( ve.dm.MWGalleryNode, ve.dm.FocusableNode );
|
2014-01-15 03:04:58 +00:00
|
|
|
|
|
|
|
/* Static members */
|
|
|
|
|
|
|
|
ve.dm.MWGalleryNode.static.name = 'mwGallery';
|
|
|
|
|
2016-11-19 23:11:06 +00:00
|
|
|
ve.dm.MWGalleryNode.static.matchRdfaTypes = [ 'mw:Extension/gallery' ];
|
|
|
|
|
|
|
|
ve.dm.MWGalleryNode.static.matchTagNames = [ 'ul' ];
|
|
|
|
|
|
|
|
ve.dm.MWGalleryNode.static.childNodeTypes = [ 'mwGalleryCaption', 'mwGalleryImage' ];
|
|
|
|
|
2020-06-10 11:15:18 +00:00
|
|
|
ve.dm.MWGalleryNode.static.disallowedAnnotationTypes = [ 'link' ];
|
2016-11-19 23:11:06 +00:00
|
|
|
|
|
|
|
ve.dm.MWGalleryNode.static.cloneElement = function () {
|
|
|
|
// Parent method
|
2024-05-21 14:22:56 +00:00
|
|
|
const clone = ve.dm.LeafNode.static.cloneElement.apply( this, arguments );
|
2016-11-19 23:11:06 +00:00
|
|
|
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 ) {
|
2024-05-21 14:22:56 +00:00
|
|
|
const mwDataJSON = domElements[ 0 ].getAttribute( 'data-mw' ),
|
2016-11-19 23:11:06 +00:00
|
|
|
mwData = mwDataJSON ? JSON.parse( mwDataJSON ) : {};
|
|
|
|
|
|
|
|
return {
|
|
|
|
type: this.name,
|
|
|
|
attributes: {
|
|
|
|
mw: mwData,
|
|
|
|
originalMw: mwDataJSON
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
ve.dm.MWGalleryNode.static.toDomElements = function ( data, doc ) {
|
2024-05-21 14:22:56 +00:00
|
|
|
const ul = doc.createElement( 'ul' );
|
2014-01-15 03:04:58 +00:00
|
|
|
|
2016-11-19 23:11:06 +00:00
|
|
|
// Build ul
|
|
|
|
ul.setAttribute( 'typeof', 'mw:Extension/gallery' );
|
|
|
|
ul.setAttribute( 'data-mw', JSON.stringify( data.attributes.mw ) );
|
|
|
|
|
|
|
|
return [ ul ];
|
|
|
|
};
|
|
|
|
|
2018-04-04 17:00:41 +00:00
|
|
|
ve.dm.MWGalleryNode.static.describeChanges = function ( attributeChanges, attributes, element ) {
|
2018-04-04 16:28:26 +00:00
|
|
|
// 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 || {} ),
|
2018-04-04 17:00:41 +00:00
|
|
|
attributes,
|
|
|
|
element
|
2018-04-04 16:28:26 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
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 );
|
|
|
|
};
|
|
|
|
|
2016-11-19 23:11:06 +00:00
|
|
|
/* Methods */
|
|
|
|
|
2022-05-19 00:28:10 +00:00
|
|
|
ve.dm.MWGalleryNode.prototype.isDiffedAsDocument = function () {
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2016-11-19 23:11:06 +00:00
|
|
|
/**
|
|
|
|
* Get the gallery's caption node.
|
|
|
|
*
|
|
|
|
* @return {ve.dm.MWImageCaptionNode|null} Caption node, if present
|
|
|
|
*/
|
|
|
|
ve.dm.MWGalleryNode.prototype.getCaptionNode = function () {
|
2024-05-21 14:22:56 +00:00
|
|
|
const node = this.children[ 0 ];
|
2016-11-19 23:11:06 +00:00
|
|
|
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 () {
|
2024-05-21 14:22:56 +00:00
|
|
|
const images = this.children.filter( ( child ) => child instanceof ve.dm.MWGalleryImageNode );
|
2016-11-19 23:11:06 +00:00
|
|
|
return images;
|
|
|
|
};
|
2014-01-27 21:45:46 +00:00
|
|
|
|
2014-01-15 03:04:58 +00:00
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.dm.modelRegistry.register( ve.dm.MWGalleryNode );
|