Update OOjs UI to v0.13.1
[lhc/web/wiklou.git] / resources / lib / oojs-ui / oojs-ui.js
index aeff69e..b4dc48c 100644 (file)
@@ -1,12 +1,12 @@
 /*!
- * OOjs UI v0.12.12
+ * OOjs UI v0.13.1
  * https://www.mediawiki.org/wiki/OOjs_UI
  *
  * Copyright 2011–2015 OOjs UI Team and other contributors.
  * Released under the MIT license
  * http://oojs.mit-license.org
  *
- * Date: 2015-10-13T20:38:18Z
+ * Date: 2015-11-03T21:42:20Z
  */
 ( function ( OO ) {
 
@@ -1289,17 +1289,25 @@ OO.ui.Element.static.unsafeInfuse = function ( idOrNode, domPromise ) {
                        }
                }
        } );
-       // jscs:disable requireCapitalizedConstructors
-       obj = new cls( data ); // rebuild widget
+       // allow widgets to reuse parts of the DOM
+       data = cls.static.reusePreInfuseDOM( $elem[ 0 ], data );
        // pick up dynamic state, like focus, value of form inputs, scroll position, etc.
-       state = obj.gatherPreInfuseState( $elem );
+       state = cls.static.gatherPreInfuseState( $elem[ 0 ], data );
+       // rebuild widget
+       // jscs:disable requireCapitalizedConstructors
+       obj = new cls( data );
+       // jscs:enable requireCapitalizedConstructors
        // now replace old DOM with this new DOM.
        if ( top ) {
-               $elem.replaceWith( obj.$element );
-               // This element is now gone from the DOM, but if anyone is holding a reference to it,
-               // let's allow them to OO.ui.infuse() it and do what they expect (T105828).
-               // Do not use jQuery.data(), as using it on detached nodes leaks memory in 1.x line by design.
-               $elem[ 0 ].oouiInfused = obj;
+               // An efficient constructor might be able to reuse the entire DOM tree of the original element,
+               // so only mutate the DOM if we need to.
+               if ( $elem[ 0 ] !== obj.$element[ 0 ] ) {
+                       $elem.replaceWith( obj.$element );
+                       // This element is now gone from the DOM, but if anyone is holding a reference to it,
+                       // let's allow them to OO.ui.infuse() it and do what they expect (T105828).
+                       // Do not use jQuery.data(), as using it on detached nodes leaks memory in 1.x line by design.
+                       $elem[ 0 ].oouiInfused = obj;
+               }
                top.resolve();
        }
        obj.$element.data( 'ooui-infused', obj );
@@ -1310,6 +1318,40 @@ OO.ui.Element.static.unsafeInfuse = function ( idOrNode, domPromise ) {
        return obj;
 };
 
