Debian Codegraph @

extensions/Cite/modules/ve-cite/ve.ui.MWReferenceGroupInputWidget.js

raw symbols SCIP
1 'use strict';
2
3 /*!
4 * VisualEditor UserInterface MWReferenceGroupInput class.
5 *
6 * @copyright 2011-2018 VisualEditor Team's Cite sub-team and others; see AUTHORS.txt
7 * @license MIT
8 */
9
10 /**
11 * Creates an ve.ui.MWReferenceGroupInput object.
12 *
13 * @class
14 * @extends OO.ui.ComboBoxInputWidget
15 *
16 * @constructor
17 * @param {Object} config
18 * @param {string} config.emptyGroupName Label of the placeholder item
19 */
20 ve.ui.MWReferenceGroupInputWidget = function VeUiMWReferenceGroupInputWidget( config ) {
21 this.emptyGroupName = config.emptyGroupName;
22
23 // Parent constructor
24 ve.ui.MWReferenceGroupInputWidget.super.call(
25 this,
26 ve.extendObject( { placeholder: config.emptyGroupName }, config )
27 );
28
29 this.$element.addClass( 've-ui-mwReferenceGroupInputWidget' );
30 };
31
32 /* Inheritance */
33
34 OO.inheritClass( ve.ui.MWReferenceGroupInputWidget, OO.ui.ComboBoxInputWidget );
35
36 /* Methods */
37
38 /**
39 * Populate the reference group menu
40 *
41 * @param {string[]} groups Group names
42 */
43 ve.ui.MWReferenceGroupInputWidget.prototype.populateMenu = function ( groups ) {
44 const items = [ new OO.ui.MenuOptionWidget( {
45 data: '',
46 label: this.emptyGroupName
47 } ) ];
48 groups.forEach( ( groupName ) => {
49 const match = groupName.match( /^mwReference\/(.+)/ );
50 if ( match ) {
51 items.push( new OO.ui.MenuOptionWidget( { data: match[ 1 ], label: match[ 1 ] } ) );
52 }
53 } );
54 this.menu.clearItems().addItems( items ).toggle( false );
55 };