X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=resources%2Flib%2Foojs-ui%2Foojs-ui-widgets.js;h=7a386331fc747d23c916e26d8e06c6dd88595184;hb=b47fbb4fde9ddddc6f94d07638150834d49bc73b;hp=cd6233900597a98a5e5a68ca2c2637f5b7c357df;hpb=81fddcf9e4ff1a66f107260628736788f4601e08;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 cd62339005..8242c86c7d 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.17.7 + * OOjs UI v0.18.1 * https://www.mediawiki.org/wiki/OOjs_UI * * Copyright 2011–2016 OOjs UI Team and other contributors. * Released under the MIT license * http://oojs.mit-license.org * - * Date: 2016-08-03T16:38:22Z + * Date: 2016-11-29T22:57:37Z */ ( function ( OO ) { @@ -85,7 +85,7 @@ OO.ui.mixin.DraggableElement.static.cancelButtonMouseDownEvents = false; * Respond to mousedown event. * * @private - * @param {jQuery.Event} e jQuery event + * @param {jQuery.Event} e Drag event */ OO.ui.mixin.DraggableElement.prototype.onDragMouseDown = function ( e ) { this.wasHandleUsed = @@ -99,7 +99,8 @@ OO.ui.mixin.DraggableElement.prototype.onDragMouseDown = function ( e ) { * Respond to dragstart event. * * @private - * @param {jQuery.Event} e jQuery event + * @param {jQuery.Event} e Drag event + * @return {boolean} False if the event is cancelled * @fires dragstart */ OO.ui.mixin.DraggableElement.prototype.onDragStart = function ( e ) { @@ -149,7 +150,7 @@ OO.ui.mixin.DraggableElement.prototype.onDragEnd = function () { * Handle drop event. * * @private - * @param {jQuery.Event} e jQuery event + * @param {jQuery.Event} e Drop event * @fires drop */ OO.ui.mixin.DraggableElement.prototype.onDrop = function ( e ) { @@ -161,6 +162,7 @@ OO.ui.mixin.DraggableElement.prototype.onDrop = function ( e ) { * In order for drag/drop to work, the dragover event must * return false and stop propogation. * + * @param {jQuery.Event} e Drag event * @private */ OO.ui.mixin.DraggableElement.prototype.onDragOver = function ( e ) { @@ -2170,7 +2172,7 @@ OO.ui.BookletLayout.prototype.selectFirstSelectablePage = function () { * }; * * var card1 = new CardOneLayout( 'one' ), - * card2 = new CardLayout( 'two', { label: 'Card two' } ); + * card2 = new OO.ui.CardLayout( 'two', { label: 'Card two' } ); * * card2.$element.append( '

Second card

