jenkins-bot has submitted this change and it was merged. Change subject: Implement new CheckboxWidget class ......................................................................
Implement new CheckboxWidget class This also provides a CheckboxInputWidget, which is unlabelled. Additionally, fix TextInputWidget to not try to set the type on the input as that won't work in IE. Change-Id: I84bd5e46753d3627b2e26820082c2aeca15b0772 --- M build/modules.json M src/styles/OO.ui.Widget.css A src/widgets/OO.ui.CheckboxInputWidget.js A src/widgets/OO.ui.CheckboxWidget.js M src/widgets/OO.ui.TextInputWidget.js 5 files changed, 110 insertions(+), 1 deletion(-) Approvals: Krinkle: Looks good to me, approved jenkins-bot: Verified diff --git a/build/modules.json b/build/modules.json index 81fd212..c41f6f2 100644 --- a/build/modules.json +++ b/build/modules.json @@ -34,6 +34,8 @@ "src/widgets/OO.ui.ButtonWidget.js", "src/widgets/OO.ui.IconButtonWidget.js", "src/widgets/OO.ui.InputWidget.js", + "src/widgets/OO.ui.CheckboxInputWidget.js", + "src/widgets/OO.ui.CheckboxWidget.js", "src/widgets/OO.ui.InputLabelWidget.js", "src/widgets/OO.ui.LookupInputWidget.js", "src/widgets/OO.ui.OptionWidget.js", diff --git a/src/styles/OO.ui.Widget.css b/src/styles/OO.ui.Widget.css index 1af4771..41ac97c 100644 --- a/src/styles/OO.ui.Widget.css +++ b/src/styles/OO.ui.Widget.css @@ -404,6 +404,16 @@ background-repeat: no-repeat; } +/* OO.ui.CheckboxWidget */ +.oo-ui-checkboxWidget .oo-ui-labeledElement-label { + display: inline-block; + vertical-align: middle; +} + +.oo-ui-checkboxWidget input { + vertical-align: middle; +} + /* OO.ui.MenuWidget */ .oo-ui-menuWidget { diff --git a/src/widgets/OO.ui.CheckboxInputWidget.js b/src/widgets/OO.ui.CheckboxInputWidget.js new file mode 100644 index 0000000..c2648c3 --- /dev/null +++ b/src/widgets/OO.ui.CheckboxInputWidget.js @@ -0,0 +1,69 @@ +/** + * Creates an OO.ui.CheckboxInputWidget object. + * + * @class + * @extends OO.ui.InputWidget + * + * @constructor + * @param {Object} [config] Configuration options + */ +OO.ui.CheckboxInputWidget = function OoUiCheckboxInputWidget( config ) { + config = config || {}; + + // Parent constructor + OO.ui.InputWidget.call( this, config ); + + this.value = false; + + // Initialization + this.$element.addClass( 'oo-ui-checkboxInputWidget' ); +}; + +/* Inheritance */ + +OO.inheritClass( OO.ui.CheckboxInputWidget, OO.ui.InputWidget ); + +/* Events */ + +/* Methods */ + +/** + * Get input element. + * + * @returns {jQuery} Input element + */ +OO.ui.CheckboxInputWidget.prototype.getInputElement = function () { + return this.$( '<input type="checkbox" />' ); +}; + +/** + * Get checked state of the checkbox + * + * @returns {boolean} If the checkbox is checked + */ +OO.ui.CheckboxInputWidget.prototype.getValue = function () { + return this.value; +}; + +/** + * Set value + */ +OO.ui.CheckboxInputWidget.prototype.setValue = function ( value ) { + if ( this.value !== value ) { + this.value = !!value; + this.$element.attr( 'checked', this.value ); + this.emit( 'change', this.value ); + } +}; + +/** + * @inheritdoc + */ +OO.ui.CheckboxInputWidget.prototype.onEdit = function () { + if ( !this.disabled ) { + // Allow the stack to clear so the value will be updated + setTimeout( OO.ui.bind( function () { + this.setValue( this.$input.attr( 'checked' ) ); + }, this ) ); + } +}; \ No newline at end of file diff --git a/src/widgets/OO.ui.CheckboxWidget.js b/src/widgets/OO.ui.CheckboxWidget.js new file mode 100644 index 0000000..d18c353 --- /dev/null +++ b/src/widgets/OO.ui.CheckboxWidget.js @@ -0,0 +1,28 @@ +/** + * Creates an OO.ui.CheckboxWidget object. + * + * @class + * @extends OO.ui.CheckboxInputWidget + * @mixins OO.ui.LabeledElement + * + * @constructor + * @param {Object} [config] Configuration options + * @cfg {string} [label=''] Label + */ +OO.ui.CheckboxWidget = function OoUiCheckboxWidget( config ) { + config = config || {}; + + // Parent constructors + OO.ui.CheckboxInputWidget.call( this, config ); + OO.ui.LabeledElement.call( this, this.$( '<span>' ) , config ); + + this.$( '<label>' ).append( this.$input, this.$label ).appendTo( this.$element ); + + // Initialization + this.$element.addClass( 'oo-ui-checkboxWidget' ); +}; + +/* Inheritance */ + +OO.inheritClass( OO.ui.CheckboxWidget, OO.ui.CheckboxInputWidget ); +OO.mixinClass( OO.ui.CheckboxWidget, OO.ui.LabeledElement ); diff --git a/src/widgets/OO.ui.TextInputWidget.js b/src/widgets/OO.ui.TextInputWidget.js index 082a4c1..ec2ec3e 100644 --- a/src/widgets/OO.ui.TextInputWidget.js +++ b/src/widgets/OO.ui.TextInputWidget.js @@ -77,7 +77,7 @@ * @returns {jQuery} Input element */ OO.ui.TextInputWidget.prototype.getInputElement = function ( config ) { - return config.multiline ? this.$( '<textarea>' ) : this.$( '<input>' ).attr( 'type', 'text' ); + return config.multiline ? this.$( '<textarea>' ) : this.$( '<input type="text" />' ); }; /* Methods */ -- To view, visit https://gerrit.wikimedia.org/r/96223 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I84bd5e46753d3627b2e26820082c2aeca15b0772 Gerrit-PatchSet: 13 Gerrit-Project: oojs/ui Gerrit-Branch: master Gerrit-Owner: Jforrester <jforres...@wikimedia.org> Gerrit-Reviewer: Catrope <roan.katt...@gmail.com> Gerrit-Reviewer: Jforrester <jforres...@wikimedia.org> Gerrit-Reviewer: Krinkle <krinklem...@gmail.com> Gerrit-Reviewer: Trevor Parscal <tpars...@wikimedia.org> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits