/*!
- * OOjs UI v0.17.8
+ * OOjs UI v0.18.0
* 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-16T21:13:48Z
+ * Date: 2016-11-09T00:52:37Z
*/
( function ( OO ) {
* 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 =
* 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 ) {
* 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 ) {
* 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 ) {
* };
*
* var card1 = new CardOneLayout( 'one' ),
- * card2 = new CardLayout( 'two', { label: 'Card two' } );
+ * card2 = new OO.ui.CardLayout( 'two', { label: 'Card two' } );
*
* card2.$element.append( '<p>Second card</p>' );
*
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 );
/* Static Properties */
-OO.ui.OutlineOptionWidget.static.highlightable = false;
+OO.ui.OutlineOptionWidget.static.highlightable = true;
OO.ui.OutlineOptionWidget.static.scrollIntoViewOnSelect = true;
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.
*
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.
*
/**
* 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();
*
* @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}.
}, config );
// Properties (must be set before mixin constructor calls)
- this.$input = config.popup ? null : $( '<input>' );
this.$handle = $( '<div>' );
+ this.$input = config.popup ? null : $( '<input>' );
+ if ( config.placeholder !== undefined && config.placeholder !== '' ) {
+ this.$input.attr( 'placeholder', config.placeholder );
+ }
// Mixin constructors
OO.ui.mixin.GroupElement.call( this, config );
}
this.menu.connect( this, {
choose: 'onMenuChoose',
+ toggle: 'onMenuToggle',
add: 'onMenuItemsChange',
remove: 'onMenuItemsChange'
} );
role: 'combobox',
'aria-autocomplete': 'list'
} );
- this.updateInputSize();
}
if ( config.data ) {
this.setItemsFromData( config.data );
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();
};
* @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 ] );
};
*/
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 ) {
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;
}
};
+/**
+ * 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.
*
.addClass( 'oo-ui-selectFileWidget-fileName' )
.text( this.currentFile.name )
);
- if ( this.currentFile.type !== '' ) {
- $label = $label.add(
- $( '<span>' )
- .addClass( 'oo-ui-selectFileWidget-fileType' )
- .text( this.currentFile.type )
- );
- }
this.setLabel( $label );
if ( this.showDropTarget ) {
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;