Debian Codegraph @

extensions/VisualEditor/modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlineToggleUnusedWidget.js

raw symbols SCIP
1 /**
2 * Button widget to toggle unused fields in the template dialog sidebar, appears
3 * at the top of any template with more than the threshold number of parameters.
4 *
5 * @class
6 * @extends OO.ui.ButtonWidget
7 *
8 * @constructor
9 */
10 ve.ui.MWTransclusionOutlineToggleUnusedWidget = function VeUiMWTransclusionOutlineToggleUnusedWidget() {
11 // Parent constructor
12 ve.ui.MWTransclusionOutlineToggleUnusedWidget.super.call( this, {
13 label: ve.msg( 'visualeditor-dialog-transclusion-filter-hide-unused' ),
14 flags: [ 'progressive' ],
15 framed: false
16 } );
17
18 // Events
19 this.connect( this, {
20 toggle: 'onToggle',
21 click: 'onClick'
22 } );
23
24 // Initialization
25 this.$element.addClass( 've-ui-mwTransclusionOutlineToggleUnusedWidget' );
26 this.showUnusedFields = true;
27 };
28
29 /* Inheritance */
30 OO.inheritClass( ve.ui.MWTransclusionOutlineToggleUnusedWidget, OO.ui.ButtonWidget );
31
32 /* Events */
33
34 /**
35 * @event ve.ui.MWTransclusionOutlineToggleUnusedWidget#toggleUnusedFields
36 * @param {boolean} visibility If unused fields should be shown or not.
37 * @param {boolean} [fromClick]
38 * Emitted when the visibility for unused fields should be (re)applied.
39 */
40
41 /**
42 * Handles clicks on the button by mouse or keyboard interaction.
43 *
44 * @private
45 * @fires ve.ui.MWTransclusionOutlineToggleUnusedWidget#toggleUnusedFields
46 */
47 ve.ui.MWTransclusionOutlineToggleUnusedWidget.prototype.onClick = function () {
48 this.toggleUnusedParameters( !this.showUnusedFields, true );
49 };
50
51 /** @inheritdoc */
52 ve.ui.MWTransclusionOutlineToggleUnusedWidget.prototype.setDisabled = function ( disabled ) {
53 ve.ui.MWTransclusionOutlineToggleUnusedWidget.super.prototype.setDisabled.call( this, disabled );
54 this.updateState( this.showUnusedFields );
55 };
56
57 /**
58 * @param {boolean} showUnused
59 * @param {boolean} [fromClick]
60 * @fires ve.ui.MWTransclusionOutlineToggleUnusedWidget#toggleUnusedFields
61 */
62 ve.ui.MWTransclusionOutlineToggleUnusedWidget.prototype.toggleUnusedParameters = function ( showUnused, fromClick ) {
63 if ( this.updateState( showUnused ) ) {
64 this.emit( 'toggleUnusedFields', this.showUnusedFields, fromClick );
65 }
66 };
67
68 /**
69 * @private
70 * @param {boolean} showUnused
71 * @return {boolean} Returns true when state changed.
72 */
73 ve.ui.MWTransclusionOutlineToggleUnusedWidget.prototype.updateState = function ( showUnused ) {
74 showUnused = showUnused || this.isDisabled();
75 if ( showUnused !== this.showUnusedFields ) {
76 this.showUnusedFields = showUnused;
77 this.setLabel( ve.msg( this.showUnusedFields ?
78 'visualeditor-dialog-transclusion-filter-hide-unused' :
79 'visualeditor-dialog-transclusion-filter-show-all'
80 ) );
81 return true;
82 }
83 return false;
84 };
85
86 /**
87 * Handles toggling the visibility of the button.
88 *
89 * @private
90 * @param {boolean} visible
91 * @fires ve.ui.MWTransclusionOutlineToggleUnusedWidget#toggleUnusedFields
92 */
93 ve.ui.MWTransclusionOutlineToggleUnusedWidget.prototype.onToggle = function ( visible ) {
94 if ( visible ) {
95 this.emit( 'toggleUnusedFields', this.showUnusedFields );
96 }
97 };