mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-24 06:54:00 +00:00
341847a410
I assume the code was using lastIndexOf as some kind of performance optimization. Certain StackOverflow threads suggest it without going into detail. It's not correct here. You can actually name a group "mwReference/", which will result in the (valid) internal name "mwReference/mwReference/". This works as expected with indexOf but not with lastIndexOf. Change-Id: I8e85ae5c11a74016c7720fcdb6ac6478431aaa8e
54 lines
1.5 KiB
JavaScript
54 lines
1.5 KiB
JavaScript
/*!
|
|
* 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.
|
|
*
|
|
* @class
|
|
* @extends OO.ui.ComboBoxInputWidget
|
|
*
|
|
* @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
|
|
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 ) {
|
|
var items = [ new OO.ui.MenuOptionWidget( {
|
|
data: '',
|
|
label: this.emptyGroupName,
|
|
flags: 'emptyGroupPlaceholder'
|
|
} ) ];
|
|
for ( var groupName in internalList.getNodeGroups() ) {
|
|
var 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 );
|
|
};
|