All files / src/ui/contextitems ve.ui.CommentAnnotationContextItem.js

54.16% Statements 13/24
100% Branches 0/0
0% Functions 0/5
56.52% Lines 13/23

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 77 78 79 80 81 82 83 84                                1x                       1x       1x   1x   1x   1x   1x   1x   1x   1x               1x                                         1x             1x  
/*!
 * VisualEditor CommentAnnotationContextItem class.
 *
 * @copyright See AUTHORS.txt
 */
 
/**
 * Context item for a comment.
 *
 * @class
 * @extends ve.ui.AnnotationContextItem
 *
 * @param {ve.ui.LinearContext} context Context the item is in
 * @param {ve.dm.Model} model Model the item is related to
 * @param {Object} [config] Configuration options
 */
ve.ui.CommentAnnotationContextItem = function VeUiCommentAnnotationContextItem( context, model, config ) {
	// Parent constructor
	ve.ui.CommentAnnotationContextItem.super.call( this, context, model, config );
 
	// Initialization
	this.$element.addClass( 've-ui-commentAnnotationContextItem' );
 
	this.editButton.setLabel( ve.msg( 'visualeditor-commentannotationcontextitem-comment' ) );
};
 
/* Inheritance */
 
OO.inheritClass( ve.ui.CommentAnnotationContextItem, ve.ui.AnnotationContextItem );
 
/* Static Properties */
 
ve.ui.CommentAnnotationContextItem.static.name = 'commentAnnotation';
 
ve.ui.CommentAnnotationContextItem.static.icon = 'speechBubble';
 
ve.ui.CommentAnnotationContextItem.static.label = OO.ui.deferMsg( 'visualeditor-commentinspector-title' );
 
ve.ui.CommentAnnotationContextItem.static.modelClasses = [ ve.dm.CommentAnnotation ];
 
ve.ui.CommentAnnotationContextItem.static.embeddable = false;
 
ve.ui.CommentAnnotationContextItem.static.commandName = 'commentAnnotation';
 
ve.ui.CommentAnnotationContextItem.static.clearable = true;
 
ve.ui.CommentAnnotationContextItem.static.clearIcon = 'trash';
 
/* Static methods */
 
/**
 * @param {ve.dm.CommentAnnotation} model
 * @return {jQuery}
 */
ve.ui.CommentAnnotationContextItem.static.renderThread = function ( model ) {
	let $thread = $( [] );
 
	model.getAttribute( 'comments' ).forEach( ( comment ) => {
		const $lineDivs = comment.text.split( '\n' ).map( ( line ) => $( '<div>' ).text( line ) );
		$thread = $thread.add(
			$( '<div>' ).addClass( 've-ui-commentAnnotationContextItem-comment' ).append(
				$( '<strong>' ).text( comment.author ),
				$lineDivs
			)
		);
	} );
 
	return $thread;
};
 
/* Methods */
 
/**
 * @inheritdoc
 */
ve.ui.CommentAnnotationContextItem.prototype.renderBody = function () {
	const $thread = this.constructor.static.renderThread( this.model );
	this.$body.append( $thread );
};
 
/* Registration */
 
ve.ui.contextItemFactory.register( ve.ui.CommentAnnotationContextItem );