/*!
- * OOUI v0.28.1
+ * OOUI v0.29.2
* 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-09-05T00:41:49Z
+ * Date: 2018-10-08T22:42:55Z
*/
( function ( OO ) {
// Initialization
if ( Array.isArray( config.classes ) ) {
- this.$element.addClass( config.classes.join( ' ' ) );
+ this.$element.addClass( config.classes );
}
if ( config.id ) {
this.setElementId( config.id );
}
$elements
- .removeClass( classes.off.join( ' ' ) )
- .addClass( classes.on.join( ' ' ) );
+ .removeClass( classes.off )
+ .addClass( classes.on );
};
/**
this.$button = null;
this.framed = null;
this.active = config.active !== undefined && config.active;
- this.onMouseUpHandler = this.onMouseUp.bind( this );
+ this.onDocumentMouseUpHandler = this.onDocumentMouseUp.bind( this );
this.onMouseDownHandler = this.onMouseDown.bind( this );
+ this.onDocumentKeyUpHandler = this.onDocumentKeyUp.bind( this );
this.onKeyDownHandler = this.onKeyDown.bind( this );
- this.onKeyUpHandler = this.onKeyUp.bind( this );
this.onClickHandler = this.onClick.bind( this );
this.onKeyPressHandler = this.onKeyPress.bind( this );
this.$element.addClass( 'oo-ui-buttonElement-pressed' );
// Run the mouseup handler no matter where the mouse is when the button is let go, so we can
// reliably remove the pressed class
- this.getElementDocument().addEventListener( 'mouseup', this.onMouseUpHandler, true );
+ this.getElementDocument().addEventListener( 'mouseup', this.onDocumentMouseUpHandler, true );
// Prevent change of focus unless specifically configured otherwise
if ( this.constructor.static.cancelButtonMouseDownEvents ) {
return false;
};
/**
- * Handles mouse up events.
+ * Handles document mouse up events.
*
* @protected
* @param {MouseEvent} e Mouse up event
*/
-OO.ui.mixin.ButtonElement.prototype.onMouseUp = function ( e ) {
+OO.ui.mixin.ButtonElement.prototype.onDocumentMouseUp = function ( e ) {
if ( this.isDisabled() || e.which !== OO.ui.MouseButtons.LEFT ) {
return;
}
this.$element.removeClass( 'oo-ui-buttonElement-pressed' );
// Stop listening for mouseup, since we only needed this once
- this.getElementDocument().removeEventListener( 'mouseup', this.onMouseUpHandler, true );
+ this.getElementDocument().removeEventListener( 'mouseup', this.onDocumentMouseUpHandler, true );
+};
+
+// Deprecated alias since 0.28.3
+OO.ui.mixin.ButtonElement.prototype.onMouseUp = function () {
+ OO.ui.warnDeprecation( 'onMouseUp is deprecated, use onDocumentMouseUp instead' );
+ this.onDocumentMouseUp.apply( this, arguments );
};
/**
this.$element.addClass( 'oo-ui-buttonElement-pressed' );
// Run the keyup handler no matter where the key is when the button is let go, so we can
// reliably remove the pressed class
- this.getElementDocument().addEventListener( 'keyup', this.onKeyUpHandler, true );
+ this.getElementDocument().addEventListener( 'keyup', this.onDocumentKeyUpHandler, true );
};
/**
- * Handles key up events.
+ * Handles document key up events.
*
* @protected
* @param {KeyboardEvent} e Key up event
*/
-OO.ui.mixin.ButtonElement.prototype.onKeyUp = function ( e ) {
+OO.ui.mixin.ButtonElement.prototype.onDocumentKeyUp = function ( e ) {
if ( this.isDisabled() || ( e.which !== OO.ui.Keys.SPACE && e.which !== OO.ui.Keys.ENTER ) ) {
return;
}
this.$element.removeClass( 'oo-ui-buttonElement-pressed' );
// Stop listening for keyup, since we only needed this once
- this.getElementDocument().removeEventListener( 'keyup', this.onKeyUpHandler, true );
+ this.getElementDocument().removeEventListener( 'keyup', this.onDocumentKeyUpHandler, true );
+};
+
+// Deprecated alias since 0.28.3
+OO.ui.mixin.ButtonElement.prototype.onKeyUp = function () {
+ OO.ui.warnDeprecation( 'onKeyUp is deprecated, use onDocumentKeyUp instead' );
+ this.onDocumentKeyUp.apply( this, arguments );
};
/**
OO.ui.mixin.FlaggedElement.prototype.setFlaggedElement = function ( $flagged ) {
var classNames = Object.keys( this.flags ).map( function ( flag ) {
return 'oo-ui-flaggedElement-' + flag;
- } ).join( ' ' );
+ } );
if ( this.$flagged ) {
this.$flagged.removeClass( classNames );
}
if ( this.$flagged ) {
- this.$flagged.removeClass( remove.join( ' ' ) );
+ this.$flagged.removeClass( remove );
}
this.updateThemeClasses();
if ( this.$flagged ) {
this.$flagged
- .addClass( add.join( ' ' ) )
- .removeClass( remove.join( ' ' ) );
+ .addClass( add )
+ .removeClass( remove );
}
this.updateThemeClasses();
this.autoClose = !!config.autoClose;
this.transitionTimeout = null;
this.anchored = false;
- this.onMouseDownHandler = this.onMouseDown.bind( this );
+ this.onDocumentMouseDownHandler = this.onDocumentMouseDown.bind( this );
this.onDocumentKeyDownHandler = this.onDocumentKeyDown.bind( this );
// Initialization
/* Methods */
/**
- * Handles mouse down events.
+ * Handles document mouse down events.
*
* @private
* @param {MouseEvent} e Mouse down event
*/
-OO.ui.PopupWidget.prototype.onMouseDown = function ( e ) {
+OO.ui.PopupWidget.prototype.onDocumentMouseDown = function ( e ) {
if (
this.isVisible() &&
!OO.ui.contains( this.$element.add( this.$autoCloseIgnore ).get(), e.target, true )
}
};
+// Deprecated alias since 0.28.3
+OO.ui.PopupWidget.prototype.onMouseDown = function () {
+ OO.ui.warnDeprecation( 'onMouseDown is deprecated, use onDocumentMouseDown instead' );
+ this.onDocumentMouseDown.apply( this, arguments );
+};
+
/**
- * Bind mouse down listener.
+ * Bind document mouse down listener.
*
* @private
*/
-OO.ui.PopupWidget.prototype.bindMouseDownListener = function () {
+OO.ui.PopupWidget.prototype.bindDocumentMouseDownListener = function () {
// Capture clicks outside popup
- this.getElementWindow().addEventListener( 'mousedown', this.onMouseDownHandler, true );
+ this.getElementDocument().addEventListener( 'mousedown', this.onDocumentMouseDownHandler, true );
// We add 'click' event because iOS safari needs to respond to this event.
// We can't use 'touchstart' (as is usually the equivalent to 'mousedown') because
// then it will trigger when scrolling. While iOS Safari has some reported behavior
// of occasionally not emitting 'click' properly, that event seems to be the standard
// that it should be emitting, so we add it to this and will operate the event handler
// on whichever of these events was triggered first
- this.getElementDocument().addEventListener( 'click', this.onMouseDownHandler, true );
+ this.getElementDocument().addEventListener( 'click', this.onDocumentMouseDownHandler, true );
+};
+
+// Deprecated alias since 0.28.3
+OO.ui.PopupWidget.prototype.bindMouseDownListener = function () {
+ OO.ui.warnDeprecation( 'bindMouseDownListener is deprecated, use bindDocumentMouseDownListener instead' );
+ this.bindDocumentMouseDownListener.apply( this, arguments );
};
/**
};
/**
- * Unbind mouse down listener.
+ * Unbind document mouse down listener.
*
* @private
*/
+OO.ui.PopupWidget.prototype.unbindDocumentMouseDownListener = function () {
+ this.getElementDocument().removeEventListener( 'mousedown', this.onDocumentMouseDownHandler, true );
+ this.getElementDocument().removeEventListener( 'click', this.onDocumentMouseDownHandler, true );
+};
+
+// Deprecated alias since 0.28.3
OO.ui.PopupWidget.prototype.unbindMouseDownListener = function () {
- this.getElementWindow().removeEventListener( 'mousedown', this.onMouseDownHandler, true );
- this.getElementDocument().removeEventListener( 'click', this.onMouseDownHandler, true );
+ OO.ui.warnDeprecation( 'unbindMouseDownListener is deprecated, use unbindDocumentMouseDownListener instead' );
+ this.unbindDocumentMouseDownListener.apply( this, arguments );
};
/**
- * Handles key down events.
+ * Handles document key down events.
*
* @private
* @param {KeyboardEvent} e Key down event
};
/**
- * Bind key down listener.
+ * Bind document key down listener.
*
* @private
*/
+OO.ui.PopupWidget.prototype.bindDocumentKeyDownListener = function () {
+ this.getElementDocument().addEventListener( 'keydown', this.onDocumentKeyDownHandler, true );
+};
+
+// Deprecated alias since 0.28.3
OO.ui.PopupWidget.prototype.bindKeyDownListener = function () {
- this.getElementWindow().addEventListener( 'keydown', this.onDocumentKeyDownHandler, true );
+ OO.ui.warnDeprecation( 'bindKeyDownListener is deprecated, use bindDocumentKeyDownListener instead' );
+ this.bindDocumentKeyDownListener.apply( this, arguments );
};
/**
- * Unbind key down listener.
+ * Unbind document key down listener.
*
* @private
*/
+OO.ui.PopupWidget.prototype.unbindDocumentKeyDownListener = function () {
+ this.getElementDocument().removeEventListener( 'keydown', this.onDocumentKeyDownHandler, true );
+};
+
+// Deprecated alias since 0.28.3
OO.ui.PopupWidget.prototype.unbindKeyDownListener = function () {
- this.getElementWindow().removeEventListener( 'keydown', this.onDocumentKeyDownHandler, true );
+ OO.ui.warnDeprecation( 'unbindKeyDownListener is deprecated, use unbindDocumentKeyDownListener instead' );
+ this.unbindDocumentKeyDownListener.apply( this, arguments );
};
/**
if ( show ) {
if ( this.autoClose ) {
- this.bindMouseDownListener();
- this.bindKeyDownListener();
+ this.bindDocumentMouseDownListener();
+ this.bindDocumentKeyDownListener();
}
this.updateDimensions();
this.toggleClipping( true );
} else {
this.toggleClipping( false );
if ( this.autoClose ) {
- this.unbindMouseDownListener();
- this.unbindKeyDownListener();
+ this.unbindDocumentMouseDownListener();
+ this.unbindDocumentKeyDownListener();
}
}
}
// Properties
this.pressed = false;
this.selecting = null;
- this.onMouseUpHandler = this.onMouseUp.bind( this );
- this.onMouseMoveHandler = this.onMouseMove.bind( this );
- this.onKeyDownHandler = this.onKeyDown.bind( this );
- this.onKeyPressHandler = this.onKeyPress.bind( this );
+ this.onDocumentMouseUpHandler = this.onDocumentMouseUp.bind( this );
+ this.onDocumentMouseMoveHandler = this.onDocumentMouseMove.bind( this );
+ this.onDocumentKeyDownHandler = this.onDocumentKeyDown.bind( this );
+ this.onDocumentKeyPressHandler = this.onDocumentKeyPress.bind( this );
this.keyPressBuffer = '';
this.keyPressBufferTimer = null;
this.blockMouseOverEvents = 0;
if ( item && item.isSelectable() ) {
this.pressItem( item );
this.selecting = item;
- this.getElementDocument().addEventListener( 'mouseup', this.onMouseUpHandler, true );
- this.getElementDocument().addEventListener( 'mousemove', this.onMouseMoveHandler, true );
+ this.getElementDocument().addEventListener( 'mouseup', this.onDocumentMouseUpHandler, true );
+ this.getElementDocument().addEventListener( 'mousemove', this.onDocumentMouseMoveHandler, true );
}
}
return false;
};
/**
- * Handle mouse up events.
+ * Handle document mouse up events.
*
* @private
* @param {MouseEvent} e Mouse up event
*/
-OO.ui.SelectWidget.prototype.onMouseUp = function ( e ) {
+OO.ui.SelectWidget.prototype.onDocumentMouseUp = function ( e ) {
var item;
this.togglePressed( false );
this.selecting = null;
}
- this.getElementDocument().removeEventListener( 'mouseup', this.onMouseUpHandler, true );
- this.getElementDocument().removeEventListener( 'mousemove', this.onMouseMoveHandler, true );
+ this.getElementDocument().removeEventListener( 'mouseup', this.onDocumentMouseUpHandler, true );
+ this.getElementDocument().removeEventListener( 'mousemove', this.onDocumentMouseMoveHandler, true );
return false;
};
+// Deprecated alias since 0.28.3
+OO.ui.SelectWidget.prototype.onMouseUp = function () {
+ OO.ui.warnDeprecation( 'onMouseUp is deprecated, use onDocumentMouseUp instead' );
+ this.onDocumentMouseUp.apply( this, arguments );
+};
+
/**
- * Handle mouse move events.
+ * Handle document mouse move events.
*
* @private
* @param {MouseEvent} e Mouse move event
*/
-OO.ui.SelectWidget.prototype.onMouseMove = function ( e ) {
+OO.ui.SelectWidget.prototype.onDocumentMouseMove = function ( e ) {
var item;
if ( !this.isDisabled() && this.pressed ) {
}
};
+// Deprecated alias since 0.28.3
+OO.ui.SelectWidget.prototype.onMouseMove = function () {
+ OO.ui.warnDeprecation( 'onMouseMove is deprecated, use onDocumentMouseMove instead' );
+ this.onDocumentMouseMove.apply( this, arguments );
+};
+
/**
* Handle mouse over events.
*
};
/**
- * Handle key down events.
+ * Handle document key down events.
*
* @protected
* @param {KeyboardEvent} e Key down event
*/
-OO.ui.SelectWidget.prototype.onKeyDown = function ( e ) {
+OO.ui.SelectWidget.prototype.onDocumentKeyDown = function ( e ) {
var nextItem,
handled = false,
currentItem = this.findHighlightedItem() || this.findSelectedItem();
if ( currentItem && currentItem.constructor.static.highlightable ) {
currentItem.setHighlighted( false );
}
- this.unbindKeyDownListener();
- this.unbindKeyPressListener();
+ this.unbindDocumentKeyDownListener();
+ this.unbindDocumentKeyPressListener();
// Don't prevent tabbing away / defocusing
handled = false;
break;
}
};
+// Deprecated alias since 0.28.3
+OO.ui.SelectWidget.prototype.onKeyDown = function () {
+ OO.ui.warnDeprecation( 'onKeyDown is deprecated, use onDocumentKeyDown instead' );
+ this.onDocumentKeyDown.apply( this, arguments );
+};
+
/**
- * Bind key down listener.
+ * Bind document key down listener.
*
* @protected
*/
+OO.ui.SelectWidget.prototype.bindDocumentKeyDownListener = function () {
+ this.getElementDocument().addEventListener( 'keydown', this.onDocumentKeyDownHandler, true );
+};
+
+// Deprecated alias since 0.28.3
OO.ui.SelectWidget.prototype.bindKeyDownListener = function () {
- this.getElementWindow().addEventListener( 'keydown', this.onKeyDownHandler, true );
+ OO.ui.warnDeprecation( 'bindKeyDownListener is deprecated, use bindDocumentKeyDownListener instead' );
+ this.bindDocumentKeyDownListener.apply( this, arguments );
};
/**
- * Unbind key down listener.
+ * Unbind document key down listener.
*
* @protected
*/
+OO.ui.SelectWidget.prototype.unbindDocumentKeyDownListener = function () {
+ this.getElementDocument().removeEventListener( 'keydown', this.onDocumentKeyDownHandler, true );
+};
+
+// Deprecated alias since 0.28.3
OO.ui.SelectWidget.prototype.unbindKeyDownListener = function () {
- this.getElementWindow().removeEventListener( 'keydown', this.onKeyDownHandler, true );
+ OO.ui.warnDeprecation( 'unbindKeyDownListener is deprecated, use unbindDocumentKeyDownListener instead' );
+ this.unbindDocumentKeyDownListener.apply( this, arguments );
};
/**
* @protected
* @param {KeyboardEvent} e Key press event
*/
-OO.ui.SelectWidget.prototype.onKeyPress = function ( e ) {
+OO.ui.SelectWidget.prototype.onDocumentKeyPress = function ( e ) {
var c, filter, item;
if ( !e.charCode ) {
e.stopPropagation();
};
+// Deprecated alias since 0.28.3
+OO.ui.SelectWidget.prototype.onKeyPress = function () {
+ OO.ui.warnDeprecation( 'onKeyPress is deprecated, use onDocumentKeyPress instead' );
+ this.onDocumentKeyPress.apply( this, arguments );
+};
+
/**
* Get a matcher for the specific string
*
};
/**
- * Bind key press listener.
+ * Bind document key press listener.
*
* @protected
*/
+OO.ui.SelectWidget.prototype.bindDocumentKeyPressListener = function () {
+ this.getElementDocument().addEventListener( 'keypress', this.onDocumentKeyPressHandler, true );
+};
+
+// Deprecated alias since 0.28.3
OO.ui.SelectWidget.prototype.bindKeyPressListener = function () {
- this.getElementWindow().addEventListener( 'keypress', this.onKeyPressHandler, true );
+ OO.ui.warnDeprecation( 'bindKeyPressListener is deprecated, use bindDocumentKeyPressListener instead' );
+ this.bindDocumentKeyPressListener.apply( this, arguments );
};
/**
- * Unbind key down listener.
+ * Unbind document key down listener.
*
* If you override this, be sure to call this.clearKeyPressBuffer() from your
* implementation.
*
* @protected
*/
-OO.ui.SelectWidget.prototype.unbindKeyPressListener = function () {
- this.getElementWindow().removeEventListener( 'keypress', this.onKeyPressHandler, true );
+OO.ui.SelectWidget.prototype.unbindDocumentKeyPressListener = function () {
+ this.getElementDocument().removeEventListener( 'keypress', this.onDocumentKeyPressHandler, true );
this.clearKeyPressBuffer();
};
+// Deprecated alias since 0.28.3
+OO.ui.SelectWidget.prototype.unbindKeyPressListener = function () {
+ OO.ui.warnDeprecation( 'unbindDocumentKeyPressListener is deprecated, use unbindDocumentKeyPressListener instead' );
+ this.unbindDocumentKeyPressListener.apply( this, arguments );
+};
+
/**
* Visibility change handler
*
* the text the user types. This config is used by {@link OO.ui.ComboBoxInputWidget ComboBoxInputWidget}
* and {@link OO.ui.mixin.LookupElement LookupElement}
* @cfg {jQuery} [$input] Text input used to implement option highlighting for menu items that match
- * the text the user types. This config is used by {@link OO.ui.CapsuleMultiselectWidget CapsuleMultiselectWidget}
+ * the text the user types. This config is used by {@link OO.ui.TagMultiselectWidget TagMultiselectWidget}
* @cfg {OO.ui.Widget} [widget] Widget associated with the menu's active state. If the user clicks the mouse
* anywhere on the page outside of this widget, the menu is hidden. For example, if there is a button
* that toggles the menu's visibility on click, the menu will be hidden then re-shown when the user clicks
/**
* @inheritdoc
*/
-OO.ui.MenuSelectWidget.prototype.onKeyDown = function ( e ) {
+OO.ui.MenuSelectWidget.prototype.onDocumentKeyDown = function ( e ) {
var currentItem = this.findHighlightedItem() || this.findSelectedItem();
if ( !this.isDisabled() && this.isVisible() ) {
case OO.ui.Keys.RIGHT:
// Do nothing if a text field is associated, arrow keys will be handled natively
if ( !this.$input ) {
- OO.ui.MenuSelectWidget.parent.prototype.onKeyDown.call( this, e );
+ OO.ui.MenuSelectWidget.parent.prototype.onDocumentKeyDown.call( this, e );
}
break;
case OO.ui.Keys.ESCAPE:
}
break;
default:
- OO.ui.MenuSelectWidget.parent.prototype.onKeyDown.call( this, e );
+ OO.ui.MenuSelectWidget.parent.prototype.onDocumentKeyDown.call( this, e );
return;
}
}
/**
* @inheritdoc
*/
-OO.ui.MenuSelectWidget.prototype.bindKeyDownListener = function () {
+OO.ui.MenuSelectWidget.prototype.bindDocumentKeyDownListener = function () {
if ( this.$input ) {
- this.$input.on( 'keydown', this.onKeyDownHandler );
+ this.$input.on( 'keydown', this.onDocumentKeyDownHandler );
} else {
- OO.ui.MenuSelectWidget.parent.prototype.bindKeyDownListener.call( this );
+ OO.ui.MenuSelectWidget.parent.prototype.bindDocumentKeyDownListener.call( this );
}
};
/**
* @inheritdoc
*/
-OO.ui.MenuSelectWidget.prototype.unbindKeyDownListener = function () {
+OO.ui.MenuSelectWidget.prototype.unbindDocumentKeyDownListener = function () {
if ( this.$input ) {
- this.$input.off( 'keydown', this.onKeyDownHandler );
+ this.$input.off( 'keydown', this.onDocumentKeyDownHandler );
} else {
- OO.ui.MenuSelectWidget.parent.prototype.unbindKeyDownListener.call( this );
+ OO.ui.MenuSelectWidget.parent.prototype.unbindDocumentKeyDownListener.call( this );
}
};
/**
* @inheritdoc
*/
-OO.ui.MenuSelectWidget.prototype.bindKeyPressListener = function () {
+OO.ui.MenuSelectWidget.prototype.bindDocumentKeyPressListener = function () {
if ( this.$input ) {
if ( this.filterFromInput ) {
this.$input.on( 'keydown mouseup cut paste change input select', this.onInputEditHandler );
this.updateItemVisibility();
}
} else {
- OO.ui.MenuSelectWidget.parent.prototype.bindKeyPressListener.call( this );
+ OO.ui.MenuSelectWidget.parent.prototype.bindDocumentKeyPressListener.call( this );
}
};
/**
* @inheritdoc
*/
-OO.ui.MenuSelectWidget.prototype.unbindKeyPressListener = function () {
+OO.ui.MenuSelectWidget.prototype.unbindDocumentKeyPressListener = function () {
if ( this.$input ) {
if ( this.filterFromInput ) {
this.$input.off( 'keydown mouseup cut paste change input select', this.onInputEditHandler );
this.updateItemVisibility();
}
} else {
- OO.ui.MenuSelectWidget.parent.prototype.unbindKeyPressListener.call( this );
+ OO.ui.MenuSelectWidget.parent.prototype.unbindDocumentKeyPressListener.call( this );
}
};
this.togglePositioning( !!this.$floatableContainer );
this.toggleClipping( true );
- this.bindKeyDownListener();
- this.bindKeyPressListener();
+ this.bindDocumentKeyDownListener();
+ this.bindDocumentKeyPressListener();
if (
( this.isClippedVertically() || this.isFloatableOutOfView() ) &&
this.emit( 'ready' );
} else {
this.$focusOwner.removeAttr( 'aria-activedescendant' );
- this.unbindKeyDownListener();
- this.unbindKeyPressListener();
+ this.unbindDocumentKeyDownListener();
+ this.unbindDocumentKeyPressListener();
this.$focusOwner.attr( 'aria-expanded', 'false' );
this.getElementDocument().removeEventListener( 'mousedown', this.onDocumentMouseDownHandler, true );
this.togglePositioning( false );
// Events
this.$element.on( {
- focus: this.bindKeyDownListener.bind( this ),
- blur: this.unbindKeyDownListener.bind( this )
+ focus: this.bindDocumentKeyDownListener.bind( this ),
+ blur: this.unbindDocumentKeyDownListener.bind( this )
} );
// Initialization
// Events
this.aggregate( { change: 'select' } );
- // This is mostly for compatibility with CapsuleMultiselectWidget... normally, 'change' is emitted
+ // This is mostly for compatibility with TagMultiselectWidget... normally, 'change' is emitted
// by GroupElement only when items are added/removed
this.connect( this, { select: [ 'emit', 'change' ] } );
labelPosition: 'after'
}, config );
- if ( config.multiline ) {
- OO.ui.warnDeprecation( 'TextInputWidget: config.multiline is deprecated. Use the MultilineTextInputWidget instead. See T130434.' );
- return new OO.ui.MultilineTextInputWidget( config );
- }
-
// Parent constructor
OO.ui.TextInputWidget.parent.call( this, config );
config = $.extend( {
type: 'text'
}, config );
- config.multiline = false;
// Parent constructor
OO.ui.MultilineTextInputWidget.parent.call( this, config );
// Properties
- this.multiline = true;
this.autosize = !!config.autosize;
this.minRows = config.rows !== undefined ? config.rows : '';
this.maxRows = config.maxRows || Math.max( 2 * ( this.minRows || 0 ), 10 );
} );
// Initialization
- if ( this.multiline && config.rows ) {
+ if ( config.rows ) {
this.$input.attr( 'rows', config.rows );
}
if ( this.autosize ) {
return $( '<textarea>' );
};
-/**
- * Check if the input supports multiple lines.
- *
- * @return {boolean}
- */
-OO.ui.MultilineTextInputWidget.prototype.isMultiline = function () {
- return !!this.multiline;
-};
-
/**
* Check if the input automatically adjusts its size.
*
*
* @constructor
* @param {Object} [config] Configuration options
- * @cfg {Object} [minusButton] Configuration options to pass to the {@link OO.ui.ButtonWidget decrementing button widget}.
- * @cfg {Object} [plusButton] Configuration options to pass to the {@link OO.ui.ButtonWidget incrementing button widget}.
- * @cfg {boolean} [allowInteger=false] Whether the field accepts only integer values.
+ * @cfg {Object} [minusButton] Configuration options to pass to the
+ * {@link OO.ui.ButtonWidget decrementing button widget}.
+ * @cfg {Object} [plusButton] Configuration options to pass to the
+ * {@link OO.ui.ButtonWidget incrementing button widget}.
* @cfg {number} [min=-Infinity] Minimum allowed value
* @cfg {number} [max=Infinity] Maximum allowed value
- * @cfg {number} [step=1] Delta when using the buttons or up/down arrow keys
- * @cfg {number|null} [pageStep] Delta when using the page-up/page-down keys. Defaults to 10 times #step.
+ * @cfg {number|null} [step] If specified, the field only accepts values that are multiples of this.
+ * @cfg {number} [buttonStep=step||1] Delta when using the buttons or up/down arrow keys.
+ * Defaults to `step` if specified, otherwise `1`.
+ * @cfg {number} [pageStep=10*buttonStep] Delta when using the page-up/page-down keys.
+ * Defaults to 10 times `buttonStep`.
* @cfg {boolean} [showButtons=true] Whether to show the plus and minus buttons.
*/
OO.ui.NumberInputWidget = function OoUiNumberInputWidget( config ) {
// Configuration initialization
config = $.extend( {
- allowInteger: false,
min: -Infinity,
max: Infinity,
- step: 1,
- pageStep: null,
showButtons: true
}, config );
}
// Initialization
- this.setAllowInteger( config.allowInteger || config.isInteger );
+ if ( config.allowInteger || config.isInteger ) {
+ // Backward compatibility
+ config.step = 1;
+ }
this.setRange( config.min, config.max );
- this.setStep( config.step, config.pageStep );
- // Set the validation method after we set allowInteger and range
+ this.setStep( config.buttonStep, config.pageStep, config.step );
+ // Set the validation method after we set step and range
// so that it doesn't immediately call setValidityFlag
this.setValidation( this.validateNumber.bind( this ) );
/* Methods */
-/**
- * Set whether only integers are allowed
- *
- * @param {boolean} flag
- */
+// Backward compatibility
OO.ui.NumberInputWidget.prototype.setAllowInteger = function ( flag ) {
- this.allowInteger = !!flag;
- this.setValidityFlag();
+ this.setStep( flag ? 1 : null );
};
// Backward compatibility
OO.ui.NumberInputWidget.prototype.setIsInteger = OO.ui.NumberInputWidget.prototype.setAllowInteger;
-/**
- * Get whether only integers are allowed
- *
- * @return {boolean} Flag value
- */
+// Backward compatibility
OO.ui.NumberInputWidget.prototype.getAllowInteger = function () {
- return this.allowInteger;
+ return this.step === 1;
};
// Backward compatibility
OO.ui.NumberInputWidget.prototype.getIsInteger = OO.ui.NumberInputWidget.prototype.getAllowInteger;
/**
* Set the stepping deltas
*
- * @param {number} step Normal step
- * @param {number|null} pageStep Page step. If null, 10 * step will be used.
+ * @param {number} [buttonStep=step||1] Delta when using the buttons or up/down arrow keys.
+ * Defaults to `step` if specified, otherwise `1`.
+ * @param {number} [pageStep=10*buttonStep] Delta when using the page-up/page-down keys.
+ * Defaults to 10 times `buttonStep`.
+ * @param {number|null} [step] If specified, the field only accepts values that are multiples of this.
*/
-OO.ui.NumberInputWidget.prototype.setStep = function ( step, pageStep ) {
- if ( step <= 0 ) {
- throw new Error( 'Step value must be positive' );
+OO.ui.NumberInputWidget.prototype.setStep = function ( buttonStep, pageStep, step ) {
+ if ( buttonStep === undefined ) {
+ buttonStep = step || 1;
}
- if ( pageStep === null ) {
- pageStep = step * 10;
- } else if ( pageStep <= 0 ) {
+ if ( pageStep === undefined ) {
+ pageStep = 10 * buttonStep;
+ }
+ if ( step !== null && step <= 0 ) {
+ throw new Error( 'Step value, if given, must be positive' );
+ }
+ if ( buttonStep <= 0 ) {
+ throw new Error( 'Button step value must be positive' );
+ }
+ if ( pageStep <= 0 ) {
throw new Error( 'Page step value must be positive' );
}
this.step = step;
+ this.buttonStep = buttonStep;
this.pageStep = pageStep;
- this.$input.attr( 'step', this.step );
+ this.$input.attr( 'step', this.step || 'any' );
+ this.setValidityFlag();
};
/**
/**
* Get the current stepping values
*
- * @return {number[]} Step and page step
+ * @return {number[]} Button step, page step, and validity step
*/
OO.ui.NumberInputWidget.prototype.getStep = function () {
- return [ this.step, this.pageStep ];
+ return [ this.buttonStep, this.pageStep, this.step ];
};
/**
} else {
n = v + delta;
n = Math.max( Math.min( n, this.max ), this.min );
- if ( this.allowInteger ) {
- n = Math.round( n );
+ if ( this.step ) {
+ n = Math.round( n / this.step ) * this.step;
}
}
return false;
}
- if ( this.allowInteger && Math.floor( n ) !== n ) {
+ if ( this.step && Math.floor( n / this.step ) !== n / this.step ) {
return false;
}
* @param {number} dir +1 or -1
*/
OO.ui.NumberInputWidget.prototype.onButtonClick = function ( dir ) {
- this.adjustValue( dir * this.step );
+ this.adjustValue( dir * this.buttonStep );
};
/**
if ( delta ) {
delta = delta < 0 ? -1 : 1;
- this.adjustValue( delta * this.step );
+ this.adjustValue( delta * this.buttonStep );
}
return false;
if ( !this.isDisabled() ) {
switch ( e.which ) {
case OO.ui.Keys.UP:
- this.adjustValue( this.step );
+ this.adjustValue( this.buttonStep );
return false;
case OO.ui.Keys.DOWN:
- this.adjustValue( -this.step );
+ this.adjustValue( -this.buttonStep );
return false;
case OO.ui.Keys.PAGEUP:
this.adjustValue( this.pageStep );