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.
|
|
|
|
*
|
2024-05-28 08:38:26 +00:00
|
|
|
* @class
|
2024-02-28 08:57:24 +00:00
|
|
|
* @extends OO.ui.ComboBoxInputWidget
|
2024-05-28 08:38:26 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} config
|
|
|
|
* @param {string} config.emptyGroupName Label of the placeholder item
|
2016-02-03 21:03:41 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWReferenceGroupInputWidget = function VeUiMWReferenceGroupInputWidget( 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
|
|
|
|
*
|
2024-08-26 09:02:07 +00:00
|
|
|
* @param {string[]} groups Group names
|
2016-02-03 21:03:41 +00:00
|
|
|
*/
|
2024-08-26 09:02:07 +00:00
|
|
|
ve.ui.MWReferenceGroupInputWidget.prototype.populateMenu = function ( groups ) {
|
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
|
|
|
} ) ];
|
2024-08-26 09:02:07 +00:00
|
|
|
groups.forEach( ( groupName ) => {
|
2023-08-21 08:08:23 +00:00
|
|
|
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 ] } ) );
|
|
|
|
}
|
2024-08-26 09:02:07 +00:00
|
|
|
} );
|
2023-05-16 15:16:04 +00:00
|
|
|
this.menu.clearItems().addItems( items ).toggle( false );
|
2016-02-03 21:03:41 +00:00
|
|
|
};
|