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

59.09% Statements 13/22
100% Branches 0/0
0% Functions 0/5
59.09% Lines 13/22

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                                1x                       1x       1x   1x   1x   1x   1x   1x   1x   1x       1x                                           1x           1x  
/*!
 * VisualEditor CommentAnnotationContextItem class.
 *
 * @copyright 2011-2020 VisualEditor Team and others; see http://ve.mit-license.org
 */
 
/**
 * Context item for a comment.
 *
 * @class
 * @extends ve.ui.AnnotationContextItem
 *
 * @param {ve.ui.Context} context Context item is in
 * @param {ve.dm.Model} model Model 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 */
 
ve.ui.CommentAnnotationContextItem.static.renderThread = function ( model ) {
	var $thread = $( [] );
 
	model.getAttribute( 'comments' ).forEach( function ( comment ) {
		$thread = $thread.add(
			$( '<div>' ).addClass( 've-ui-commentAnnotationContextItem-comment' ).append(
				$( '<strong>' ).text( comment.author ),
				comment.text.split( '\n' ).map( function ( line ) {
					return $( '<div>' ).text( line );
				} )
			)
		);
	} );
 
	return $thread;
};
 
/* Methods */
 
/**
 * @inheritdoc
 */
ve.ui.CommentAnnotationContextItem.prototype.renderBody = function () {
	this.$body.append( this.constructor.static.renderThread( this.model ) );
};
 
/* Registration */
 
ve.ui.contextItemFactory.register( ve.ui.CommentAnnotationContextItem );