diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2015-12-20 09:00:55 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2015-12-20 09:00:55 +0100 |
commit | a2190ac74dd4d7080b12bab90e552d7aa81209ef (patch) | |
tree | 8b31f38de9882d18df54cf8d9e0de74167a094eb /vendor/oojs/oojs-ui/src/widgets/DropdownInputWidget.js | |
parent | 15e69f7b20b6596b9148030acce5b59993b95a45 (diff) | |
parent | 257401d8b2cf661adf36c84b0e3fd1cf85e33c22 (diff) |
Merge branch 'mw-1.26'
Diffstat (limited to 'vendor/oojs/oojs-ui/src/widgets/DropdownInputWidget.js')
-rw-r--r-- | vendor/oojs/oojs-ui/src/widgets/DropdownInputWidget.js | 137 |
1 files changed, 0 insertions, 137 deletions
diff --git a/vendor/oojs/oojs-ui/src/widgets/DropdownInputWidget.js b/vendor/oojs/oojs-ui/src/widgets/DropdownInputWidget.js deleted file mode 100644 index d4a5ce2a..00000000 --- a/vendor/oojs/oojs-ui/src/widgets/DropdownInputWidget.js +++ /dev/null @@ -1,137 +0,0 @@ -/** - * DropdownInputWidget is a {@link OO.ui.DropdownWidget DropdownWidget} intended to be used - * within a HTML form, such as a OO.ui.FormLayout. The selected value is synchronized with the value - * of a hidden HTML `input` tag. Please see the [OOjs UI documentation on MediaWiki][1] for - * more information about input widgets. - * - * @example - * // Example: A DropdownInputWidget with three options - * var dropDown = new OO.ui.DropdownInputWidget( { - * label: 'Dropdown menu: Select a menu option', - * options: [ - * { data: 'a', label: 'First' } , - * { data: 'b', label: 'Second'} , - * { data: 'c', label: 'Third' } - * ] - * } ); - * $( 'body' ).append( dropDown.$element ); - * - * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Inputs - * - * @class - * @extends OO.ui.InputWidget - * - * @constructor - * @param {Object} [config] Configuration options - * @cfg {Object[]} [options=[]] Array of menu options in the format `{ data: …, label: … }` - */ -OO.ui.DropdownInputWidget = function OoUiDropdownInputWidget( config ) { - // Configuration initialization - config = config || {}; - - // Properties (must be done before parent constructor which calls #setDisabled) - this.dropdownWidget = new OO.ui.DropdownWidget(); - - // Parent constructor - OO.ui.DropdownInputWidget.super.call( this, config ); - - // Events - this.dropdownWidget.getMenu().connect( this, { select: 'onMenuSelect' } ); - - // Initialization - this.setOptions( config.options || [] ); - this.$element - .addClass( 'oo-ui-dropdownInputWidget' ) - .append( this.dropdownWidget.$element ); -}; - -/* Setup */ - -OO.inheritClass( OO.ui.DropdownInputWidget, OO.ui.InputWidget ); - -/* Methods */ - -/** - * @inheritdoc - * @private - */ -OO.ui.DropdownInputWidget.prototype.getInputElement = function () { - return $( '<input type="hidden">' ); -}; - -/** - * Handles menu select events. - * - * @private - * @param {OO.ui.MenuOptionWidget} item Selected menu item - */ -OO.ui.DropdownInputWidget.prototype.onMenuSelect = function ( item ) { - this.setValue( item.getData() ); -}; - -/** - * @inheritdoc - */ -OO.ui.DropdownInputWidget.prototype.setValue = function ( value ) { - this.dropdownWidget.getMenu().selectItemByData( value ); - OO.ui.DropdownInputWidget.super.prototype.setValue.call( this, value ); - return this; -}; - -/** - * @inheritdoc - */ -OO.ui.DropdownInputWidget.prototype.setDisabled = function ( state ) { - this.dropdownWidget.setDisabled( state ); - OO.ui.DropdownInputWidget.super.prototype.setDisabled.call( this, state ); - return this; -}; - -/** - * Set the options available for this input. - * - * @param {Object[]} options Array of menu options in the format `{ data: …, label: … }` - * @chainable - */ -OO.ui.DropdownInputWidget.prototype.setOptions = function ( options ) { - var value = this.getValue(); - - // Rebuild the dropdown menu - this.dropdownWidget.getMenu() - .clearItems() - .addItems( options.map( function ( opt ) { - return new OO.ui.MenuOptionWidget( { - data: opt.data, - label: opt.label !== undefined ? opt.label : opt.data - } ); - } ) ); - - // Restore the previous value, or reset to something sensible - if ( this.dropdownWidget.getMenu().getItemFromData( value ) ) { - // Previous value is still available, ensure consistency with the dropdown - this.setValue( value ); - } else { - // No longer valid, reset - if ( options.length ) { - this.setValue( options[ 0 ].data ); - } - } - - return this; -}; - -/** - * @inheritdoc - */ -OO.ui.DropdownInputWidget.prototype.focus = function () { - this.dropdownWidget.getMenu().toggle( true ); - return this; -}; - -/** - * @inheritdoc - */ -OO.ui.DropdownInputWidget.prototype.blur = function () { - this.dropdownWidget.getMenu().toggle( false ); - return this; -}; |