mediawiki-extensions-Visual.../modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlineToggleUnusedWidget.js
WMDE-Fisch 20435b319c Add button to sidebar to hide/show unused fields
Bug: T298259
Change-Id: I8e5091b97dfb19eba981b2a919b82b6f14823990
2022-01-14 11:09:04 +00:00

61 lines
1.6 KiB
JavaScript

/**
* Button widget to toggle unused fields
*
* @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 toggleUnusedFields
* Emitted when the visibility for unused fields should be (re)applied.
*/
/**
* Handles clicks on the button by mouse or keyboard interaction.
*
* @fires toggleUnusedFields
*/
ve.ui.MWTransclusionOutlineToggleUnusedWidget.prototype.onClick = function () {
this.showUnusedFields = !this.showUnusedFields;
this.setLabel( ve.msg( this.showUnusedFields ? 'visualeditor-dialog-transclusion-filter-hide-unused' :
'visualeditor-dialog-transclusion-filter-show-all' ) );
this.emit( 'toggleUnusedFields', this.showUnusedFields );
};
/**
* Handles toggling the visibility of the button.
*
* @param {boolean} visible
* @fires toggleUnusedFields
*/
ve.ui.MWTransclusionOutlineToggleUnusedWidget.prototype.onToggle = function ( visible ) {
if ( visible ) {
this.emit( 'toggleUnusedFields', this.showUnusedFields );
}
};