mediawiki-extensions-Visual.../modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlineToggleUnusedWidget.js
James D. Forrester b518e55ef9 docs: Replace JSDuck with JSDoc (and pull-through VE with said change)
This is not great, but it's a start (and unblocks other pull-throughs).

New changes:
c401efc98 build: Replace jsduck with jsdoc for documentation
16ba162a0 JSDoc: @mixins -> @mixes
9e0a1f53b JSDoc: Fix complex return types
449b6cc0f Prefer arrow function callbacks
1539af2c8 Remove 'this' bindings in arrow functions
b760f3b14 Use arrow functions in OO.ui.Process steps
57c24109e Use arrow functions in jQuery callbacks
9622ccef9 Convert some remaining functions callbacks to arrow functions
f6c885021 Remove useless local variable
1cd800020 Clear branch node cache when rebuilding tree

Bug: T250843
Bug: T363329
Change-Id: I0f4878ca84b95e3f388b358b943f105637e455f9
2024-04-29 16:16:50 +01:00

98 lines
2.8 KiB
JavaScript

/**
* Button widget to toggle unused fields in the template dialog sidebar, appears
* at the top of any template with more than the threshold number of parameters.
*
* @class
* @extends OO.ui.ButtonWidget
*
* @constructor
*/
ve.ui.MWTransclusionOutlineToggleUnusedWidget = function VeUiMWTransclusionOutlineToggleUnusedWidget() {
// Parent constructor
ve.ui.MWTransclusionOutlineToggleUnusedWidget.super.call( this, {
label: ve.msg( 'visualeditor-dialog-transclusion-filter-hide-unused' ),
flags: [ 'progressive' ],
framed: false
} );
// Events
this.connect( this, {
toggle: 'onToggle',
click: 'onClick'
} );
// Initialization
this.$element.addClass( 've-ui-mwTransclusionOutlineToggleUnusedWidget' );
this.showUnusedFields = true;
};
/* Inheritance */
OO.inheritClass( ve.ui.MWTransclusionOutlineToggleUnusedWidget, OO.ui.ButtonWidget );
/* Events */
/**
* @event ve.ui.MWTransclusionOutlineToggleUnusedWidget#toggleUnusedFields
* @param {boolean} visibility If unused fields should be shown or not.
* @param {boolean} [fromClick]
* Emitted when the visibility for unused fields should be (re)applied.
*/
/**
* Handles clicks on the button by mouse or keyboard interaction.
*
* @private
* @fires toggleUnusedFields
*/
ve.ui.MWTransclusionOutlineToggleUnusedWidget.prototype.onClick = function () {
this.toggleUnusedParameters( !this.showUnusedFields, true );
};
/** @inheritdoc */
ve.ui.MWTransclusionOutlineToggleUnusedWidget.prototype.setDisabled = function ( disabled ) {
ve.ui.MWTransclusionOutlineToggleUnusedWidget.super.prototype.setDisabled.call( this, disabled );
this.updateState( this.showUnusedFields );
};
/**
* @param {boolean} showUnused
* @param {boolean} [fromClick]
* @fires toggleUnusedFields
*/
ve.ui.MWTransclusionOutlineToggleUnusedWidget.prototype.toggleUnusedParameters = function ( showUnused, fromClick ) {
if ( this.updateState( showUnused ) ) {
this.emit( 'toggleUnusedFields', this.showUnusedFields, fromClick );
}
};
/**
* @private
* @param {boolean} showUnused
* @return {boolean} Returns true when state changed.
*/
ve.ui.MWTransclusionOutlineToggleUnusedWidget.prototype.updateState = function ( showUnused ) {
showUnused = showUnused || this.isDisabled();
if ( showUnused !== this.showUnusedFields ) {
this.showUnusedFields = showUnused;
this.setLabel( ve.msg( this.showUnusedFields ?
'visualeditor-dialog-transclusion-filter-hide-unused' :
'visualeditor-dialog-transclusion-filter-show-all'
) );
return true;
}
return false;
};
/**
* Handles toggling the visibility of the button.
*
* @private
* @param {boolean} visible
* @fires toggleUnusedFields
*/
ve.ui.MWTransclusionOutlineToggleUnusedWidget.prototype.onToggle = function ( visible ) {
if ( visible ) {
this.emit( 'toggleUnusedFields', this.showUnusedFields );
}
};