Debian Codegraph @

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

raw symbols SCIP
1 /**
2 * A widget that represents a template parameter, with a checkbox to add/remove the parameter.
3 * Modelled after {@see OO.ui.OutlineOptionWidget}. Also see {@see OO.ui.CheckboxMultioptionWidget}
4 * for inspiration.
5 *
6 * @class
7 * @extends OO.ui.OptionWidget
8 *
9 * @constructor
10 * @param {Object} config
11 * @param {string} config.data Parameter name
12 * @param {string} config.label
13 * @param {boolean} [config.required=false] Required parameters can't be unchecked
14 * @param {boolean} [config.selected=false] If the parameter is currently used (checked)
15 * @param {boolean} [config.hasValue=false] If the parameter has a value that's not empty
16 */
17 ve.ui.MWTransclusionOutlineParameterWidget = function VeUiMWTransclusionOutlineParameterWidget( config ) {
18 this.checkbox = new OO.ui.CheckboxInputWidget( {
19 title: config.required ?
20 ve.msg( 'visualeditor-dialog-transclusion-required-parameter' ) :
21 null,
22 disabled: config.required,
23 selected: config.selected || config.required,
24 // Keyboard navigation is handled by the outer OO.ui.SelectWidget
25 tabIndex: -1
26 } )
27 .connect( this, {
28 // The array syntax is a way to call `this.emit( 'change' )`.
29 change: [ 'emit', 'change' ]
30 } );
31 this.checkbox.$input.on( {
32 mousedown: this.onMouseDown.bind( this )
33 } );
34
35 // Parent constructor
36 ve.ui.MWTransclusionOutlineParameterWidget.super.call( this, ve.extendObject( config, {
37 classes: [ 've-ui-mwTransclusionOutlineParameterWidget' ],
38 $label: $( '<label>' )
39 } ) );
40
41 this.toggleHasValue( config.hasValue );
42
43 // Initialization
44 this.$element
45 .append( this.checkbox.$element, this.$label );
46 };
47
48 /* Inheritance */
49
50 OO.inheritClass( ve.ui.MWTransclusionOutlineParameterWidget, OO.ui.OptionWidget );
51
52 /* Methods */
53
54 /**
55 * @private
56 * @param {jQuery.Event} e
57 */
58 ve.ui.MWTransclusionOutlineParameterWidget.prototype.onMouseDown = function ( e ) {
59 // Mouse clicks conflict with the click handler in {@see OO.ui.SelectWidget}
60 e.stopPropagation();
61 };
62
63 /**
64 * @inheritDoc OO.ui.OptionWidget
65 */
66 ve.ui.MWTransclusionOutlineParameterWidget.prototype.setSelected = function ( state ) {
67 // Never uncheck a required parameter
68 state = state || this.checkbox.isDisabled();
69
70 this.checkbox.setSelected( state, true );
71 return ve.ui.MWTransclusionOutlineParameterWidget.super.prototype.setSelected.call( this, state );
72 };
73
74 /**
75 * @param {boolean} state
76 */
77 ve.ui.MWTransclusionOutlineParameterWidget.prototype.toggleActivePageIndicator = function ( state ) {
78 this.$element.toggleClass( 've-ui-mwTransclusionOutlineParameterWidget-activePage', state );
79 };
80
81 /**
82 * @param {boolean} hasValue
83 */
84 ve.ui.MWTransclusionOutlineParameterWidget.prototype.toggleHasValue = function ( hasValue ) {
85 this.$element.toggleClass( 've-ui-mwTransclusionOutlineParameterWidget-hasValue', hasValue );
86 };
87
88 /**
89 * Custom method to scroll parameter into view respecting the sticky part that sits above
90 *
91 * @param {number} paddingTop
92 */
93 ve.ui.MWTransclusionOutlineParameterWidget.prototype.ensureVisibility = function ( paddingTop ) {
94 // make sure parameter is visible and scrolled underneath the sticky
95 this.scrollElementIntoView( { animate: false, padding: { top: paddingTop } } );
96 };