Debian Codegraph @

extensions/VisualEditor/modules/ve-mw/ui/contextitems/ve.ui.MWIncludesContextItem.js

raw symbols SCIP
1 /*!
2 * VisualEditor MWIncludesContextItem class.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 /**
8 * Context item for a MWIncludesContextItem.
9 *
10 * @class
11 * @extends ve.ui.LinearContextItem
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.MWIncludesContextItem = function VeUiMWIncludesContextItem() {
19 // Parent constructor
20 ve.ui.MWIncludesContextItem.super.apply( this, arguments );
21
22 // Initialization
23 this.$element.addClass( 've-ui-mwIncludesContextItem' );
24
25 this.setLabel( this.getLabelMessage() );
26
27 this.$actions.remove();
28 };
29
30 /* Inheritance */
31
32 OO.inheritClass( ve.ui.MWIncludesContextItem, ve.ui.LinearContextItem );
33
34 /* Static Properties */
35
36 ve.ui.MWIncludesContextItem.static.editable = false;
37
38 ve.ui.MWIncludesContextItem.static.name = 'mwIncludes';
39
40 ve.ui.MWIncludesContextItem.static.icon = 'markup';
41
42 ve.ui.MWIncludesContextItem.static.modelClasses = [
43 ve.dm.MWIncludesNode
44 ];
45
46 /* Methods */
47
48 /**
49 * @return {string}
50 */
51 ve.ui.MWIncludesContextItem.prototype.getLabelMessage = function () {
52 const key = {
53 'mw:Includes/NoInclude': 'visualeditor-includes-noinclude-start',
54 'mw:Includes/NoInclude/End': 'visualeditor-includes-noinclude-end',
55 'mw:Includes/OnlyInclude': 'visualeditor-includes-onlyinclude-start',
56 'mw:Includes/OnlyInclude/End': 'visualeditor-includes-onlyinclude-end',
57 'mw:Includes/IncludeOnly': 'visualeditor-includes-includeonly'
58 }[ this.model.getAttribute( 'type' ) ];
59 // eslint-disable-next-line mediawiki/msg-doc
60 return key ? mw.message( key ).text() : '';
61 };
62
63 /**
64 * @return {jQuery}
65 */
66 ve.ui.MWIncludesContextItem.prototype.getDescriptionMessage = function () {
67 const key = {
68 'mw:Includes/NoInclude': 'visualeditor-includes-noinclude-description',
69 'mw:Includes/OnlyInclude': 'visualeditor-includes-onlyinclude-description',
70 'mw:Includes/IncludeOnly': 'visualeditor-includes-includeonly-description'
71 }[ this.model.getAttribute( 'type' ) ];
72 // eslint-disable-next-line mediawiki/msg-doc
73 return key ? mw.message( key ).parseDom() : $( [] );
74 };
75
76 /**
77 * @inheritdoc
78 */
79 ve.ui.MWIncludesContextItem.prototype.renderBody = function () {
80 this.$body.empty();
81
82 const $desc = this.getDescriptionMessage();
83 this.$body.append( $desc, $( document.createTextNode( mw.msg( 'word-separator' ) ) ) );
84
85 if ( this.model.getAttribute( 'mw' ) ) {
86 let wikitext = this.model.getAttribute( 'mw' ).src;
87 // The opening and closing tags are included, eww
88 wikitext = wikitext.replace( /^<includeonly>\s*([\s\S]*)\s*<\/includeonly>$/, '$1' );
89 this.$body.append( $( '<pre>' )
90 // The following classes are used here:
91 // * mw-editfont-monospace
92 // * mw-editfont-sans-serif
93 // * mw-editfont-serif
94 .addClass( 'mw-editfont-' + mw.user.options.get( 'editfont' ) )
95 .text( wikitext )
96 );
97 }
98
99 const $docMsg = mw.message( 'visualeditor-includes-documentation' ).parseDom();
100 this.$body.append( $docMsg );
101 };
102
103 /* Registration */
104
105 ve.ui.contextItemFactory.register( ve.ui.MWIncludesContextItem );