Debian Codegraph @

extensions/VisualEditor/editcheck/modules/EditCheckContextItem.js

raw symbols SCIP
1 /*!
2 * VisualEditor EditCheckContextItem class.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 /**
8 * Context item shown after a rich text paste.
9 *
10 * @class
11 * @extends ve.ui.PersistentContextItem
12 *
13 * @constructor
14 * @param {ve.ui.LinearContext} context Context the item is in
15 * @param {ve.dm.Model} model Model the item is related to
16 * @param {Object} [config]
17 */
18 ve.ui.EditCheckContextItem = function VeUiEditCheckContextItem() {
19 // Parent constructor
20 ve.ui.EditCheckContextItem.super.apply( this, arguments );
21
22 // Initialization
23 this.$element.addClass( 've-ui-editCheckContextItem' );
24 };
25
26 /* Inheritance */
27
28 OO.inheritClass( ve.ui.EditCheckContextItem, ve.ui.PersistentContextItem );
29
30 /* Static Properties */
31
32 ve.ui.EditCheckContextItem.static.name = 'editCheckReferences';
33
34 ve.ui.EditCheckContextItem.static.icon = 'quotes';
35
36 ve.ui.EditCheckContextItem.static.label = OO.ui.deferMsg( 'editcheck-dialog-addref-title' );
37
38 /* Methods */
39
40 /**
41 * @inheritdoc
42 */
43 ve.ui.EditCheckContextItem.prototype.renderBody = function () {
44 const $actions = $( '<div>' ).addClass( 've-ui-editCheckContextItem-actions' );
45
46 this.data.action.getChoices().forEach( ( choice ) => {
47 const button = new OO.ui.ButtonWidget( choice );
48 button.connect( this, {
49 click: () => {
50 this.onChoiceClick( choice.action );
51 }
52 } );
53 $actions.append( button.$element );
54 } );
55
56 // HACK: Suppress close button on mobile context
57 if ( this.context.isMobile() ) {
58 this.context.closeButton.toggle( false );
59 }
60
61 this.$body.append(
62 $( '<p>' ).text( this.data.action.getDescription() ),
63 $actions
64 );
65 };
66
67 ve.ui.EditCheckContextItem.prototype.close = function ( data ) {
68 // HACK: Un-suppress close button on mobile context
69 if ( this.context.isMobile() ) {
70 this.context.closeButton.toggle( true );
71 }
72 this.data.callback( data, this.data );
73 };
74
75 ve.ui.EditCheckContextItem.prototype.onChoiceClick = function ( choice ) {
76 this.data.action.check.act( choice, this.data.action, this );
77 };
78
79 /* Registration */
80
81 ve.ui.contextItemFactory.register( ve.ui.EditCheckContextItem );