Update OOUI to v0.26.4
[lhc/web/wiklou.git] / resources / lib / oojs-ui / oojs-ui-widgets.js
index fb8b14b..7407ed0 100644 (file)
@@ -1,12 +1,12 @@
 /*!
- * OOUI v0.25.3
+ * OOUI v0.26.4
  * https://www.mediawiki.org/wiki/OOUI
  *
  * Copyright 2011–2018 OOUI Team and other contributors.
  * Released under the MIT license
  * http://oojs.mit-license.org
  *
- * Date: 2018-03-07T06:52:35Z
+ * Date: 2018-04-17T22:23:58Z
  */
 ( function ( OO ) {
 
@@ -3272,11 +3272,6 @@ OO.ui.OutlineOptionWidget.prototype.getLevel = function () {
  */
 OO.ui.OutlineOptionWidget.prototype.setPressed = function ( state ) {
        OO.ui.OutlineOptionWidget.parent.prototype.setPressed.call( this, state );
-       if ( this.pressed ) {
-               this.setFlags( { progressive: true } );
-       } else if ( !this.selected ) {
-               this.setFlags( { progressive: false } );
-       }
        return this;
 };
 
@@ -3313,11 +3308,6 @@ OO.ui.OutlineOptionWidget.prototype.setRemovable = function ( removable ) {
  */
 OO.ui.OutlineOptionWidget.prototype.setSelected = function ( state ) {
        OO.ui.OutlineOptionWidget.parent.prototype.setSelected.call( this, state );
-       if ( this.selected ) {
-               this.setFlags( { progressive: true } );
-       } else {
-               this.setFlags( { progressive: false } );
-       }
        return this;
 };
 
@@ -4606,10 +4596,18 @@ OO.mixinClass( OO.ui.TagItemWidget, OO.ui.mixin.DraggableElement );
  * Item validity has changed
  */
 
+/**
+ * @event disabled
+ * @param {boolean} isDisabled Item is disabled
+ *
+ * Item disabled state has changed
+ */
+
 /* Methods */
 
 /**
  * @inheritdoc
+ * @fires disabled
  */
 OO.ui.TagItemWidget.prototype.setDisabled = function ( state ) {
        // Parent method
@@ -4618,6 +4616,8 @@ OO.ui.TagItemWidget.prototype.setDisabled = function ( state ) {
        if ( this.closeButton ) {
                this.closeButton.setDisabled( state );
        }
+
+       this.emit( 'disabled', this.isDisabled() );
        return this;
 };
 
@@ -4648,7 +4648,7 @@ OO.ui.TagItemWidget.prototype.remove = function () {
 OO.ui.TagItemWidget.prototype.onKeyDown = function ( e ) {
        var movement;
 
-       if ( e.keyCode === OO.ui.Keys.BACKSPACE || e.keyCode === OO.ui.Keys.DELETE ) {
+       if ( !this.isDisabled() && e.keyCode === OO.ui.Keys.BACKSPACE || e.keyCode === OO.ui.Keys.DELETE ) {
                this.remove();
                return false;
        } else if ( e.keyCode === OO.ui.Keys.ENTER ) {
@@ -4675,6 +4675,7 @@ OO.ui.TagItemWidget.prototype.onKeyDown = function ( e ) {
                        e.keyCode === OO.ui.Keys.LEFT ?
                                movement.left : movement.right
                );
+               return false;
        }
 };
 
@@ -4823,11 +4824,13 @@ OO.ui.TagMultiselectWidget = function OoUiTagMultiselectWidget( config ) {
        this.aggregate( {
                remove: 'itemRemove',
                navigate: 'itemNavigate',
-               select: 'itemSelect'
+               select: 'itemSelect',
+               disabled: 'itemDisabled'
        } );
        this.connect( this, {
                itemRemove: 'onTagRemove',
                itemSelect: 'onTagSelect',
+               itemDisabled: 'onTagDisabled',
                itemNavigate: 'onTagNavigate',
                change: 'onChangeTags'
        } );
@@ -4979,7 +4982,22 @@ OO.ui.TagMultiselectWidget.prototype.onInputKeyPress = function ( e ) {
  */
 OO.ui.TagMultiselectWidget.prototype.onInputKeyDown = function ( e ) {
        var movement, direction,
-               withMetaKey = e.metaKey || e.ctrlKey;
+               widget = this,
+               withMetaKey = e.metaKey || e.ctrlKey,
+               isMovementInsideInput = function ( direction ) {
+                       var inputRange = widget.input.getRange(),
+                               inputValue = widget.hasInput && widget.input.getValue();
+
+                       if ( direction === 'forwards' && inputRange.to > inputValue.length - 1 ) {
+                               return false;
+                       }
+
+                       if ( direction === 'backwards' && inputRange.from <= 0 ) {
+                               return false;
+                       }
+
+                       return true;
+               };
 
        if ( !this.isDisabled() ) {
                // 'keypress' event is not triggered for Backspace
@@ -5005,7 +5023,9 @@ OO.ui.TagMultiselectWidget.prototype.onInputKeyDown = function ( e ) {
                        direction = e.keyCode === OO.ui.Keys.LEFT ?
                                movement.left : movement.right;
 
-                       return this.doInputArrow( e, direction, withMetaKey );
+                       if ( !this.hasInput || !isMovementInsideInput( direction ) ) {
+                               return this.doInputArrow( e, direction, withMetaKey );
+                       }
                }
        }
 };
@@ -5056,11 +5076,14 @@ OO.ui.TagMultiselectWidget.prototype.doInputBackspace = function ( e, withMetaKe
                // Delete the last item
                items = this.getItems();
                item = items[ items.length - 1 ];
-               this.removeItems( [ item ] );
-               // If Ctrl/Cmd was pressed, delete item entirely.
-               // Otherwise put it into the text field for editing.
-               if ( !withMetaKey ) {
-                       this.input.setValue( item.getData() );
+
+               if ( !item.isDisabled() ) {
+                       this.removeItems( [ item ] );
+                       // If Ctrl/Cmd was pressed, delete item entirely.
+                       // Otherwise put it into the text field for editing.
+                       if ( !withMetaKey ) {
+                               this.input.setValue( item.getData() );
+                       }
                }
 
                return false;
@@ -5078,8 +5101,8 @@ OO.ui.TagMultiselectWidget.prototype.doInputEscape = function () {
 
 /**
  * Perform an action after the arrow key on the input, select the previous
- * or next item from the input.
- * See #getPreviousItem and #getNextItem
+ * item from the input.
+ * See #getPreviousItem
  *
  * @param {jQuery.Event} e Event data
  * @param {string} direction Direction of the movement; forwards or backwards
@@ -5089,15 +5112,11 @@ OO.ui.TagMultiselectWidget.prototype.doInputEscape = function () {
 OO.ui.TagMultiselectWidget.prototype.doInputArrow = function ( e, direction ) {
        if (
                this.inputPosition === 'inline' &&
-               !this.isEmpty()
+               !this.isEmpty() &&
+               direction === 'backwards'
        ) {
-               if ( direction === 'backwards' ) {
-                       // Get previous item
-                       this.getPreviousItem().focus();
-               } else {
-                       // Get next item
-                       this.getNextItem().focus();
-               }
+               // Get previous item
+               this.getPreviousItem().focus();
        }
 };
 
@@ -5120,6 +5139,18 @@ OO.ui.TagMultiselectWidget.prototype.onTagSelect = function ( item ) {
        }
 };
 
+/**
+ * Respond to item disabled state change
+ *
+ * @param {OO.ui.TagItemWidget} item Selected item
+ * @param {boolean} isDisabled Item is disabled
+ */
+OO.ui.TagMultiselectWidget.prototype.onTagDisabled = function ( item, isDisabled ) {
+       if ( isDisabled ) {
+       // Move item to start if it is disabled
+               this.addItems( item, 0 );
+       }
+};
 /**
  * Respond to change event, where items were added, removed, or cleared.
  */
@@ -5164,9 +5195,13 @@ OO.ui.TagMultiselectWidget.prototype.onTagRemove = function ( item ) {
  * @param {string} direction Direction of movement; 'forwards' or 'backwards'
  */
 OO.ui.TagMultiselectWidget.prototype.onTagNavigate = function ( item, direction ) {
+       var firstItem = this.getItems()[ 0 ];
+
        if ( direction === 'forwards' ) {
                this.getNextItem( item ).focus();
-       } else {
+       } else if ( !this.inputPosition === 'inline' || item !== firstItem ) {
+               // If the widget has an inline input, we want to stop at the starting edge
+               // of the tags
                this.getPreviousItem( item ).focus();
        }
 };
@@ -5581,6 +5616,7 @@ OO.ui.PopupTagMultiselectWidget = function OoUiPopupTagMultiselectWidget( config
 
                defaultConfig.popupInput = defaultInput;
                defaultConfig.popup.$content = defaultInput.$element;
+               defaultConfig.popup.padded = true;
 
                this.$element.addClass( 'oo-ui-popupTagMultiselectWidget-defaultPopup' );
        }
@@ -5859,6 +5895,10 @@ OO.ui.MenuTagMultiselectWidget.prototype.addTagFromInput = function () {
                highlightedItem = this.menu.findHighlightedItem(),
                item = this.menu.findItemFromData( inputValue );
 
+       if ( !inputValue ) {
+               return;
+       }
+
        // Override the parent method so we add from the menu
        // rather than directly from the input