Update OOUI to v0.26.1
[lhc/web/wiklou.git] / resources / lib / oojs-ui / oojs-ui-widgets.js
index 4bb5a44..851ab78 100644 (file)
@@ -1,12 +1,12 @@
 /*!
- * OOUI v0.25.1
+ * OOUI v0.26.1
  * 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-01-17T01:47:15Z
+ * Date: 2018-03-23T23:42:32Z
  */
 ( function ( OO ) {
 
@@ -154,7 +154,7 @@ OO.ui.mixin.DraggableElement.prototype.onDragStart = function ( e ) {
        // We must set up a dataTransfer data property or Firefox seems to
        // ignore the fact the element is draggable.
        try {
-               dataTransfer.setData( 'application-x/OOjs-UI-draggable', this.getIndex() );
+               dataTransfer.setData( 'application-x/OOUI-draggable', this.getIndex() );
        } catch ( err ) {
                // The above is only for Firefox. Move on if it fails.
        }
@@ -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 ) {
@@ -4823,11 +4823,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'
        } );
@@ -4938,7 +4940,11 @@ OO.ui.TagMultiselectWidget.static.allowedInputPositions = [ 'inline', 'outline',
  * @return {boolean} False to prevent defaults
  */
 OO.ui.TagMultiselectWidget.prototype.onMouseDown = function ( e ) {
-       if ( !this.isDisabled() && e.which === OO.ui.MouseButtons.LEFT ) {
+       if (
+               !this.isDisabled() &&
+               ( !this.hasInput || e.target !== this.input.$input[ 0 ] ) &&
+               e.which === OO.ui.MouseButtons.LEFT
+       ) {
                this.focus();
                return false;
        }
@@ -5052,11 +5058,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;
@@ -5116,6 +5125,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.
  */
@@ -5704,6 +5725,7 @@ OO.ui.PopupTagMultiselectWidget.prototype.addTagByPopupValue = function ( data,
  *
  * @constructor
  * @param {Object} [config] Configuration object
+ * @cfg {boolean} [clearInputOnChoose=true] Clear the text input value when a menu option is chosen
  * @cfg {Object} [menu] Configuration object for the menu widget
  * @cfg {jQuery} [$overlay] An overlay for the menu.
  *  See <https://www.mediawiki.org/wiki/OOUI/Concepts#Overlays>.
@@ -5716,7 +5738,7 @@ OO.ui.MenuTagMultiselectWidget = function OoUiMenuTagMultiselectWidget( config )
        OO.ui.MenuTagMultiselectWidget.parent.call( this, config );
 
        this.$overlay = ( config.$overlay === true ? OO.ui.getDefaultOverlay() : config.$overlay ) || this.$element;
-
+       this.clearInputOnChoose = config.clearInputOnChoose === undefined || !!config.clearInputOnChoose;
        this.menu = this.createMenuWidget( $.extend( {
                widget: this,
                input: this.hasInput ? this.input : null,
@@ -5782,6 +5804,7 @@ OO.ui.MenuTagMultiselectWidget.prototype.onInputFocus = function () {
  */
 OO.ui.MenuTagMultiselectWidget.prototype.onInputChange = function () {
        this.menu.toggle( true );
+       this.initializeMenuSelection();
 };
 
 /**
@@ -5792,6 +5815,9 @@ OO.ui.MenuTagMultiselectWidget.prototype.onInputChange = function () {
 OO.ui.MenuTagMultiselectWidget.prototype.onMenuChoose = function ( menuItem ) {
        // Add tag
        this.addTag( menuItem.getData(), menuItem.getLabel() );
+       if ( this.hasInput && this.clearInputOnChoose ) {
+               this.input.setValue( '' );
+       }
 };
 
 /**
@@ -5803,6 +5829,8 @@ OO.ui.MenuTagMultiselectWidget.prototype.onMenuToggle = function ( isVisible ) {
        if ( !isVisible ) {
                this.menu.selectItem( null );
                this.menu.highlightItem( null );
+       } else {
+               this.initializeMenuSelection();
        }
 };
 
@@ -5827,6 +5855,18 @@ OO.ui.MenuTagMultiselectWidget.prototype.onTagSelect = function ( tagItem ) {
        this.focus();
 };
 
+/**
+ * Highlight the first selectable item in the menu, if configured.
+ *
+ * @private
+ * @chainable
+ */
+OO.ui.MenuTagMultiselectWidget.prototype.initializeMenuSelection = function () {
+       if ( !this.menu.findSelectedItem() ) {
+               this.menu.highlightItem( this.menu.findFirstSelectableItem() );
+       }
+};
+
 /**
  * @inheritdoc
  */
@@ -5836,6 +5876,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