2021-05-17 15:43:49 +00:00
|
|
|
/**
|
2021-08-16 16:17:14 +00:00
|
|
|
* 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.
|
2021-05-17 15:43:49 +00:00
|
|
|
*
|
|
|
|
* @class
|
2021-08-16 14:06:39 +00:00
|
|
|
* @extends OO.ui.OptionWidget
|
2021-05-17 15:43:49 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
2021-07-13 19:01:30 +00:00
|
|
|
* @param {Object} config
|
2024-05-27 04:59:02 +00:00
|
|
|
* @param {string} config.data Parameter name
|
|
|
|
* @param {string} config.label
|
|
|
|
* @param {boolean} [config.required=false] Required parameters can't be unchecked
|
|
|
|
* @param {boolean} [config.selected=false] If the parameter is currently used (checked)
|
|
|
|
* @param {boolean} [config.hasValue=false] If the parameter has a value that's not empty
|
2021-05-17 15:43:49 +00:00
|
|
|
*/
|
2021-08-16 12:56:27 +00:00
|
|
|
ve.ui.MWTransclusionOutlineParameterWidget = function VeUiMWTransclusionOutlineParameterWidget( config ) {
|
2021-08-10 14:42:21 +00:00
|
|
|
this.checkbox = new OO.ui.CheckboxInputWidget( {
|
2021-08-16 16:17:14 +00:00
|
|
|
title: config.required ?
|
|
|
|
ve.msg( 'visualeditor-dialog-transclusion-required-parameter' ) :
|
|
|
|
null,
|
2021-05-17 15:43:49 +00:00
|
|
|
disabled: config.required,
|
2021-08-16 16:17:14 +00:00
|
|
|
selected: config.selected || config.required,
|
|
|
|
// Keyboard navigation is handled by the outer OO.ui.SelectWidget
|
|
|
|
tabIndex: -1
|
2021-05-17 15:43:49 +00:00
|
|
|
} )
|
2021-08-16 16:17:14 +00:00
|
|
|
.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 )
|
|
|
|
} );
|
2021-05-17 15:43:49 +00:00
|
|
|
|
|
|
|
// Parent constructor
|
2021-08-16 12:56:27 +00:00
|
|
|
ve.ui.MWTransclusionOutlineParameterWidget.super.call( this, ve.extendObject( config, {
|
2021-09-10 19:18:59 +00:00
|
|
|
classes: [ 've-ui-mwTransclusionOutlineParameterWidget' ],
|
2021-08-16 14:06:39 +00:00
|
|
|
$label: $( '<label>' )
|
|
|
|
} ) );
|
2021-05-17 15:43:49 +00:00
|
|
|
|
2022-06-15 14:47:54 +00:00
|
|
|
this.toggleHasValue( config.hasValue );
|
|
|
|
|
2021-05-17 15:43:49 +00:00
|
|
|
// Initialization
|
2021-08-09 16:35:53 +00:00
|
|
|
this.$element
|
2021-08-16 16:17:14 +00:00
|
|
|
.append( this.checkbox.$element, this.$label );
|
2021-05-17 15:43:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2021-08-16 12:56:27 +00:00
|
|
|
OO.inheritClass( ve.ui.MWTransclusionOutlineParameterWidget, OO.ui.OptionWidget );
|
2021-06-29 19:45:09 +00:00
|
|
|
|
2021-05-17 15:43:49 +00:00
|
|
|
/* Methods */
|
2021-06-29 19:45:09 +00:00
|
|
|
|
2021-08-09 16:35:53 +00:00
|
|
|
/**
|
2021-08-16 14:06:39 +00:00
|
|
|
* @private
|
2021-10-13 13:02:57 +00:00
|
|
|
* @param {jQuery.Event} e
|
2021-08-09 16:35:53 +00:00
|
|
|
*/
|
2021-08-16 16:17:14 +00:00
|
|
|
ve.ui.MWTransclusionOutlineParameterWidget.prototype.onMouseDown = function ( e ) {
|
|
|
|
// Mouse clicks conflict with the click handler in {@see OO.ui.SelectWidget}
|
|
|
|
e.stopPropagation();
|
2021-08-09 16:35:53 +00:00
|
|
|
};
|
|
|
|
|
2021-08-16 14:06:39 +00:00
|
|
|
/**
|
2021-08-16 16:17:14 +00:00
|
|
|
* @inheritDoc OO.ui.OptionWidget
|
2021-08-16 14:06:39 +00:00
|
|
|
*/
|
2021-08-16 16:17:14 +00:00
|
|
|
ve.ui.MWTransclusionOutlineParameterWidget.prototype.setSelected = function ( state ) {
|
|
|
|
// Never uncheck a required parameter
|
|
|
|
state = state || this.checkbox.isDisabled();
|
2021-08-09 16:35:53 +00:00
|
|
|
|
2021-08-16 16:17:14 +00:00
|
|
|
this.checkbox.setSelected( state, true );
|
2022-07-18 14:52:20 +00:00
|
|
|
return ve.ui.MWTransclusionOutlineParameterWidget.super.prototype.setSelected.call( this, state );
|
2021-05-17 15:43:49 +00:00
|
|
|
};
|
2022-06-15 14:47:54 +00:00
|
|
|
|
2022-07-12 18:10:02 +00:00
|
|
|
/**
|
|
|
|
* @param {boolean} state
|
|
|
|
*/
|
2022-07-18 14:36:37 +00:00
|
|
|
ve.ui.MWTransclusionOutlineParameterWidget.prototype.toggleActivePageIndicator = function ( state ) {
|
|
|
|
this.$element.toggleClass( 've-ui-mwTransclusionOutlineParameterWidget-activePage', state );
|
2022-07-09 06:54:35 +00:00
|
|
|
};
|
|
|
|
|
2022-06-15 14:47:54 +00:00
|
|
|
/**
|
|
|
|
* @param {boolean} hasValue
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionOutlineParameterWidget.prototype.toggleHasValue = function ( hasValue ) {
|
|
|
|
this.$element.toggleClass( 've-ui-mwTransclusionOutlineParameterWidget-hasValue', hasValue );
|
|
|
|
};
|
2022-07-11 08:58:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Custom method to scroll parameter into view respecting the sticky part that sits above
|
2022-08-01 13:12:56 +00:00
|
|
|
*
|
2022-08-02 09:08:23 +00:00
|
|
|
* @param {number} paddingTop
|
2022-07-11 08:58:36 +00:00
|
|
|
*/
|
2022-08-02 09:08:23 +00:00
|
|
|
ve.ui.MWTransclusionOutlineParameterWidget.prototype.ensureVisibility = function ( paddingTop ) {
|
2022-07-11 08:58:36 +00:00
|
|
|
// make sure parameter is visible and scrolled underneath the sticky
|
2022-08-02 09:08:23 +00:00
|
|
|
this.scrollElementIntoView( { animate: false, padding: { top: paddingTop } } );
|
2022-07-11 08:58:36 +00:00
|
|
|
};
|