mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-18 03:41:45 +00:00
4367235dcc
This makes the code more readable and easier to reason about. The ESLint rule responsible for this code style was removed just recently. Notes: * I focus on classes that are relevant for what the WMDE team does right now. * I merge multiple `var` keywords only when the variables are strongly connected. * Caching the length in a for loop makes the code hard to read, but not really faster when it's a trivial property access anyway. Bug: T284895 Change-Id: I621fed61d894a83dc95f58129bbe679d82b0f5f5
70 lines
1.8 KiB
JavaScript
70 lines
1.8 KiB
JavaScript
/*!
|
|
* VisualEditor UserInterface MWParameterResultWidget class.
|
|
*
|
|
* @copyright 2011-2020 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* Creates an ve.ui.MWParameterResultWidget object.
|
|
*
|
|
* @class
|
|
* @extends OO.ui.DecoratedOptionWidget
|
|
*
|
|
* @constructor
|
|
* @param {Object} [config] Configuration options
|
|
*/
|
|
ve.ui.MWParameterResultWidget = function VeUiMWParameterResultWidget( config ) {
|
|
// Configuration initialization
|
|
config = ve.extendObject( { icon: 'parameter' }, config );
|
|
|
|
// Parent constructor
|
|
ve.ui.MWParameterResultWidget.super.call( this, config );
|
|
|
|
// Initialization
|
|
this.$element.addClass( 've-ui-mwParameterResultWidget' );
|
|
this.setLabel( this.buildLabel() );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
OO.inheritClass( ve.ui.MWParameterResultWidget, OO.ui.DecoratedOptionWidget );
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Build the label element
|
|
*
|
|
* @return {jQuery}
|
|
*/
|
|
ve.ui.MWParameterResultWidget.prototype.buildLabel = function () {
|
|
var $label = $( '<div>' )
|
|
.addClass( 've-ui-mwParameterResultWidget-label' )
|
|
.text( this.data.label ),
|
|
$names = $( '<div>' )
|
|
.addClass( 've-ui-mwParameterResultWidget-names' ),
|
|
$description = $( '<div>' )
|
|
.addClass( 've-ui-mwParameterResultWidget-description' )
|
|
.text( this.data.description || '' );
|
|
|
|
if ( this.data.name && this.data.name !== this.data.label ) {
|
|
$names.append(
|
|
$( '<span>' )
|
|
.addClass( 've-ui-mwParameterResultWidget-name' )
|
|
.text( this.data.name )
|
|
);
|
|
}
|
|
for ( var i = 0; i < this.data.aliases.length; i++ ) {
|
|
if ( this.data.aliases[ i ] === this.data.label ) {
|
|
continue;
|
|
}
|
|
$names.append(
|
|
$( '<span>' )
|
|
.addClass( 've-ui-mwParameterResultWidget-name ve-ui-mwParameterResultWidget-alias' )
|
|
.text( this.data.aliases[ i ] )
|
|
);
|
|
}
|
|
|
|
return $label.add( $names ).add( $description );
|
|
};
|