mediawiki-extensions-Visual.../modules/ve-mw/dm/nodes/ve.dm.MWAnnotationNode.js
Ed Sanders dbc696124f ESLint: Enforce no-var and autofix
Temporarily disable prefer-const as this requires
manual fixing.

Change-Id: I477b69a57e8d33535c6fc71dba196a8605780725
2024-05-21 17:40:52 +01:00

66 lines
1.4 KiB
JavaScript

/*!
* VisualEditor DataModel MWAnnotationNode class.
*
* @copyright See AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* DataModel MW node for mw:Annotation tags.
*
* @class
* @extends ve.dm.AlienInlineNode
* @constructor
* @param {Object} element Reference to element in linear model
*/
ve.dm.MWAnnotationNode = function VeDmMWAnnotationNode() {
// Parent constructor
ve.dm.MWAnnotationNode.super.apply( this, arguments );
};
/* Inheritance */
OO.inheritClass( ve.dm.MWAnnotationNode, ve.dm.AlienInlineNode );
/* Static Properties */
ve.dm.MWAnnotationNode.static.name = 'mwAnnotation';
ve.dm.MWAnnotationNode.static.preserveHtmlAttributes = true;
/* Static Methods */
/**
* @inheritdoc
*/
ve.dm.MWAnnotationNode.static.toDataElement = function ( domElements ) {
let dataElement,
mwDataJSON = domElements[ 0 ].getAttribute( 'data-mw' ),
type = domElements[ 0 ].getAttribute( 'typeof' );
dataElement = {
type: 'mwAnnotation',
attributes: {
type: type
}
};
if ( mwDataJSON !== null ) {
dataElement.attributes.mw = JSON.parse( mwDataJSON );
}
return dataElement;
};
ve.dm.MWAnnotationNode.static.toDomElements = function ( dataElement, doc ) {
let el;
el = doc.createElement( 'meta' );
el.setAttribute( 'typeof', dataElement.attributes.type );
if ( dataElement.attributes.mw ) {
el.setAttribute( 'data-mw', JSON.stringify( dataElement.attributes.mw ) );
}
return [ el ];
};