mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-12-13 14:58:43 +00:00
7aeff4bfd3
Most notably: * Move some code snippets from the outer …TemplateWidget to the inner …SelectWidget, without introducing new dependencies. * Move all knowledge about the item class …OutlineParameterWidget class into …SelectWidget. * Some more self-documenting method names for event handlers. * Avoid the somewhat ambiguous variable name "checkbox" in favor of "item". That's how it's named in the upstream OOUI …SelectWidget. This is extracted from the following patch Ibd94c39. The difference is that the following patch adds a new dependency: The …SelectWidget gets to know the template model. This patch here contains all changes that are possible without this new dependency. Bug: T288827 Change-Id: I187f313c84424b28005d9276cb1356029f9ebb75
77 lines
2.2 KiB
JavaScript
77 lines
2.2 KiB
JavaScript
/*!
|
|
* VisualEditor user interface MWTransclusionOutlineParameterWidget class.
|
|
*
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* A widget that represents a template parameter, with a checkbox to add/remove the parameter.
|
|
* Modelled after {@see OO.ui.OutlineOptionWidget}. Also see {@see OO.ui.CheckboxMultioptionWidget}
|
|
* for inspiration.
|
|
*
|
|
* @class
|
|
* @extends OO.ui.OptionWidget
|
|
*
|
|
* @constructor
|
|
* @param {Object} config
|
|
* @cfg {string} data Parameter name
|
|
* @cfg {string} label
|
|
* @cfg {boolean} [required] Required parameters can't be unchecked
|
|
* @cfg {boolean} [selected] If the parameter is currently used (checked)
|
|
*/
|
|
ve.ui.MWTransclusionOutlineParameterWidget = function VeUiMWTransclusionOutlineParameterWidget( config ) {
|
|
this.checkbox = new OO.ui.CheckboxInputWidget( {
|
|
title: config.required ?
|
|
ve.msg( 'visualeditor-dialog-transclusion-required-parameter' ) :
|
|
null,
|
|
disabled: config.required,
|
|
selected: config.selected || config.required,
|
|
// Keyboard navigation is handled by the outer OO.ui.SelectWidget
|
|
tabIndex: -1
|
|
} )
|
|
.connect( this, {
|
|
// The array syntax is a way to call `this.emit( 'change' )`.
|
|
change: [ 'emit', 'change' ]
|
|
} );
|
|
this.checkbox.$input.on( {
|
|
mousedown: this.onMouseDown.bind( this )
|
|
} );
|
|
|
|
// Parent constructor
|
|
ve.ui.MWTransclusionOutlineParameterWidget.super.call( this, ve.extendObject( config, {
|
|
$label: $( '<label>' )
|
|
} ) );
|
|
|
|
// Initialization
|
|
this.$element
|
|
.addClass( 've-ui-mwTransclusionOutlineItem' )
|
|
.append( this.checkbox.$element, this.$label );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
OO.inheritClass( ve.ui.MWTransclusionOutlineParameterWidget, OO.ui.OptionWidget );
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* @private
|
|
*/
|
|
ve.ui.MWTransclusionOutlineParameterWidget.prototype.onMouseDown = function ( e ) {
|
|
// Mouse clicks conflict with the click handler in {@see OO.ui.SelectWidget}
|
|
e.stopPropagation();
|
|
};
|
|
|
|
/**
|
|
* @inheritDoc OO.ui.OptionWidget
|
|
*/
|
|
ve.ui.MWTransclusionOutlineParameterWidget.prototype.setSelected = function ( state ) {
|
|
// Never uncheck a required parameter
|
|
state = state || this.checkbox.isDisabled();
|
|
|
|
this.checkbox.setSelected( state, true );
|
|
ve.ui.MWTransclusionOutlineParameterWidget.super.prototype.setSelected.call( this, state );
|
|
|
|
return this;
|
|
};
|