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

100% Statements 18/18
75% Branches 6/8
100% Functions 3/3
100% Lines 18/18
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                                                                                     
/*!
 * VisualEditor DataModel CommentAnnotation class.
 *
 * @copyright 2011-2019 VisualEditor Team and others; see http://ve.mit-license.org
 */
 
/**
 * 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 ) {
	var domElement;
	if ( converter.isForParser() || converter.isForPreview() ) {
		// TODO: Return some nodes for preview?
		return [];
	} else {
		domElement = doc.createElement( 'span' );
		domElement.setAttribute( 'rel', 've:CommentAnnotation' );
		Eif ( dataElement.attributes.text ) {
			domElement.setAttribute( 'data-text', dataElement.attributes.text );
		}
		return [ domElement ];
	}
};
 
/* Registration */
 
ve.dm.modelRegistry.register( ve.dm.CommentAnnotation );