Debian Codegraph @

extensions/VisualEditor/modules/ve-mw/dm/nodes/ve.dm.MWAnnotationNode.js

raw symbols SCIP
1 /*!
2 * VisualEditor DataModel MWAnnotationNode class.
3 *
4 * @copyright See AUTHORS.txt
5 * @license The MIT License (MIT); see LICENSE.txt
6 */
7
8 /**
9 * DataModel MW node for mw:Annotation tags.
10 *
11 * @class
12 * @extends ve.dm.AlienInlineNode
13 * @constructor
14 * @param {Object} element Reference to element in linear model
15 */
16 ve.dm.MWAnnotationNode = function VeDmMWAnnotationNode() {
17 // Parent constructor
18 ve.dm.MWAnnotationNode.super.apply( this, arguments );
19 };
20
21 /* Inheritance */
22
23 OO.inheritClass( ve.dm.MWAnnotationNode, ve.dm.AlienInlineNode );
24
25 /* Static Properties */
26
27 ve.dm.MWAnnotationNode.static.name = 'mwAnnotation';
28
29 ve.dm.MWAnnotationNode.static.preserveHtmlAttributes = true;
30
31 /* Static Methods */
32
33 /**
34 * @inheritdoc
35 */
36 ve.dm.MWAnnotationNode.static.toDataElement = function ( domElements ) {
37 const mwDataJSON = domElements[ 0 ].getAttribute( 'data-mw' ),
38 type = domElements[ 0 ].getAttribute( 'typeof' );
39
40 const dataElement = {
41 type: 'mwAnnotation',
42 attributes: {
43 type: type
44 }
45 };
46
47 if ( mwDataJSON !== null ) {
48 dataElement.attributes.mw = JSON.parse( mwDataJSON );
49 }
50
51 return dataElement;
52 };
53
54 ve.dm.MWAnnotationNode.static.toDomElements = function ( dataElement, doc ) {
55 const el = doc.createElement( 'meta' );
56 el.setAttribute( 'typeof', dataElement.attributes.type );
57 if ( dataElement.attributes.mw ) {
58 el.setAttribute( 'data-mw', JSON.stringify( dataElement.attributes.mw ) );
59 }
60
61 return [ el ];
62 };