2023-08-21 08:08:23 +00:00
|
|
|
'use strict';
|
|
|
|
|
2016-02-03 21:03:41 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor UserInterface MWReferenceGroupInput class.
|
|
|
|
*
|
2018-01-03 01:05:45 +00:00
|
|
|
* @copyright 2011-2018 VisualEditor Team's Cite sub-team and others; see AUTHORS.txt
|
2017-12-29 12:12:35 +00:00
|
|
|
* @license MIT
|
2016-02-03 21:03:41 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an ve.ui.MWReferenceGroupInput object.
|
|
|
|
*
|
|
|
|
* @constructor
|
2024-02-28 08:57:24 +00:00
|
|
|
* @extends OO.ui.ComboBoxInputWidget
|
2016-02-03 21:03:41 +00:00
|
|
|
* @param {Object} [config] Configuration options
|
|
|
|
* @cfg {string} emptyGroupName Label of the placeholder item
|
|
|
|
*/
|
|
|
|
ve.ui.MWReferenceGroupInputWidget = function VeUiMWReferenceGroupInputWidget( config ) {
|
|
|
|
config = config || {};
|
|
|
|
|
|
|
|
this.emptyGroupName = config.emptyGroupName;
|
|
|
|
|
|
|
|
// Parent constructor
|
2024-01-30 11:18:52 +00:00
|
|
|
ve.ui.MWReferenceGroupInputWidget.super.call(
|
|
|
|
this,
|
|
|
|
ve.extendObject( { placeholder: config.emptyGroupName }, config )
|
|
|
|
);
|
2016-02-03 21:03:41 +00:00
|
|
|
|
|
|
|
this.$element.addClass( 've-ui-mwReferenceGroupInputWidget' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2016-11-09 19:29:35 +00:00
|
|
|
OO.inheritClass( ve.ui.MWReferenceGroupInputWidget, OO.ui.ComboBoxInputWidget );
|
2016-02-03 21:03:41 +00:00
|
|
|
|
|
|
|
/* 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 ) {
|
2023-08-21 08:08:23 +00:00
|
|
|
const items = [ new OO.ui.MenuOptionWidget( {
|
2016-02-03 21:03:41 +00:00
|
|
|
data: '',
|
2024-03-12 15:03:23 +00:00
|
|
|
label: this.emptyGroupName
|
2023-05-16 15:16:04 +00:00
|
|
|
} ) ];
|
2023-08-21 08:08:23 +00:00
|
|
|
for ( const groupName in internalList.getNodeGroups() ) {
|
|
|
|
const match = groupName.match( /^mwReference\/(.+)/ );
|
2023-05-16 15:16:04 +00:00
|
|
|
if ( match ) {
|
|
|
|
items.push( new OO.ui.MenuOptionWidget( { data: match[ 1 ], label: match[ 1 ] } ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.menu.clearItems().addItems( items ).toggle( false );
|
2016-02-03 21:03:41 +00:00
|
|
|
};
|