/*!
- * 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 ) {
// 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.
}
*/
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;
};
*/
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;
};
* 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
if ( this.closeButton ) {
this.closeButton.setDisabled( state );
}
+
+ this.emit( 'disabled', this.isDisabled() );
return this;
};
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 ) {
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'
} );
* @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;
}
// 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;
}
};
+/**
+ * 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.
*/
*
* @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>.
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,
*/
OO.ui.MenuTagMultiselectWidget.prototype.onInputChange = function () {
this.menu.toggle( true );
+ this.initializeMenuSelection();
};
/**
OO.ui.MenuTagMultiselectWidget.prototype.onMenuChoose = function ( menuItem ) {
// Add tag
this.addTag( menuItem.getData(), menuItem.getLabel() );
+ if ( this.hasInput && this.clearInputOnChoose ) {
+ this.input.setValue( '' );
+ }
};
/**
if ( !isVisible ) {
this.menu.selectItem( null );
this.menu.highlightItem( null );
+ } else {
+ this.initializeMenuSelection();
}
};
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
*/
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