2022-01-12 14:05:07 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
2022-02-03 12:30:29 +00:00
|
|
|
* @private
|
2022-01-12 14:05:07 +00:00
|
|
|
* @fires toggleUnusedFields
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionOutlineToggleUnusedWidget.prototype.onClick = function () {
|
2022-03-11 11:02:32 +00:00
|
|
|
this.toggleUnusedParameters( !this.showUnusedFields, true );
|
2022-02-04 11:06:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/** @inheritdoc */
|
|
|
|
ve.ui.MWTransclusionOutlineToggleUnusedWidget.prototype.setDisabled = function ( disabled ) {
|
|
|
|
ve.ui.MWTransclusionOutlineToggleUnusedWidget.super.prototype.setDisabled.call( this, disabled );
|
2022-03-11 11:02:32 +00:00
|
|
|
this.updateState( this.showUnusedFields );
|
2022-02-03 12:30:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2022-02-04 11:06:54 +00:00
|
|
|
* @param {boolean} showUnused
|
2022-03-04 11:01:58 +00:00
|
|
|
* @param {boolean} [fromClick]
|
2022-02-03 12:30:29 +00:00
|
|
|
* @fires toggleUnusedFields
|
|
|
|
*/
|
2022-03-11 11:02:32 +00:00
|
|
|
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 ) {
|
2022-02-04 11:06:54 +00:00
|
|
|
showUnused = showUnused || this.isDisabled();
|
2022-02-03 12:30:29 +00:00
|
|
|
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'
|
|
|
|
) );
|
2022-03-11 11:02:32 +00:00
|
|
|
return true;
|
2022-02-03 12:30:29 +00:00
|
|
|
}
|
2022-03-11 11:02:32 +00:00
|
|
|
return false;
|
2022-01-12 14:05:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles toggling the visibility of the button.
|
|
|
|
*
|
2022-02-03 12:30:29 +00:00
|
|
|
* @private
|
2022-01-12 14:05:07 +00:00
|
|
|
* @param {boolean} visible
|
|
|
|
* @fires toggleUnusedFields
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionOutlineToggleUnusedWidget.prototype.onToggle = function ( visible ) {
|
|
|
|
if ( visible ) {
|
|
|
|
this.emit( 'toggleUnusedFields', this.showUnusedFields );
|
|
|
|
}
|
|
|
|
};
|