/*!
- * 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 ) {
*/
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 ) {
e.keyCode === OO.ui.Keys.LEFT ?
movement.left : movement.right
);
+ return false;
}
};
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'
} );
*/
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
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 );
+ }
}
}
};
// 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;
/**
* 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
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();
}
};
}
};
+/**
+ * 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.
*/
* @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();
}
};
defaultConfig.popupInput = defaultInput;
defaultConfig.popup.$content = defaultInput.$element;
+ defaultConfig.popup.padded = true;
this.$element.addClass( 'oo-ui-popupTagMultiselectWidget-defaultPopup' );
}
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