Debian Codegraph @

extensions/VisualEditor/lib/ve/src/dm/annotations/ve.dm.CommentAnnotation.js

raw symbols SCIP
1 /*!
2 * VisualEditor DataModel CommentAnnotation class.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 /**
8 * DataModel comment annotation.
9 *
10 * @class
11 * @extends ve.dm.Annotation
12 * @constructor
13 * @param {Object} element
14 */
15 ve.dm.CommentAnnotation = function VeDmCommentAnnotation() {
16 // Parent constructor
17 ve.dm.CommentAnnotation.super.apply( this, arguments );
18 };
19
20 /* Inheritance */
21
22 OO.inheritClass( ve.dm.CommentAnnotation, ve.dm.Annotation );
23
24 /* Static Properties */
25
26 ve.dm.CommentAnnotation.static.name = 'commentAnnotation';
27
28 ve.dm.CommentAnnotation.static.matchTagNames = [ 'span' ];
29
30 ve.dm.CommentAnnotation.static.matchRdfaTypes = [ 've:CommentAnnotation' ];
31
32 // ve.dm.CommentAnnotation.static.applyToAppendedContent = true;
33
34 ve.dm.CommentAnnotation.static.toDataElement = function ( domElements ) {
35 return {
36 type: this.name,
37 attributes: {
38 text: domElements[ 0 ].getAttribute( 'data-text' ) || ''
39 }
40 };
41 };
42
43 ve.dm.CommentAnnotation.static.toDomElements = function ( dataElement, doc, converter ) {
44 if ( converter.isForParser() || converter.isForPreview() ) {
45 // TODO: Return some nodes for preview?
46 return [];
47 } else {
48 const domElement = doc.createElement( 'span' );
49 domElement.setAttribute( 'rel', 've:CommentAnnotation' );
50 if ( dataElement.attributes.text ) {
51 domElement.setAttribute( 'data-text', dataElement.attributes.text );
52 }
53 return [ domElement ];
54 }
55 };
56
57 /* Methods */
58
59 ve.dm.CommentAnnotation.prototype.getAttribute = function ( key ) {
60 // Support old documents with text attributes
61 if ( key === 'comments' && this.getAttribute( 'text' ) ) {
62 return [ {
63 author: '',
64 text: this.getAttribute( 'text' )
65 } ].concat(
66 ve.dm.CommentAnnotation.super.prototype.getAttribute.call( this, 'comments' ) || []
67 );
68 }
69 // Parent method
70 return ve.dm.CommentAnnotation.super.prototype.getAttribute.call( this, key );
71 };
72
73 /* Registration */
74
75 ve.dm.modelRegistry.register( ve.dm.CommentAnnotation );