Debian Codegraph @

extensions/VisualEditor/lib/ve/src/ui/contextitems/ve.ui.CommentAnnotationContextItem.js

raw symbols SCIP
1 /*!
2 * VisualEditor CommentAnnotationContextItem class.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 /**
8 * Context item for a comment.
9 *
10 * @class
11 * @extends ve.ui.AnnotationContextItem
12 *
13 * @param {ve.ui.LinearContext} context Context the item is in
14 * @param {ve.dm.Model} model Model the item is related to
15 * @param {Object} [config] Configuration options
16 */
17 ve.ui.CommentAnnotationContextItem = function VeUiCommentAnnotationContextItem( context, model, config ) {
18 // Parent constructor
19 ve.ui.CommentAnnotationContextItem.super.call( this, context, model, config );
20
21 // Initialization
22 this.$element.addClass( 've-ui-commentAnnotationContextItem' );
23
24 this.editButton.setLabel( ve.msg( 'visualeditor-commentannotationcontextitem-comment' ) );
25 };
26
27 /* Inheritance */
28
29 OO.inheritClass( ve.ui.CommentAnnotationContextItem, ve.ui.AnnotationContextItem );
30
31 /* Static Properties */
32
33 ve.ui.CommentAnnotationContextItem.static.name = 'commentAnnotation';
34
35 ve.ui.CommentAnnotationContextItem.static.icon = 'speechBubble';
36
37 ve.ui.CommentAnnotationContextItem.static.label = OO.ui.deferMsg( 'visualeditor-commentinspector-title' );
38
39 ve.ui.CommentAnnotationContextItem.static.modelClasses = [ ve.dm.CommentAnnotation ];
40
41 ve.ui.CommentAnnotationContextItem.static.embeddable = false;
42
43 ve.ui.CommentAnnotationContextItem.static.commandName = 'commentAnnotation';
44
45 ve.ui.CommentAnnotationContextItem.static.clearable = true;
46
47 ve.ui.CommentAnnotationContextItem.static.clearIcon = 'trash';
48
49 /* Static methods */
50
51 /**
52 * @param {ve.dm.CommentAnnotation} model
53 * @return {jQuery}
54 */
55 ve.ui.CommentAnnotationContextItem.static.renderThread = function ( model ) {
56 let $thread = $( [] );
57
58 model.getAttribute( 'comments' ).forEach( ( comment ) => {
59 const $lineDivs = comment.text.split( '\n' ).map( ( line ) => $( '<div>' ).text( line ) );
60 $thread = $thread.add(
61 $( '<div>' ).addClass( 've-ui-commentAnnotationContextItem-comment' ).append(
62 $( '<strong>' ).text( comment.author ),
63 $lineDivs
64 )
65 );
66 } );
67
68 return $thread;
69 };
70
71 /* Methods */
72
73 /**
74 * @inheritdoc
75 */
76 ve.ui.CommentAnnotationContextItem.prototype.renderBody = function () {
77 const $thread = this.constructor.static.renderThread( this.model );
78 this.$body.append( $thread );
79 };
80
81 /* Registration */
82
83 ve.ui.contextItemFactory.register( ve.ui.CommentAnnotationContextItem );