X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=resources%2Flib%2Foojs-ui%2Foojs-ui-widgets.js;h=58ff9e5443fb7a8e9a34d82e608d2018b01d8b71;hb=e164e35b1d07af22d0ca8420d4de5ee37a75c702;hp=a2e6e3413721b2b981bfa9b82a2669af757a6a58;hpb=6bb010ccaca4c8f55be1235c205663258826a04c;p=lhc%2Fweb%2Fwiklou.git diff --git a/resources/lib/oojs-ui/oojs-ui-widgets.js b/resources/lib/oojs-ui/oojs-ui-widgets.js index a2e6e34137..58ff9e5443 100644 --- a/resources/lib/oojs-ui/oojs-ui-widgets.js +++ b/resources/lib/oojs-ui/oojs-ui-widgets.js @@ -1,12 +1,12 @@ /*! - * OOjs UI v0.21.1 + * OOjs UI v0.21.2 * https://www.mediawiki.org/wiki/OOjs_UI * * Copyright 2011–2017 OOjs UI Team and other contributors. * Released under the MIT license * http://oojs.mit-license.org * - * Date: 2017-04-18T23:32:49Z + * Date: 2017-04-26T01:05:10Z */ ( function ( OO ) { @@ -628,7 +628,8 @@ OO.ui.mixin.RequestManager.prototype.getRequestCacheDataFromResponse = null; * * @constructor * @param {Object} [config] Configuration options - * @cfg {jQuery} [$overlay] Overlay for the lookup menu; defaults to relative positioning + * @cfg {jQuery} [$overlay] Overlay for the lookup menu; defaults to relative positioning. + * See . * @cfg {jQuery} [$container=this.$element] The container element. The lookup menu is rendered beneath the specified element. * @cfg {boolean} [allowSuggestionsWhenEmpty=false] Request and display a lookup menu when the text input is empty. * By default, the lookup menu is not generated and displayed until the user begins to type. @@ -669,6 +670,11 @@ OO.ui.mixin.LookupElement = function OoUiMixinLookupElement( config ) { } ); // Initialization + this.$input.attr( { + role: 'combobox', + 'aria-owns': this.lookupMenu.getElementId(), + 'aria-autocomplete': 'list' + } ); this.$element.addClass( 'oo-ui-lookupElement' ); this.lookupMenu.$element.addClass( 'oo-ui-lookupElement-menu' ); this.$overlay.append( this.lookupMenu.$element ); @@ -3701,6 +3707,7 @@ OO.ui.CapsuleItemWidget.prototype.focus = function () { * its containing `
`. The specified overlay layer is usually on top of * the containing `
` and has a larger area. By default, the menu uses * relative positioning. + * See . */ OO.ui.CapsuleMultiselectWidget = function OoUiCapsuleMultiselectWidget( config ) { var $tabFocus; @@ -3795,6 +3802,7 @@ OO.ui.CapsuleMultiselectWidget = function OoUiCapsuleMultiselectWidget( config ) this.$input.prop( 'disabled', this.isDisabled() ); this.$input.attr( { role: 'combobox', + 'aria-owns': this.menu.getElementId(), 'aria-autocomplete': 'list' } ); } @@ -5512,7 +5520,8 @@ OO.ui.TagMultiselectWidget.prototype.isValid = function () { * @mixins OO.ui.mixin.PopupElement * * @param {Object} config Configuration object - * @cfg {jQuery} [$overlay] An overlay for the popup + * @cfg {jQuery} [$overlay] An overlay for the popup. + * See . * @cfg {Object} [popup] Configuration options for the popup * @cfg {OO.ui.InputWidget} [popupInput] An input widget inside the popup that will be * focused when the popup is opened and will be used as replacement for the @@ -5566,6 +5575,7 @@ OO.ui.PopupTagMultiselectWidget = function OoUiPopupTagMultiselectWidget( config } // Events + this.on( 'resize', this.popup.updateDimensions.bind( this.popup ) ); this.popup.connect( this, { toggle: 'onPopupToggle' } ); this.$tabIndexed .on( 'focus', this.focus.bind( this ) ); @@ -5675,7 +5685,8 @@ OO.ui.PopupTagMultiselectWidget.prototype.addTagByPopupValue = function ( data, * @constructor * @param {Object} [config] Configuration object * @cfg {Object} [menu] Configuration object for the menu widget - * @cfg {jQuery} [$overlay] An overlay for the menu + * @cfg {jQuery} [$overlay] An overlay for the menu. + * See . * @cfg {Object[]} [options=[]] Array of menu options in the format `{ data: …, label: … }` */ OO.ui.MenuTagMultiselectWidget = function OoUiMenuTagMultiselectWidget( config ) { @@ -6546,14 +6557,13 @@ OO.ui.SearchWidget.prototype.getResults = function () { * $( 'body' ).append( numberInput.$element ); * * @class - * @extends OO.ui.Widget + * @extends OO.ui.TextInputWidget * * @constructor * @param {Object} [config] Configuration options - * @cfg {Object} [input] Configuration options to pass to the {@link OO.ui.TextInputWidget text input widget}. * @cfg {Object} [minusButton] Configuration options to pass to the {@link OO.ui.ButtonWidget decrementing button widget}. * @cfg {Object} [plusButton] Configuration options to pass to the {@link OO.ui.ButtonWidget incrementing button widget}. - * @cfg {boolean} [isInteger=false] Whether the field accepts only integer values. + * @cfg {boolean} [allowInteger=false] Whether the field accepts only integer values. * @cfg {number} [min=-Infinity] Minimum allowed value * @cfg {number} [max=Infinity] Maximum allowed value * @cfg {number} [step=1] Delta when using the buttons or up/down arrow keys @@ -6561,6 +6571,9 @@ OO.ui.SearchWidget.prototype.getResults = function () { * @cfg {boolean} [showButtons=true] Whether to show the plus and minus buttons. */ OO.ui.NumberInputWidget = function OoUiNumberInputWidget( config ) { + var $field = $( '
' ) + .addClass( 'oo-ui-numberInputWidget-field' ); + // Configuration initialization config = $.extend( { isInteger: false, @@ -6571,17 +6584,15 @@ OO.ui.NumberInputWidget = function OoUiNumberInputWidget( config ) { showButtons: true }, config ); + // For backward compatibility + $.extend( config, config.input ); + this.input = this; + // Parent constructor - OO.ui.NumberInputWidget.parent.call( this, config ); + OO.ui.NumberInputWidget.parent.call( this, $.extend( config, { + type: 'number' + } ) ); - // Properties - this.input = new OO.ui.TextInputWidget( $.extend( - { - disabled: this.isDisabled(), - type: 'number' - }, - config.input - ) ); if ( config.showButtons ) { this.minusButton = new OO.ui.ButtonWidget( $.extend( { @@ -6604,11 +6615,7 @@ OO.ui.NumberInputWidget = function OoUiNumberInputWidget( config ) { } // Events - this.input.connect( this, { - change: this.emit.bind( this, 'change' ), - enter: this.emit.bind( this, 'enter' ) - } ); - this.input.$input.on( { + this.$input.on( { keydown: this.onKeyDown.bind( this ), 'wheel mousewheel DOMMouseScroll': this.onWheel.bind( this ) } ); @@ -6621,40 +6628,31 @@ OO.ui.NumberInputWidget = function OoUiNumberInputWidget( config ) { } ); } - // Initialization - this.setIsInteger( !!config.isInteger ); - this.setRange( config.min, config.max ); - this.setStep( config.step, config.pageStep ); - - this.$field = $( '
' ).addClass( 'oo-ui-numberInputWidget-field' ) - .append( this.input.$element ); - this.$element.addClass( 'oo-ui-numberInputWidget' ).append( this.$field ); + // Build the field + $field.append( this.$input ); if ( config.showButtons ) { - this.$field + $field .prepend( this.minusButton.$element ) .append( this.plusButton.$element ); - this.$element.addClass( 'oo-ui-numberInputWidget-buttoned' ); } - this.input.setValidation( this.validateNumber.bind( this ) ); -}; - -/* Setup */ -OO.inheritClass( OO.ui.NumberInputWidget, OO.ui.Widget ); + // Initialization + this.setAllowInteger( config.isInteger || config.allowInteger ); + this.setRange( config.min, config.max ); + this.setStep( config.step, config.pageStep ); + // Set the validation method after we set isInteger and range + // so that it doesn't immediately call setValidityFlag + this.setValidation( this.validateNumber.bind( this ) ); -/* Events */ + this.$element + .addClass( 'oo-ui-numberInputWidget' ) + .toggleClass( 'oo-ui-numberInputWidget-buttoned', config.showButtons ) + .append( $field ); +}; -/** - * A `change` event is emitted when the value of the input changes. - * - * @event change - */ +/* Setup */ -/** - * An `enter` event is emitted when the user presses 'enter' inside the text box. - * - * @event enter - */ +OO.inheritClass( OO.ui.NumberInputWidget, OO.ui.TextInputWidget ); /* Methods */ @@ -6663,19 +6661,23 @@ OO.inheritClass( OO.ui.NumberInputWidget, OO.ui.Widget ); * * @param {boolean} flag */ -OO.ui.NumberInputWidget.prototype.setIsInteger = function ( flag ) { +OO.ui.NumberInputWidget.prototype.setAllowInteger = function ( flag ) { this.isInteger = !!flag; - this.input.setValidityFlag(); + this.setValidityFlag(); }; +// Backward compatibility +OO.ui.NumberInputWidget.prototype.setIsInteger = OO.ui.NumberInputWidget.prototype.setAllowInteger; /** * Get whether only integers are allowed * * @return {boolean} Flag value */ -OO.ui.NumberInputWidget.prototype.getIsInteger = function () { +OO.ui.NumberInputWidget.prototype.getAllowInteger = function () { return this.isInteger; }; +// Backward compatibility +OO.ui.NumberInputWidget.prototype.getIsInteger = OO.ui.NumberInputWidget.prototype.getAllowInteger; /** * Set the range of allowed values @@ -6689,7 +6691,7 @@ OO.ui.NumberInputWidget.prototype.setRange = function ( min, max ) { } this.min = min; this.max = max; - this.input.setValidityFlag(); + this.setValidityFlag(); }; /** @@ -6729,31 +6731,13 @@ OO.ui.NumberInputWidget.prototype.getStep = function () { return [ this.step, this.pageStep ]; }; -/** - * Get the current value of the widget - * - * @return {string} - */ -OO.ui.NumberInputWidget.prototype.getValue = function () { - return this.input.getValue(); -}; - /** * Get the current value of the widget as a number * * @return {number} May be NaN, or an invalid number */ OO.ui.NumberInputWidget.prototype.getNumericValue = function () { - return +this.input.getValue(); -}; - -/** - * Set the value of the widget - * - * @param {string} value Invalid values are allowed - */ -OO.ui.NumberInputWidget.prototype.setValue = function ( value ) { - this.input.setValue( value ); + return +this.getValue(); }; /** @@ -6783,7 +6767,6 @@ OO.ui.NumberInputWidget.prototype.adjustValue = function ( delta ) { this.setValue( n ); } }; - /** * Validate input * @@ -6793,6 +6776,10 @@ OO.ui.NumberInputWidget.prototype.adjustValue = function ( delta ) { */ OO.ui.NumberInputWidget.prototype.validateNumber = function ( value ) { var n = +value; + if ( value === '' ) { + return !this.isRequired(); + } + if ( isNaN( n ) || !isFinite( n ) ) { return false; } @@ -6827,7 +6814,7 @@ OO.ui.NumberInputWidget.prototype.onButtonClick = function ( dir ) { OO.ui.NumberInputWidget.prototype.onWheel = function ( event ) { var delta = 0; - if ( !this.isDisabled() && this.input.$input.is( ':focus' ) ) { + if ( !this.isDisabled() && this.$input.is( ':focus' ) ) { // Standard 'wheel' event if ( event.originalEvent.deltaMode !== undefined ) { this.sawWheelEvent = true; @@ -6892,9 +6879,6 @@ OO.ui.NumberInputWidget.prototype.setDisabled = function ( disabled ) { // Parent method OO.ui.NumberInputWidget.parent.prototype.setDisabled.call( this, disabled ); - if ( this.input ) { - this.input.setDisabled( this.isDisabled() ); - } if ( this.minusButton ) { this.minusButton.setDisabled( this.isDisabled() ); }