diff options
author | James D. Forrester <jforrester@wikimedia.org> | 2014-11-21 14:32:42 -0800 |
---|---|---|
committer | James D. Forrester <jforrester@wikimedia.org> | 2014-11-21 14:34:28 -0800 |
commit | 5c0fecfe55418b85e1ddbd5b1255d0353eb774de (patch) | |
tree | cffb98ce0c8c7ffa83fee1cc9b762cc291e74eb1 /resources/lib/oojs-ui/oojs-ui.js | |
parent | f58cfa84a653ca8fb8e3b2089c20bc7e1d2b9d8d (diff) | |
download | mediawikicore-5c0fecfe55418b85e1ddbd5b1255d0353eb774de.tar.gz mediawikicore-5c0fecfe55418b85e1ddbd5b1255d0353eb774de.zip |
Update OOjs UI to v0.1.0-pre (8f8896196f)
New changes:
56587a8 [BREAKING CHANGE] Rename InputWidget#sanitizeValue → #cleanUpValue
4253739 Implement radio button widgets
Change-Id: If10927a4e595de9b6d0ad45182470e84f335683c
Diffstat (limited to 'resources/lib/oojs-ui/oojs-ui.js')
-rw-r--r-- | resources/lib/oojs-ui/oojs-ui.js | 154 |
1 files changed, 147 insertions, 7 deletions
diff --git a/resources/lib/oojs-ui/oojs-ui.js b/resources/lib/oojs-ui/oojs-ui.js index 9b2c13f4ca48..30e5e4e4cfc9 100644 --- a/resources/lib/oojs-ui/oojs-ui.js +++ b/resources/lib/oojs-ui/oojs-ui.js @@ -1,12 +1,12 @@ /*! - * OOjs UI v0.1.0-pre (23565e7519) + * OOjs UI v0.1.0-pre (8f8896196f) * https://www.mediawiki.org/wiki/OOjs_UI * * Copyright 2011–2014 OOjs Team and other contributors. * Released under the MIT license * http://oojs.mit-license.org * - * Date: 2014-11-21T22:18:20Z + * Date: 2014-11-21T22:32:28Z */ ( function ( OO ) { @@ -9163,12 +9163,12 @@ OO.ui.InputWidget.prototype.setRTL = function ( isRTL ) { * @chainable */ OO.ui.InputWidget.prototype.setValue = function ( value ) { - value = this.sanitizeValue( value ); + value = this.cleanUpValue( value ); if ( this.value !== value ) { this.value = value; this.emit( 'change', this.value ); } - // Update the DOM if it has changed. Note that with sanitizeValue, it + // Update the DOM if it has changed. Note that with cleanUpValue, it // is possible for the DOM value to change without this.value changing. if ( this.$input.val() !== this.value ) { this.$input.val( this.value ); @@ -9177,15 +9177,15 @@ OO.ui.InputWidget.prototype.setValue = function ( value ) { }; /** - * Sanitize incoming value. + * Clean up incoming value. * * Ensures value is a string, and converts undefined and null to empty string. * * @private * @param {string} value Original value - * @return {string} Sanitized value + * @return {string} Cleaned up value */ -OO.ui.InputWidget.prototype.sanitizeValue = function ( value ) { +OO.ui.InputWidget.prototype.cleanUpValue = function ( value ) { if ( value === undefined || value === null ) { return ''; } else if ( this.inputFilter ) { @@ -9463,6 +9463,74 @@ OO.ui.CheckboxInputWidget.prototype.onEdit = function () { }; /** + * Radio input widget. + * + * Radio buttons only make sense as a set, and you probably want to use the OO.ui.RadioSelectWidget + * class instead of using this class directly. + * + * This class doesn't make it possible to learn whether the radio button is selected ("pressed"). + * + * @class + * @extends OO.ui.InputWidget + * + * @constructor + * @param {Object} [config] Configuration options + * @param {boolean} [config.selected=false] Whether the radio button is initially selected + */ +OO.ui.RadioInputWidget = function OoUiRadioInputWidget( config ) { + // Parent constructor + OO.ui.RadioInputWidget.super.call( this, config ); + + // Initialization + this.$element.addClass( 'oo-ui-radioInputWidget' ); + this.setSelected( config.selected !== undefined ? config.selected : false ); +}; + +/* Setup */ + +OO.inheritClass( OO.ui.RadioInputWidget, OO.ui.InputWidget ); + +/* Methods */ + +/** + * Get input element. + * + * @private + * @return {jQuery} Input element + */ +OO.ui.RadioInputWidget.prototype.getInputElement = function () { + return this.$( '<input type="radio" />' ); +}; + +/** + * @inheritdoc + */ +OO.ui.RadioInputWidget.prototype.onEdit = function () { + // RadioInputWidget doesn't track its state. +}; + +/** + * Set selection state of this radio button. + * + * @param {boolean} state Whether the button is selected + * @chainable + */ +OO.ui.RadioInputWidget.prototype.setSelected = function ( state ) { + // RadioInputWidget doesn't track its state. + this.$input.prop( 'checked', state ); + return this; +}; + +/** + * Check if this radio button is selected. + * + * @return {boolean} Radio is selected + */ +OO.ui.RadioInputWidget.prototype.isSelected = function () { + return this.$input.prop( 'checked' ); +}; + +/** * Input widget with a text field. * * @class @@ -10241,6 +10309,55 @@ OO.ui.ButtonOptionWidget.prototype.setSelected = function ( state ) { }; /** + * Option widget that looks like a radio button. + * + * Use together with OO.ui.RadioSelectWidget. + * + * @class + * @extends OO.ui.OptionWidget + * @mixins OO.ui.ButtonElement + * + * @constructor + * @param {Mixed} data Option data + * @param {Object} [config] Configuration options + */ +OO.ui.RadioOptionWidget = function OoUiRadioOptionWidget( data, config ) { + // Parent constructor + OO.ui.RadioOptionWidget.super.call( this, data, config ); + + // Properties + this.radio = new OO.ui.RadioInputWidget( { value: data } ); + + // Initialization + this.$element + .addClass( 'oo-ui-radioOptionWidget' ) + .prepend( this.radio.$element ); +}; + +/* Setup */ + +OO.inheritClass( OO.ui.RadioOptionWidget, OO.ui.OptionWidget ); + +/* Static Properties */ + +OO.ui.RadioOptionWidget.static.highlightable = false; + +OO.ui.RadioOptionWidget.static.pressable = false; + +/* Methods */ + +/** + * @inheritdoc + */ +OO.ui.RadioOptionWidget.prototype.setSelected = function ( state ) { + OO.ui.RadioOptionWidget.super.prototype.setSelected.call( this, state ); + + this.radio.setSelected( state ); + + return this; +}; + +/** * Item of an OO.ui.MenuSelectWidget. * * @class @@ -11477,6 +11594,29 @@ OO.ui.ButtonSelectWidget = function OoUiButtonSelectWidget( config ) { OO.inheritClass( OO.ui.ButtonSelectWidget, OO.ui.SelectWidget ); /** + * Select widget containing radio button options. + * + * Use together with OO.ui.RadioOptionWidget. + * + * @class + * @extends OO.ui.SelectWidget + * + * @constructor + * @param {Object} [config] Configuration options + */ +OO.ui.RadioSelectWidget = function OoUiRadioSelectWidget( config ) { + // Parent constructor + OO.ui.RadioSelectWidget.super.call( this, config ); + + // Initialization + this.$element.addClass( 'oo-ui-radioSelectWidget' ); +}; + +/* Setup */ + +OO.inheritClass( OO.ui.RadioSelectWidget, OO.ui.SelectWidget ); + +/** * Overlaid menu of options. * * Menus are clipped to the visible viewport. They do not provide a control for opening or closing |