mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-12-18 17:21:25 +00:00
3a3437007a
Preserve the place of annotation meta tags; adds information for the users about annotation and, if necessary, annotation range extension. The messages and individual handling of annotations for the annotation range can be defined by the extensions: see I0b58a418 for an example of how that can look like. The structure of this patch closely follows the one from I104e7abbd (handling of <noinclude> et al.). Bug: T261181 Change-Id: I39029e4a63d22b37107edec066006557bcff34bf
66 lines
1.5 KiB
JavaScript
66 lines
1.5 KiB
JavaScript
/*!
|
|
* VisualEditor DataModel MWAnnotationNode class.
|
|
*
|
|
* @copyright 2011-2021 VisualEditor Team and others; 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 ) {
|
|
var 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 ) {
|
|
var 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 ];
|
|
};
|