+/**
+ * Pick out parts of `node`'s DOM to be reused when infusing a widget.
+ *
+ * This method **must not** make any changes to the DOM, only find interesting pieces and add them
+ * to `config` (which should then be returned). Actual DOM juggling should then be done by the
+ * constructor, which will be given the enhanced config.
+ *
+ * @protected
+ * @param {HTMLElement} node
+ * @param {Object} config
+ * @return {Object}
+ */
+OO.ui.Element.static.reusePreInfuseDOM = function ( node, config ) {
+       return config;
+};
+
+/**
+ * Gather the dynamic state (focus, value of form inputs, scroll position, etc.) of a HTML DOM node
+ * (and its children) that represent an Element of the same class and the given configuration,
+ * generated by the PHP implementation.
+ *
+ * This method is called just before `node` is detached from the DOM. The return value of this
+ * function will be passed to #restorePreInfuseState after the newly created widget's #$element
+ * is inserted into DOM to replace `node`.
+ *
+ * @protected
+ * @param {HTMLElement} node
+ * @param {Object} config
+ * @return {Object}
+ */
+OO.ui.Element.static.gatherPreInfuseState = function () {
+       return {};
+};
+
 /**
  * Get a jQuery function within a specific document.
  *
@@ -1888,23 +1930,6 @@ OO.ui.Element.prototype.scrollElementIntoView = function ( config ) {
        return OO.ui.Element.static.scrollIntoView( this.$element[ 0 ], config );
 };
 
-/**
- * Gather the dynamic state (focus, value of form inputs, scroll position, etc.) of a HTML DOM node
- * (and its children) that represent an Element of the same type and configuration as the current
- * one, generated by the PHP implementation.
- *
- * This method is called just before `node` is detached from the DOM. The return value of this
- * function will be passed to #restorePreInfuseState after this widget's #$element is inserted into
- * DOM to replace `node`.
- *
- * @protected
- * @param {HTMLElement} node
- * @return {Object}
- */
-OO.ui.Element.prototype.gatherPreInfuseState = function () {
-       return {};
-};
-
 /**
  * Restore the pre-infusion dynamic state for this widget.
  *
@@ -9020,7 +9045,7 @@ OO.ui.ProcessDialog.prototype.getTeardownProcess = function ( data ) {
  * @throws {Error} An error is thrown if no widget is specified
  */
 OO.ui.FieldLayout = function OoUiFieldLayout( fieldWidget, config ) {
-       var hasInputWidget, div, i;
+       var hasInputWidget, div;
 
        // Allow passing positional parameters inside the config object
        if ( OO.isPlainObject( fieldWidget ) && config === undefined ) {
@@ -9047,8 +9072,8 @@ OO.ui.FieldLayout = function OoUiFieldLayout( fieldWidget, config ) {
 
        // Properties
        this.fieldWidget = fieldWidget;
-       this.errors = config.errors || [];
-       this.notices = config.notices || [];
+       this.errors = [];
+       this.notices = [];
        this.$field = $( '<div>' );
        this.$messages = $( '<ul>' );
        this.$body = $( '<' + ( hasInputWidget ? 'label' : 'div' ) + '>' );
@@ -9084,9 +9109,6 @@ OO.ui.FieldLayout = function OoUiFieldLayout( fieldWidget, config ) {
        this.$element
                .addClass( 'oo-ui-fieldLayout' )
                .append( this.$help, this.$body );
-       if ( this.errors.length || this.notices.length ) {
-               this.$element.append( this.$messages );
-       }
        this.$body.addClass( 'oo-ui-fieldLayout-body' );
        this.$messages.addClass( 'oo-ui-fieldLayout-messages' );
        this.$field
@@ -9094,13 +9116,8 @@ OO.ui.FieldLayout = function OoUiFieldLayout( fieldWidget, config ) {
                .toggleClass( 'oo-ui-fieldLayout-disable', this.fieldWidget.isDisabled() )
                .append( this.fieldWidget.$element );
 
-       for ( i = 0; i < this.notices.length; i++ ) {
-               this.$messages.append( this.makeMessage( 'notice', this.notices[ i ] ) );
-       }
-       for ( i = 0; i < this.errors.length; i++ ) {
-               this.$messages.append( this.makeMessage( 'error', this.errors[ i ] ) );
-       }
-
+       this.setErrors( config.errors || [] );
+       this.setNotices( config.notices || [] );
        this.setAlignment( config.align );
 };
 
@@ -9143,6 +9160,7 @@ OO.ui.FieldLayout.prototype.getField = function () {
 };
 
 /**
+ * @protected
  * @param {string} kind 'error' or 'notice'
  * @param {string|OO.ui.HtmlSnippet} text
  * @return {jQuery}
@@ -9198,6 +9216,56 @@ OO.ui.FieldLayout.prototype.setAlignment = function ( value ) {
        return this;
 };
 
+/**
+ * Set the list of error messages.
+ *
+ * @param {Array} errors Error messages about the widget, which will be displayed below the widget.
+ *  The array may contain strings or OO.ui.HtmlSnippet instances.
+ * @chainable
+ */
+OO.ui.FieldLayout.prototype.setErrors = function ( errors ) {
+       this.errors = errors.slice();
+       this.updateMessages();
+       return this;
+};
+
+/**
+ * Set the list of notice messages.
+ *
+ * @param {Array} notices Notices about the widget, which will be displayed below the widget.
+ *  The array may contain strings or OO.ui.HtmlSnippet instances.
+ * @chainable
+ */
+OO.ui.FieldLayout.prototype.setNotices = function ( notices ) {
+       this.notices = notices.slice();
+       this.updateMessages();
+       return this;
+};
+
+/**
+ * Update the rendering of error and notice messages.
+ *
+ * @private
+ */
+OO.ui.FieldLayout.prototype.updateMessages = function () {
+       var i;
+       this.$messages.empty();
+
+       if ( this.errors.length || this.notices.length ) {
+               this.$body.after( this.$messages );
+       } else {
+               this.$messages.remove();
+               return;
+       }
+
+       for ( i = 0; i < this.notices.length; i++ ) {
+               this.$messages.append( this.makeMessage( 'notice', this.notices[ i ] ) );
+       }
+       for ( i = 0; i < this.errors.length; i++ ) {
+               this.$messages.append( this.makeMessage( 'error', this.errors[ i ] ) );
+       }
+};
+
 /**
  * ActionFieldLayouts are used with OO.ui.FieldsetLayout. The layout consists of a field-widget, a button,
  * and an optional label and/or help text. The field-widget (e.g., a {@link OO.ui.TextInputWidget TextInputWidget}),
@@ -9730,6 +9798,8 @@ OO.ui.BookletLayout = function OoUiBookletLayout( config ) {
        this.stackLayout.connect( this, { set: 'onStackLayoutSet' } );
        if ( this.outlined ) {
                this.outlineSelectWidget.connect( this, { select: 'onOutlineSelectWidgetSelect' } );
+               this.scrolling = false;
+               this.stackLayout.connect( this, { visibleItemChange: 'onStackLayoutVisibleItemChange' } );
        }
        if ( this.autoFocus ) {
                // Event 'focus' does not bubble, but 'focusin' does
@@ -9801,6 +9871,22 @@ OO.ui.BookletLayout.prototype.onStackLayoutFocus = function ( e ) {
        }
 };
 
+/**
+ * Handle visibleItemChange events from the stackLayout
+ *
+ * The next visible page is set as the current page by selecting it
+ * in the outline
+ *
+ * @param {OO.ui.PageLayout} page The next visible page in the layout
+ */
+OO.ui.BookletLayout.prototype.onStackLayoutVisibleItemChange = function ( page ) {
+       // Set a flag to so that the resulting call to #onStackLayoutSet doesn't
+       // try and scroll the item into view again.
+       this.scrolling = true;
+       this.outlineSelectWidget.selectItemByData( page.getName() );
+       this.scrolling = false;
+};
+
 /**
  * Handle stack layout set events.
  *
@@ -9809,7 +9895,7 @@ OO.ui.BookletLayout.prototype.onStackLayoutFocus = function ( e ) {
  */
 OO.ui.BookletLayout.prototype.onStackLayoutSet = function ( page ) {
        var layout = this;
-       if ( page ) {
+       if ( !this.scrolling && page ) {
                page.scrollElementIntoView( { complete: function () {
                        if ( layout.autoFocus ) {
                                layout.focus();
@@ -11020,6 +11106,7 @@ OO.ui.StackLayout = function OoUiStackLayout( config ) {
        this.$element.addClass( 'oo-ui-stackLayout' );
        if ( this.continuous ) {
                this.$element.addClass( 'oo-ui-stackLayout-continuous' );
+               this.$element.on( 'scroll', OO.ui.debounce( this.onScroll.bind( this ), 250 ) );
        }
        if ( Array.isArray( config.items ) ) {
                this.addItems( config.items );
@@ -11041,8 +11128,66 @@ OO.mixinClass( OO.ui.StackLayout, OO.ui.mixin.GroupElement );
  * @param {OO.ui.Layout|null} item Current panel or `null` if no panel is shown
  */
 
+/**
+ * When used in continuous mode, this event is emitted when the user scrolls down
+ * far enough such that currentItem is no longer visible.
+ *
+ * @event visibleItemChange
+ * @param {OO.ui.PanelLayout} panel The next visible item in the layout
+ */
+
 /* Methods */
 
+/**
+ * Handle scroll events from the layout element
+ *
+ * @param {jQuery.Event} e
+ * @fires visibleItemChange
+ */
+OO.ui.StackLayout.prototype.onScroll = function () {
+       var currentRect,
+               len = this.items.length,
+               currentIndex = this.items.indexOf( this.currentItem ),
+               newIndex = currentIndex,
+               containerRect = this.$element[ 0 ].getBoundingClientRect();
+
+       if ( !containerRect || ( !containerRect.top && !containerRect.bottom ) ) {
+               // Can't get bounding rect, possibly not attached.
+               return;
+       }
+
+       function getRect( item ) {
+               return item.$element[ 0 ].getBoundingClientRect();
+       }
+
+       function isVisible( item ) {
+               var rect = getRect( item );
+               return rect.bottom > containerRect.top && rect.top < containerRect.bottom;
+       }
+
+       currentRect = getRect( this.currentItem );
+
+       if ( currentRect.bottom < containerRect.top ) {
+               // Scrolled down past current item
+               while ( ++newIndex < len ) {
+                       if ( isVisible( this.items[ newIndex ] ) ) {
+                               break;
+                       }
+               }
+       } else if ( currentRect.top > containerRect.bottom ) {
+               // Scrolled up past current item
+               while ( --newIndex >= 0 ) {
+                       if ( isVisible( this.items[ newIndex ] ) ) {
+                               break;
+                       }
+               }
+       }
+
+       if ( newIndex !== currentIndex ) {
+               this.emit( 'visibleItemChange', this.items[ newIndex ] );
+       }
+};
+
 /**
  * Get the current panel.
  *
@@ -14491,7 +14636,7 @@ OO.ui.IndicatorWidget.static.tagName = 'span';
  * @param {Object} [config] Configuration options
  * @cfg {string} [name=''] The value of the input’s HTML `name` attribute.
  * @cfg {string} [value=''] The value of the input.
- * @cfg {string} [accessKey=''] The access key of the input.
+ * @cfg {string} [dir] The directionality of the input (ltr/rtl).
  * @cfg {Function} [inputFilter] The name of an input filter function. Input filters modify the value of an input
  *  before it is accepted.
  */
@@ -14526,6 +14671,9 @@ OO.ui.InputWidget = function OoUiInputWidget( config ) {
                .append( this.$input );
        this.setValue( config.value );
        this.setAccessKey( config.accessKey );
+       if ( config.dir ) {
+               this.setDir( config.dir );
+       }
 };
 
 /* Setup */
@@ -14540,6 +14688,29 @@ OO.mixinClass( OO.ui.InputWidget, OO.ui.mixin.AccessKeyedElement );
 
 OO.ui.InputWidget.static.supportsSimpleLabel = true;
 
+/* Static Methods */
+
+/**
+ * @inheritdoc
+ */
+OO.ui.InputWidget.static.reusePreInfuseDOM = function ( node, config ) {
+       config = OO.ui.InputWidget.parent.static.reusePreInfuseDOM( node, config );
+       // Reusing $input lets browsers preserve inputted values across page reloads (T114134)
+       config.$input = $( node ).find( '.oo-ui-inputWidget-input' );
+       return config;
+};
+
+/**
+ * @inheritdoc
+ */
+OO.ui.InputWidget.static.gatherPreInfuseState = function ( node, config ) {
+       var state = OO.ui.InputWidget.parent.static.gatherPreInfuseState( node, config );
+       state.value = config.$input.val();
+       // Might be better in TabIndexedElement, but it's awkward to do there because mixins are awkward
+       state.focus = config.$input.is( ':focus' );
+       return state;
+};
+
 /* Events */
 
 /**
@@ -14562,8 +14733,9 @@ OO.ui.InputWidget.static.supportsSimpleLabel = true;
  * @param {Object} config Configuration options
  * @return {jQuery} Input element
  */
-OO.ui.InputWidget.prototype.getInputElement = function () {
-       return $( '<input>' );
+OO.ui.InputWidget.prototype.getInputElement = function ( config ) {
+       // See #reusePreInfuseDOM about config.$input
+       return config.$input || $( '<input>' );
 };
 
 /**
@@ -14598,13 +14770,26 @@ OO.ui.InputWidget.prototype.getValue = function () {
 };
 
 /**
- * Set the direction of the input, either RTL (right-to-left) or LTR (left-to-right).
+ * Set the directionality of the input, either RTL (right-to-left) or LTR (left-to-right).
  *
- * @param {boolean} isRTL
- * Direction is right-to-left
+ * @deprecated since v0.13.1, use #setDir directly
+ * @param {boolean} isRTL Directionality is right-to-left
+ * @chainable
  */
 OO.ui.InputWidget.prototype.setRTL = function ( isRTL ) {
-       this.$input.prop( 'dir', isRTL ? 'rtl' : 'ltr' );
+       this.setDir( isRTL ? 'rtl' : 'ltr' );
+       return this;
+};
+
+/**
+ * Set the directionality of the input.
+ *
+ * @param {string} dir Text directionality: 'ltr', 'rtl' or 'auto'
+ * @chainable
+ */
+OO.ui.InputWidget.prototype.setDir = function ( dir ) {
+       this.$input.prop( 'dir', dir );
+       return this;
 };
 
 /**
@@ -14718,19 +14903,6 @@ OO.ui.InputWidget.prototype.blur = function () {
        return this;
 };
 
-/**
- * @inheritdoc
- */
-OO.ui.InputWidget.prototype.gatherPreInfuseState = function ( node ) {
-       var
-               state = OO.ui.InputWidget.parent.prototype.gatherPreInfuseState.call( this, node ),
-               $input = state.$input || $( node ).find( '.oo-ui-inputWidget-input' );
-       state.value = $input.val();
-       // Might be better in TabIndexedElement, but it's awkward to do there because mixins are awkward
-       state.focus = $input.is( ':focus' );
-       return state;
-};
-
 /**
  * @inheritdoc
  */
@@ -14826,9 +14998,12 @@ OO.ui.ButtonInputWidget.static.supportsSimpleLabel = false;
  * @protected
  */
 OO.ui.ButtonInputWidget.prototype.getInputElement = function ( config ) {
-       var type = [ 'button', 'submit', 'reset' ].indexOf( config.type ) !== -1 ?
-               config.type :
-               'button';
+       var type;
+       // See InputWidget#reusePreInfuseDOM about config.$input
+       if ( config.$input ) {
+               return config.$input.empty();
+       }
+       type = [ 'button', 'submit', 'reset' ].indexOf( config.type ) !== -1 ? config.type : 'button';
        return $( '<' + ( config.useInputTag ? 'input' : 'button' ) + ' type="' + type + '">' );
 };
 
@@ -14936,6 +15111,17 @@ OO.ui.CheckboxInputWidget = function OoUiCheckboxInputWidget( config ) {
 
 OO.inheritClass( OO.ui.CheckboxInputWidget, OO.ui.InputWidget );
 
+/* Static Methods */
+
+/**
+ * @inheritdoc
+ */
+OO.ui.CheckboxInputWidget.static.gatherPreInfuseState = function ( node, config ) {
+       var state = OO.ui.CheckboxInputWidget.parent.static.gatherPreInfuseState( node, config );
+       state.checked = config.$input.prop( 'checked' );
+       return state;
+};
+
 /* Methods */
 
 /**
@@ -14990,18 +15176,6 @@ OO.ui.CheckboxInputWidget.prototype.isSelected = function () {
        return this.selected;
 };
 
-/**
- * @inheritdoc
- */
-OO.ui.CheckboxInputWidget.prototype.gatherPreInfuseState = function ( node ) {
-       var
-               state = OO.ui.CheckboxInputWidget.parent.prototype.gatherPreInfuseState.call( this, node ),
-               $input = $( node ).find( '.oo-ui-inputWidget-input' );
-       state.$input = $input; // shortcut for performance, used in InputWidget
-       state.checked = $input.prop( 'checked' );
-       return state;
-};
-
 /**
  * @inheritdoc
  */
@@ -15080,7 +15254,11 @@ OO.mixinClass( OO.ui.DropdownInputWidget, OO.ui.mixin.TitledElement );
  * @inheritdoc
  * @protected
  */
-OO.ui.DropdownInputWidget.prototype.getInputElement = function () {
+OO.ui.DropdownInputWidget.prototype.getInputElement = function ( config ) {
+       // See InputWidget#reusePreInfuseDOM about config.$input
+       if ( config.$input ) {
+               return config.$input.addClass( 'oo-ui-element-hidden' );
+       }
        return $( '<input type="hidden">' );
 };
 
@@ -15225,6 +15403,17 @@ OO.ui.RadioInputWidget = function OoUiRadioInputWidget( config ) {
 
 OO.inheritClass( OO.ui.RadioInputWidget, OO.ui.InputWidget );
 
+/* Static Methods */
+
+/**
+ * @inheritdoc
+ */
+OO.ui.RadioInputWidget.static.gatherPreInfuseState = function ( node, config ) {
+       var state = OO.ui.RadioInputWidget.parent.static.gatherPreInfuseState( node, config );
+       state.checked = config.$input.prop( 'checked' );
+       return state;
+};
+
 /* Methods */
 
 /**
@@ -15263,18 +15452,6 @@ OO.ui.RadioInputWidget.prototype.isSelected = function () {
        return this.$input.prop( 'checked' );
 };
 
-/**
- * @inheritdoc
- */
-OO.ui.RadioInputWidget.prototype.gatherPreInfuseState = function ( node ) {
-       var
-               state = OO.ui.RadioInputWidget.parent.prototype.gatherPreInfuseState.call( this, node ),
-               $input = $( node ).find( '.oo-ui-inputWidget-input' );
-       state.$input = $input; // shortcut for performance, used in InputWidget
-       state.checked = $input.prop( 'checked' );
-       return state;
-};
-
 /**
  * @inheritdoc
  */
@@ -15341,6 +15518,17 @@ OO.inheritClass( OO.ui.RadioSelectInputWidget, OO.ui.InputWidget );
 
 OO.ui.RadioSelectInputWidget.static.supportsSimpleLabel = false;
 
+/* Static Methods */
+
+/**
+ * @inheritdoc
+ */
+OO.ui.RadioSelectInputWidget.static.gatherPreInfuseState = function ( node, config ) {
+       var state = OO.ui.RadioSelectInputWidget.parent.static.gatherPreInfuseState( node, config );
+       state.value = $( node ).find( '.oo-ui-radioInputWidget .oo-ui-inputWidget-input:checked' ).val();
+       return state;
+};
+
 /* Methods */
 
 /**
@@ -15416,15 +15604,6 @@ OO.ui.RadioSelectInputWidget.prototype.setOptions = function ( options ) {
        return this;
 };
 
-/**
- * @inheritdoc
- */
-OO.ui.RadioSelectInputWidget.prototype.gatherPreInfuseState = function ( node ) {
-       var state = OO.ui.RadioSelectInputWidget.parent.prototype.gatherPreInfuseState.call( this, node );
-       state.value = $( node ).find( '.oo-ui-radioInputWidget .oo-ui-inputWidget-input:checked' ).val();
-       return state;
-};
-
 /**
  * TextInputWidgets, like HTML text inputs, can be configured with options that customize the
  * size of the field as well as its presentation. In addition, these widgets can be configured
@@ -15517,6 +15696,8 @@ OO.ui.TextInputWidget = function OoUiTextInputWidget( config ) {
        this.minRows = config.rows !== undefined ? config.rows : '';
        this.maxRows = config.maxRows || Math.max( 2 * ( this.minRows || 0 ), 10 );
        this.validate = null;
+       this.styleHeight = null;
+       this.scrollWidth = null;
 
        // Clone for resizing
        if ( this.autosize ) {
@@ -15603,6 +15784,19 @@ OO.ui.TextInputWidget.static.validationPatterns = {
        integer: /^\d+$/
 };
 
+/* Static Methods */
+
+/**
+ * @inheritdoc
+ */
+OO.ui.TextInputWidget.static.gatherPreInfuseState = function ( node, config ) {
+       var state = OO.ui.TextInputWidget.parent.static.gatherPreInfuseState( node, config );
+       if ( config.multiline ) {
+               state.scrollTop = config.$input.scrollTop();
+       }
+       return state;
+};
+
 /* Events */
 
 /**
@@ -15613,6 +15807,12 @@ OO.ui.TextInputWidget.static.validationPatterns = {
  * @event enter
  */
 
+/**
+ * A `resize` event is emitted when autosize is set and the widget resizes
+ *
+ * @event resize
+ */
+
 /* Methods */
 
 /**
@@ -15802,48 +16002,70 @@ OO.ui.TextInputWidget.prototype.installParentChangeDetector = function () {
  * This only affects #multiline inputs that are {@link #autosize autosized}.
  *
  * @chainable
+ * @fires resize
  */
 OO.ui.TextInputWidget.prototype.adjustSize = function () {
-       var scrollHeight, innerHeight, outerHeight, maxInnerHeight, measurementError, idealHeight;
+       var scrollHeight, innerHeight, outerHeight, maxInnerHeight, measurementError,
+               idealHeight, newHeight, scrollWidth, property;
 
-       if ( this.multiline && this.autosize && this.$input.val() !== this.valCache ) {
-               this.$clone
-                       .val( this.$input.val() )
-                       .attr( 'rows', this.minRows )
-                       // Set inline height property to 0 to measure scroll height
-                       .css( 'height', 0 );
+       if ( this.multiline && this.$input.val() !== this.valCache ) {
+               if ( this.autosize ) {
+                       this.$clone
+                               .val( this.$input.val() )
+                               .attr( 'rows', this.minRows )
+                               // Set inline height property to 0 to measure scroll height
+                               .css( 'height', 0 );
 
-               this.$clone.removeClass( 'oo-ui-element-hidden' );
+                       this.$clone.removeClass( 'oo-ui-element-hidden' );
 
-               this.valCache = this.$input.val();
+                       this.valCache = this.$input.val();
 
-               scrollHeight = this.$clone[ 0 ].scrollHeight;
+                       scrollHeight = this.$clone[ 0 ].scrollHeight;
 
-               // Remove inline height property to measure natural heights
-               this.$clone.css( 'height', '' );
-               innerHeight = this.$clone.innerHeight();
-               outerHeight = this.$clone.outerHeight();
+                       // Remove inline height property to measure natural heights
+                       this.$clone.css( 'height', '' );
+                       innerHeight = this.$clone.innerHeight();
+                       outerHeight = this.$clone.outerHeight();
 
-               // Measure max rows height
-               this.$clone
-                       .attr( 'rows', this.maxRows )
-                       .css( 'height', 'auto' )
-                       .val( '' );
-               maxInnerHeight = this.$clone.innerHeight();
+                       // Measure max rows height
+                       this.$clone
+                               .attr( 'rows', this.maxRows )
+                               .css( 'height', 'auto' )
+                               .val( '' );
+                       maxInnerHeight = this.$clone.innerHeight();
 
-               // Difference between reported innerHeight and scrollHeight with no scrollbars present
-               // Equals 1 on Blink-based browsers and 0 everywhere else
-               measurementError = maxInnerHeight - this.$clone[ 0 ].scrollHeight;
-               idealHeight = Math.min( maxInnerHeight, scrollHeight + measurementError );
+                       // Difference between reported innerHeight and scrollHeight with no scrollbars present
+                       // Equals 1 on Blink-based browsers and 0 everywhere else
+                       measurementError = maxInnerHeight - this.$clone[ 0 ].scrollHeight;
+                       idealHeight = Math.min( maxInnerHeight, scrollHeight + measurementError );
 
-               this.$clone.addClass( 'oo-ui-element-hidden' );
+                       this.$clone.addClass( 'oo-ui-element-hidden' );
 
-               // Only apply inline height when expansion beyond natural height is needed
-               if ( idealHeight > innerHeight ) {
+                       // Only apply inline height when expansion beyond natural height is needed
                        // Use the difference between the inner and outer height as a buffer
-                       this.$input.css( 'height', idealHeight + ( outerHeight - innerHeight ) );
-               } else {
-                       this.$input.css( 'height', '' );
+                       newHeight = idealHeight > innerHeight ? idealHeight + ( outerHeight - innerHeight ) : '';
+                       if ( newHeight !== this.styleHeight ) {
+                               this.$input.css( 'height', newHeight );
+                               this.styleHeight = newHeight;
+                               this.emit( 'resize' );
+                       }
+               }
+               scrollWidth = this.$input[ 0 ].offsetWidth - this.$input[ 0 ].clientWidth;
+               if ( scrollWidth !== this.scrollWidth ) {
+                       property = this.$element.css( 'direction' ) === 'rtl' ? 'left' : 'right';
+                       // Reset
+                       this.$label.css( { right: '', left: '' } );
+                       this.$indicator.css( { right: '', left: '' } );
+
+                       if ( scrollWidth ) {
+                               this.$indicator.css( property, scrollWidth );
+                               if ( this.labelPosition === 'after' ) {
+                                       this.$label.css( property, scrollWidth );
+                               }
+                       }
+
+                       this.scrollWidth = scrollWidth;
+                       this.positionLabel();
                }
        }
        return this;
@@ -15892,30 +16114,74 @@ OO.ui.TextInputWidget.prototype.isAutosizing = function () {
 };
 
 /**
- * Select the entire text of the input.
+ * Focus the input and select a specified range within the text.
  *
+ * @param {number} from Select from offset
+ * @param {number} [to] Select to offset, defaults to from
  * @chainable
  */
-OO.ui.TextInputWidget.prototype.select = function () {
-       this.$input.select();
-       return this;
-};
-
-/**
- * Focus the input and move the cursor to the end.
- */
-OO.ui.TextInputWidget.prototype.moveCursorToEnd = function () {
-       var textRange,
+OO.ui.TextInputWidget.prototype.selectRange = function ( from, to ) {
+       var textRange, isBackwards, start, end,
                element = this.$input[ 0 ];
+
+       to = to || from;
+
+       isBackwards = to < from;
+       start = isBackwards ? to : from;
+       end = isBackwards ? from : to;
+
        this.focus();
-       if ( element.selectionStart !== undefined ) {
-               element.selectionStart = element.selectionEnd = element.value.length;
+
+       if ( element.setSelectionRange ) {
+               element.setSelectionRange( start, end, isBackwards ? 'backward' : 'forward' );
        } else if ( element.createTextRange ) {
                // IE 8 and below
                textRange = element.createTextRange();
-               textRange.collapse( false );
+               textRange.collapse( true );
+               textRange.moveStart( 'character', start );
+               textRange.moveEnd( 'character', end - start );
                textRange.select();
        }
+       return this;
+};
+
+/**
+ * Get the length of the text input value.
+ *
+ * This could differ from the length of #getValue if the
+ * value gets filtered
+ *
+ * @return {number} Input length
+ */
+OO.ui.TextInputWidget.prototype.getInputLength = function () {
+       return this.$input[ 0 ].value.length;
+};
+
+/**
+ * Focus the input and select the entire text.
+ *
+ * @chainable
+ */
+OO.ui.TextInputWidget.prototype.select = function () {
+       return this.selectRange( 0, this.getInputLength() );
+};
+
+/**
+ * Focus the input and move the cursor to the start.
+ *
+ * @chainable
+ */
+OO.ui.TextInputWidget.prototype.moveCursorToStart = function () {
+       return this.selectRange( 0 );
+};
+
+/**
+ * Focus the input and move the cursor to the end.
+ *
+ * @chainable
+ */
+OO.ui.TextInputWidget.prototype.moveCursorToEnd = function () {
+       return this.selectRange( this.getInputLength() );
 };
 
 /**
@@ -16066,6 +16332,9 @@ OO.ui.TextInputWidget.prototype.updatePosition = function () {
                .toggleClass( 'oo-ui-textInputWidget-labelPosition-after', !!this.label && after )
                .toggleClass( 'oo-ui-textInputWidget-labelPosition-before', !!this.label && !after );
 
+       this.valCache = null;
+       this.scrollWidth = null;
+       this.adjustSize();
        this.positionLabel();
 
        return this;
@@ -16112,25 +16381,11 @@ OO.ui.TextInputWidget.prototype.positionLabel = function () {
        rtl = this.$element.css( 'direction' ) === 'rtl';
        property = after === rtl ? 'padding-left' : 'padding-right';
 
-       this.$input.css( property, this.$label.outerWidth( true ) );
+       this.$input.css( property, this.$label.outerWidth( true ) + ( after ? this.scrollWidth : 0 ) );
 
        return this;
 };
 
-/**
- * @inheritdoc
- */
-OO.ui.TextInputWidget.prototype.gatherPreInfuseState = function ( node ) {
-       var
-               state = OO.ui.TextInputWidget.parent.prototype.gatherPreInfuseState.call( this, node ),
-               $input = $( node ).find( '.oo-ui-inputWidget-input' );
-       state.$input = $input; // shortcut for performance, used in InputWidget
-       if ( this.multiline ) {
-               state.scrollTop = $input.scrollTop();
-       }
-       return state;
-};
-
 /**
  * @inheritdoc
  */
@@ -19612,104 +19867,4 @@ OO.ui.ToggleSwitchWidget.prototype.onKeyPress = function ( e ) {
        }
 };
 
-/*!
- * Deprecated aliases for classes in the `OO.ui.mixin` namespace.
- */
-
-/**
- * @inheritdoc OO.ui.mixin.ButtonElement
- * @deprecated Use {@link OO.ui.mixin.ButtonElement} instead.
- */
-OO.ui.ButtonElement = OO.ui.mixin.ButtonElement;
-
-/**
- * @inheritdoc OO.ui.mixin.ClippableElement
- * @deprecated Use {@link OO.ui.mixin.ClippableElement} instead.
- */
-OO.ui.ClippableElement = OO.ui.mixin.ClippableElement;
-
-/**
- * @inheritdoc OO.ui.mixin.DraggableElement
- * @deprecated Use {@link OO.ui.mixin.DraggableElement} instead.
- */
-OO.ui.DraggableElement = OO.ui.mixin.DraggableElement;
-
-/**
- * @inheritdoc OO.ui.mixin.DraggableGroupElement
- * @deprecated Use {@link OO.ui.mixin.DraggableGroupElement} instead.
- */
-OO.ui.DraggableGroupElement = OO.ui.mixin.DraggableGroupElement;
-
-/**
- * @inheritdoc OO.ui.mixin.FlaggedElement
- * @deprecated Use {@link OO.ui.mixin.FlaggedElement} instead.
- */
-OO.ui.FlaggedElement = OO.ui.mixin.FlaggedElement;
-
-/**
- * @inheritdoc OO.ui.mixin.GroupElement
- * @deprecated Use {@link OO.ui.mixin.GroupElement} instead.
- */
-OO.ui.GroupElement = OO.ui.mixin.GroupElement;
-
-/**
- * @inheritdoc OO.ui.mixin.GroupWidget
- * @deprecated Use {@link OO.ui.mixin.GroupWidget} instead.
- */
-OO.ui.GroupWidget = OO.ui.mixin.GroupWidget;
-
-/**
- * @inheritdoc OO.ui.mixin.IconElement
- * @deprecated Use {@link OO.ui.mixin.IconElement} instead.
- */
-OO.ui.IconElement = OO.ui.mixin.IconElement;
-
-/**
- * @inheritdoc OO.ui.mixin.IndicatorElement
- * @deprecated Use {@link OO.ui.mixin.IndicatorElement} instead.
- */
-OO.ui.IndicatorElement = OO.ui.mixin.IndicatorElement;
-
-/**
- * @inheritdoc OO.ui.mixin.ItemWidget
- * @deprecated Use {@link OO.ui.mixin.ItemWidget} instead.
- */
-OO.ui.ItemWidget = OO.ui.mixin.ItemWidget;
-
-/**
- * @inheritdoc OO.ui.mixin.LabelElement
- * @deprecated Use {@link OO.ui.mixin.LabelElement} instead.
- */
-OO.ui.LabelElement = OO.ui.mixin.LabelElement;
-
-/**
- * @inheritdoc OO.ui.mixin.LookupElement
- * @deprecated Use {@link OO.ui.mixin.LookupElement} instead.
- */
-OO.ui.LookupElement = OO.ui.mixin.LookupElement;
-
-/**
- * @inheritdoc OO.ui.mixin.PendingElement
- * @deprecated Use {@link OO.ui.mixin.PendingElement} instead.
- */
-OO.ui.PendingElement = OO.ui.mixin.PendingElement;
-
-/**
- * @inheritdoc OO.ui.mixin.PopupElement
- * @deprecated Use {@link OO.ui.mixin.PopupElement} instead.
- */
-OO.ui.PopupElement = OO.ui.mixin.PopupElement;
-
-/**
- * @inheritdoc OO.ui.mixin.TabIndexedElement
- * @deprecated Use {@link OO.ui.mixin.TabIndexedElement} instead.
- */
-OO.ui.TabIndexedElement = OO.ui.mixin.TabIndexedElement;
-
-/**
- * @inheritdoc OO.ui.mixin.TitledElement
- * @deprecated Use {@link OO.ui.mixin.TitledElement} instead.
- */
-OO.ui.TitledElement = OO.ui.mixin.TitledElement;
-
 }( OO ) );