Debian Codegraph @

extensions/VisualEditor/lib/ve/src/ui/pages/ve.ui.SymbolListPage.js

raw symbols SCIP
1 /*!
2 * VisualEditor user interface SymbolListPage class.
3 *
4 * @copyright See AUTHORS.txt
5 * @license The MIT License (MIT); see LICENSE.txt
6 */
7
8 /**
9 * Special symbol toolbar dialog.
10 *
11 * @class
12 * @extends OO.ui.PageLayout
13 *
14 * @constructor
15 * @param {string} name Unique symbolic name of page
16 * @param {Object} [config] Configuration options
17 * @param {string} [config.label] Group label
18 * @param {Object} [config.symbols] Symbol set
19 * @param {Object} [config.attributes] Extra attributes for the group, e.g. `lang` & `dir`
20 */
21 ve.ui.SymbolListPage = function VeUiSymbolListPage( name, config ) {
22 // Parent constructor
23 ve.ui.SymbolListPage.super.apply( this, arguments );
24
25 this.label = config.label;
26
27 const $symbols = $( '<div>' ).addClass( 've-ui-symbolListPage-symbols' );
28 const symbolsNode = $symbols[ 0 ];
29
30 // It is assumed this loop may contain hundreds or thousands of symbols,
31 // so avoid jQuery and use plain DOM.
32 config.symbols.forEach( ( symbol ) => {
33 const symbolNode = document.createElement( 'div' );
34 symbolNode.classList.add( 've-ui-symbolListPage-symbol' );
35 if ( symbol.classes ) {
36 DOMTokenList.prototype.add.apply( symbolNode.classList, symbol.classes );
37 }
38 if ( symbol.titleMsg ) {
39 // eslint-disable-next-line mediawiki/msg-doc
40 symbolNode.setAttribute( 'title', ve.msg( symbol.titleMsg ) );
41 }
42 symbolNode.textContent = Object.prototype.hasOwnProperty.call( symbol, 'label' ) ? symbol.label : symbol;
43
44 $.data( symbolNode, 'symbol', symbol );
45
46 symbolsNode.appendChild( symbolNode );
47 } );
48
49 if ( config.attributes ) {
50 $symbols.attr( config.attributes );
51 }
52
53 this.$element
54 .addClass( 've-ui-symbolListPage' )
55 .append( $( '<h3>' ).text( this.label ), $symbols );
56 };
57
58 /* Inheritance */
59
60 OO.inheritClass( ve.ui.SymbolListPage, OO.ui.PageLayout );
61
62 /* Methods */
63
64 /**
65 * @inheritdoc
66 */
67 ve.ui.SymbolListPage.prototype.setupOutlineItem = function () {
68 // Parent method
69 ve.ui.SymbolListPage.super.prototype.setupOutlineItem.apply( this, arguments );
70
71 this.outlineItem.setLabel( this.label );
72 };