mediawiki-extensions-Cite/modules/ve-cite/ve.ui.MWReferenceGroupInputWidget.js
thiemowmde d6a58cfa8d Add initial QUnit tests relevant for reference re-use in VE
Note these are more meant as regression test to better cover what's
done in other patches. Everybody should feel free to delete a test
when it gets in the way. I marked a few especially fragile places
with respective comments.

Bug: T358652
Change-Id: I7844907fe3ef4f3439717381b4ecdac9e2d0a825
2024-03-21 09:37:26 +01:00

54 lines
1.5 KiB
JavaScript

'use strict';
/*!
* VisualEditor UserInterface MWReferenceGroupInput class.
*
* @copyright 2011-2018 VisualEditor Team's Cite sub-team and others; see AUTHORS.txt
* @license MIT
*/
/**
* Creates an ve.ui.MWReferenceGroupInput object.
*
* @constructor
* @extends OO.ui.ComboBoxInputWidget
* @param {Object} config Configuration options
* @cfg {string} emptyGroupName Label of the placeholder item
*/
ve.ui.MWReferenceGroupInputWidget = function VeUiMWReferenceGroupInputWidget( config ) {
this.emptyGroupName = config.emptyGroupName;
// Parent constructor
ve.ui.MWReferenceGroupInputWidget.super.call(
this,
ve.extendObject( { placeholder: config.emptyGroupName }, config )
);
this.$element.addClass( 've-ui-mwReferenceGroupInputWidget' );
};
/* Inheritance */
OO.inheritClass( ve.ui.MWReferenceGroupInputWidget, OO.ui.ComboBoxInputWidget );
/* Methods */
/**
* Populate the reference group menu
*
* @param {ve.dm.InternalList} internalList Internal list with which to populate the menu
*/
ve.ui.MWReferenceGroupInputWidget.prototype.populateMenu = function ( internalList ) {
const items = [ new OO.ui.MenuOptionWidget( {
data: '',
label: this.emptyGroupName
} ) ];
for ( const groupName in internalList.getNodeGroups() ) {
const match = groupName.match( /^mwReference\/(.+)/ );
if ( match ) {
items.push( new OO.ui.MenuOptionWidget( { data: match[ 1 ], label: match[ 1 ] } ) );
}
}
this.menu.clearItems().addItems( items ).toggle( false );
};