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.
|
|
|
|
*
|
|
|
|
* @class
|
2016-11-09 19:29:35 +00:00
|
|
|
* @extends OO.ui.ComboBoxInputWidget
|
2016-02-03 21:03:41 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @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
|
2016-11-10 23:22:40 +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 ) {
|
|
|
|
var placeholderGroupItem = new OO.ui.MenuOptionWidget( {
|
|
|
|
data: '',
|
|
|
|
label: this.emptyGroupName,
|
|
|
|
flags: 'emptyGroupPlaceholder'
|
|
|
|
} );
|
|
|
|
this.menu.clearItems();
|
2018-11-27 22:23:57 +00:00
|
|
|
this.menu.addItems( [ placeholderGroupItem ].concat(
|
|
|
|
Object.keys( internalList.getNodeGroups() ).map(
|
|
|
|
function ( groupInternalName ) {
|
|
|
|
var groupName;
|
|
|
|
if ( groupInternalName.indexOf( 'mwReference/' ) === 0 ) {
|
|
|
|
groupName = groupInternalName.slice( 'mwReference/'.length );
|
|
|
|
if ( groupName ) {
|
|
|
|
return new OO.ui.MenuOptionWidget( { data: groupName, label: groupName } );
|
|
|
|
}
|
2016-02-03 21:03:41 +00:00
|
|
|
}
|
2020-06-09 10:27:52 +00:00
|
|
|
return null;
|
2016-02-03 21:03:41 +00:00
|
|
|
}
|
2018-11-27 22:23:57 +00:00
|
|
|
).filter( function ( item ) {
|
|
|
|
return item;
|
|
|
|
} )
|
|
|
|
), 0 );
|
2016-02-03 21:03:41 +00:00
|
|
|
this.menu.toggle( false );
|
|
|
|
};
|