' ); * @@ -2709,7 +2711,7 @@ OO.ui.ToggleButtonWidget = function OoUiToggleButtonWidget( config ) { OO.ui.ToggleButtonWidget.parent.call( this, config ); // Mixin constructors - OO.ui.mixin.ButtonElement.call( this, config ); + OO.ui.mixin.ButtonElement.call( this, $.extend( {}, config, { active: this.active } ) ); OO.ui.mixin.IconElement.call( this, config ); OO.ui.mixin.IndicatorElement.call( this, config ); OO.ui.mixin.LabelElement.call( this, config ); @@ -3057,7 +3059,7 @@ OO.inheritClass( OO.ui.OutlineOptionWidget, OO.ui.DecoratedOptionWidget ); /* Static Properties */ -OO.ui.OutlineOptionWidget.static.highlightable = false; +OO.ui.OutlineOptionWidget.static.highlightable = true; OO.ui.OutlineOptionWidget.static.scrollIntoViewOnSelect = true; @@ -3098,6 +3100,19 @@ OO.ui.OutlineOptionWidget.prototype.getLevel = function () { return this.level; }; +/** + * @inheritdoc + */ +OO.ui.OutlineOptionWidget.prototype.setPressed = function ( state ) { + OO.ui.OutlineOptionWidget.parent.prototype.setPressed.call( this, state ); + if ( this.pressed ) { + this.setFlags( 'progressive' ); + } else if ( !this.selected ) { + this.clearFlags(); + } + return this; +}; + /** * Set movability. * @@ -3126,6 +3141,19 @@ OO.ui.OutlineOptionWidget.prototype.setRemovable = function ( removable ) { return this; }; +/** + * @inheritdoc + */ +OO.ui.OutlineOptionWidget.prototype.setSelected = function ( state ) { + OO.ui.OutlineOptionWidget.parent.prototype.setSelected.call( this, state ); + if ( this.selected ) { + this.setFlags( 'progressive' ); + } else { + this.clearFlags(); + } + return this; +}; + /** * Set indentation level. * @@ -3464,6 +3492,8 @@ OO.ui.CapsuleItemWidget.prototype.onClick = function () { /** * Handle keyDown event for the entire capsule + * + * @param {jQuery.Event} e Key down event */ OO.ui.CapsuleItemWidget.prototype.onKeyDown = function ( e ) { var element = this.getElementGroup(); @@ -3541,6 +3571,7 @@ OO.ui.CapsuleItemWidget.prototype.focus = function () { * * @constructor * @param {Object} [config] Configuration options + * @cfg {string} [placeholder] Placeholder text * @cfg {boolean} [allowArbitrary=false] Allow data items to be added even if not present in the menu. * @cfg {Object} [menu] (required) Configuration options to pass to the * {@link OO.ui.MenuSelectWidget menu select widget}. @@ -3567,8 +3598,11 @@ OO.ui.CapsuleMultiselectWidget = function OoUiCapsuleMultiselectWidget( config ) }, config ); // Properties (must be set before mixin constructor calls) - this.$input = config.popup ? null : $( '' ); this.$handle = $( '
' ); + this.$input = config.popup ? null : $( '' ); + if ( config.placeholder !== undefined && config.placeholder !== '' ) { + this.$input.attr( 'placeholder', config.placeholder ); + } // Mixin constructors OO.ui.mixin.GroupElement.call( this, config ); @@ -3629,6 +3663,7 @@ OO.ui.CapsuleMultiselectWidget = function OoUiCapsuleMultiselectWidget( config ) } this.menu.connect( this, { choose: 'onMenuChoose', + toggle: 'onMenuToggle', add: 'onMenuItemsChange', remove: 'onMenuItemsChange' } ); @@ -3643,7 +3678,6 @@ OO.ui.CapsuleMultiselectWidget = function OoUiCapsuleMultiselectWidget( config ) role: 'combobox', 'aria-autocomplete': 'list' } ); - this.updateInputSize(); } if ( config.data ) { this.setItemsFromData( config.data ); @@ -3662,6 +3696,14 @@ OO.ui.CapsuleMultiselectWidget = function OoUiCapsuleMultiselectWidget( config ) this.$content.append( this.$input ); this.$overlay.append( this.menu.$element ); } + + // Input size needs to be calculated after everything else is rendered + setTimeout( function () { + if ( this.$input ) { + this.updateInputSize(); + } + }.bind( this ) ); + this.onMenuItemsChange(); }; @@ -3878,9 +3920,12 @@ OO.ui.CapsuleMultiselectWidget.prototype.addItems = function ( items ) { * @param {Object} item */ OO.ui.CapsuleMultiselectWidget.prototype.editItem = function ( item ) { + this.addItemFromLabel( this.$input.val() ); + this.clearInput(); this.$input.val( item.label ); this.updateInputSize(); this.focus(); + this.menu.updateItemVisibility(); // Hack, we shouldn't be calling this method directly this.removeItems( [ item ] ); }; @@ -4029,8 +4074,7 @@ OO.ui.CapsuleMultiselectWidget.prototype.onPopupFocusOut = function () { setTimeout( function () { if ( widget.isVisible() && - !OO.ui.contains( widget.$element[ 0 ], document.activeElement, true ) && - ( !widget.$autoCloseIgnore || !widget.$autoCloseIgnore.has( document.activeElement ).length ) + !OO.ui.contains( widget.$element.add( widget.$autoCloseIgnore ).get(), document.activeElement, true ) ) { widget.toggle( false ); } @@ -4116,11 +4160,31 @@ OO.ui.CapsuleMultiselectWidget.prototype.onKeyDown = function ( e ) { */ OO.ui.CapsuleMultiselectWidget.prototype.updateInputSize = function () { var $lastItem, direction, contentWidth, currentWidth, bestWidth; - if ( !this.isDisabled() ) { + if ( this.$input && !this.isDisabled() ) { this.$input.css( 'width', '1em' ); $lastItem = this.$group.children().last(); direction = OO.ui.Element.static.getDir( this.$handle ); - contentWidth = this.$input[ 0 ].scrollWidth; + + // Get the width of the input with the placeholder text as + // the value and save it so that we don't keep recalculating + if ( + this.contentWidthWithPlaceholder === undefined && + this.$input.val() === '' && + this.$input.attr( 'placeholder' ) !== undefined + ) { + this.$input.val( this.$input.attr( 'placeholder' ) ); + this.contentWidthWithPlaceholder = this.$input[ 0 ].scrollWidth; + this.$input.val( '' ); + + } + + // Always keep the input wide enough for the placeholder text + contentWidth = Math.max( + this.$input[ 0 ].scrollWidth, + // undefined arguments in Math.max lead to NaN + ( this.contentWidthWithPlaceholder === undefined ) ? + 0 : this.contentWidthWithPlaceholder + ); currentWidth = this.$input.width(); if ( contentWidth < currentWidth ) { @@ -4128,13 +4192,14 @@ OO.ui.CapsuleMultiselectWidget.prototype.updateInputSize = function () { return; } - if ( !$lastItem.length ) { + if ( $lastItem.length === 0 ) { bestWidth = this.$content.innerWidth(); } else { bestWidth = direction === 'ltr' ? this.$content.innerWidth() - $lastItem.position().left - $lastItem.outerWidth() : $lastItem.position().left; } + // Some safety margin for sanity, because I *really* don't feel like finding out where the few // pixels this is off by are coming from. bestWidth -= 10; @@ -4174,6 +4239,16 @@ OO.ui.CapsuleMultiselectWidget.prototype.onMenuChoose = function ( item ) { } }; +/** + * Handle menu toggle events. + * + * @private + * @param {boolean} isVisible Menu toggle event + */ +OO.ui.CapsuleMultiselectWidget.prototype.onMenuToggle = function ( isVisible ) { + this.$element.toggleClass( 'oo-ui-capsuleMultiselectWidget-open', isVisible ); +}; + /** * Handle menu item change events. * @@ -4480,13 +4555,6 @@ OO.ui.SelectFileWidget.prototype.updateUI = function () { .addClass( 'oo-ui-selectFileWidget-fileName' ) .text( this.currentFile.name ) ); - if ( this.currentFile.type !== '' ) { - $label = $label.add( - $( '' ) - .addClass( 'oo-ui-selectFileWidget-fileType' ) - .text( this.currentFile.type ) - ); - } this.setLabel( $label ); if ( this.showDropTarget ) { @@ -4770,103 +4838,6 @@ OO.ui.SelectFileWidget.prototype.setDisabled = function ( disabled ) { return this; }; -/** - * Progress bars visually display the status of an operation, such as a download, - * and can be either determinate or indeterminate: - * - * - **determinate** process bars show the percent of an operation that is complete. - * - * - **indeterminate** process bars use a visual display of motion to indicate that an operation - * is taking place. Because the extent of an indeterminate operation is unknown, the bar does - * not use percentages. - * - * The value of the `progress` configuration determines whether the bar is determinate or indeterminate. - * - * @example - * // Examples of determinate and indeterminate progress bars. - * var progressBar1 = new OO.ui.ProgressBarWidget( { - * progress: 33 - * } ); - * var progressBar2 = new OO.ui.ProgressBarWidget(); - * - * // Create a FieldsetLayout to layout progress bars - * var fieldset = new OO.ui.FieldsetLayout; - * fieldset.addItems( [ - * new OO.ui.FieldLayout( progressBar1, {label: 'Determinate', align: 'top'}), - * new OO.ui.FieldLayout( progressBar2, {label: 'Indeterminate', align: 'top'}) - * ] ); - * $( 'body' ).append( fieldset.$element ); - * - * @class - * @extends OO.ui.Widget - * - * @constructor - * @param {Object} [config] Configuration options - * @cfg {number|boolean} [progress=false] The type of progress bar (determinate or indeterminate). - * To create a determinate progress bar, specify a number that reflects the initial percent complete. - * By default, the progress bar is indeterminate. - */ -OO.ui.ProgressBarWidget = function OoUiProgressBarWidget( config ) { - // Configuration initialization - config = config || {}; - - // Parent constructor - OO.ui.ProgressBarWidget.parent.call( this, config ); - - // Properties - this.$bar = $( '
' ); - this.progress = null; - - // Initialization - this.setProgress( config.progress !== undefined ? config.progress : false ); - this.$bar.addClass( 'oo-ui-progressBarWidget-bar' ); - this.$element - .attr( { - role: 'progressbar', - 'aria-valuemin': 0, - 'aria-valuemax': 100 - } ) - .addClass( 'oo-ui-progressBarWidget' ) - .append( this.$bar ); -}; - -/* Setup */ - -OO.inheritClass( OO.ui.ProgressBarWidget, OO.ui.Widget ); - -/* Static Properties */ - -OO.ui.ProgressBarWidget.static.tagName = 'div'; - -/* Methods */ - -/** - * Get the percent of the progress that has been completed. Indeterminate progresses will return `false`. - * - * @return {number|boolean} Progress percent - */ -OO.ui.ProgressBarWidget.prototype.getProgress = function () { - return this.progress; -}; - -/** - * Set the percent of the process completed or `false` for an indeterminate process. - * - * @param {number|boolean} progress Progress percent or `false` for indeterminate - */ -OO.ui.ProgressBarWidget.prototype.setProgress = function ( progress ) { - this.progress = progress; - - if ( progress !== false ) { - this.$bar.css( 'width', this.progress + '%' ); - this.$element.attr( 'aria-valuenow', this.progress ); - } else { - this.$bar.css( 'width', '' ); - this.$element.removeAttr( 'aria-valuenow' ); - } - this.$element.toggleClass( 'oo-ui-progressBarWidget-indeterminate', !progress ); -}; - /** * SearchWidgets combine a {@link OO.ui.TextInputWidget text input field}, where users can type a search query, * and a menu of search results, which is displayed beneath the query @@ -5263,11 +5234,11 @@ OO.ui.NumberInputWidget.prototype.validateNumber = function ( value ) { return false; } - /*jshint bitwise: false */ + /* eslint-disable no-bitwise */ if ( this.isInteger && ( n | 0 ) !== n ) { return false; } - /*jshint bitwise: true */ + /* eslint-enable no-bitwise */ if ( n < this.min || n > this.max ) { return false;