All files / src/dm/annotations ve.dm.CommentAnnotation.js

85.71% Statements 18/21
42.85% Branches 6/14
75% Functions 3/4
85.71% Lines 18/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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