mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-18 03:41:45 +00:00
5e2cd392c7
Bug: T274545 Change-Id: I0514a93f4313914a654e5f24cf78950cb4893409
63 lines
1.8 KiB
JavaScript
63 lines
1.8 KiB
JavaScript
/*!
|
|
* VisualEditor user interface MWTemplateOutlineParameterCheckboxLayout class.
|
|
*
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* Container for checkbox and label
|
|
*
|
|
* @class
|
|
* @extends OO.ui.FieldLayout
|
|
*
|
|
* @constructor
|
|
* @param {Object} [config] Configuration options
|
|
*/
|
|
ve.ui.MWTemplateOutlineParameterCheckboxLayout = function VeUiMWTemplateOutlineParameterCheckboxLayout( config ) {
|
|
config = config || {};
|
|
config = $.extend( { align: 'inline' }, config );
|
|
|
|
this.checkbox = new OO.ui.CheckboxInputWidget( {
|
|
title: config.required ? ve.msg( 'visualeditor-dialog-transclusion-required-parameter' ) : null,
|
|
disabled: config.required,
|
|
selected: config.selected || config.required
|
|
} )
|
|
// FIXME: pass-through binding like [ 'emit', 'toggle' ]?
|
|
.connect( this, {
|
|
change: 'onEdit'
|
|
} );
|
|
|
|
// Parent constructor
|
|
ve.ui.MWTemplateOutlineParameterCheckboxLayout.super.call( this, this.checkbox, config );
|
|
|
|
// Initialization
|
|
this.$element.addClass( 've-ui-templateOutlineItem' );
|
|
|
|
// Override base behaviors
|
|
// Unwire native label->input linkage, and replace with our custom click handler.
|
|
this.$label
|
|
.attr( 'for', null );
|
|
this.$header
|
|
.on( 'click', this.onLabelClick.bind( this ) );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
OO.inheritClass( ve.ui.MWTemplateOutlineParameterCheckboxLayout, OO.ui.FieldLayout );
|
|
|
|
/* Methods */
|
|
ve.ui.MWTemplateOutlineParameterCheckboxLayout.prototype.onEdit = function ( value ) {
|
|
this.emit( 'change', this.getData(), value );
|
|
};
|
|
|
|
ve.ui.MWTemplateOutlineParameterCheckboxLayout.prototype.onLabelClick = function () {
|
|
if ( !this.fieldWidget.isSelected() ) {
|
|
this.fieldWidget.setSelected( true );
|
|
}
|
|
this.emit( 'select', this.getData() );
|
|
};
|
|
|
|
ve.ui.MWTemplateOutlineParameterCheckboxLayout.prototype.setSelected = function ( state, internal ) {
|
|
this.checkbox.setSelected( state, internal );
|
|
};
|