Merge "resourceloader: Make various CSSMin performance optimizations and cleanups"
[lhc/web/wiklou.git] / resources / lib / oojs-ui / oojs-ui-core.js
index f403dee..68efe07 100644 (file)
@@ -1,12 +1,12 @@
 /*!
- * OOUI v0.26.5
+ * OOUI v0.27.0
  * 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-04-24T23:29:01Z
+ * Date: 2018-05-09T00:44:45Z
  */
 ( function ( OO ) {
 
@@ -2425,18 +2425,6 @@ OO.ui.mixin.GroupElement.prototype.findItemFromData = function ( data ) {
        return null;
 };
 
-/**
- * Get an item by its data.
- *
- * @deprecated Since v0.25.0; use {@link #findItemFromData} instead.
- * @param {Object} data Item data to search for
- * @return {OO.ui.Element|null} Item with equivalent data, `null` if none exists
- */
-OO.ui.mixin.GroupElement.prototype.getItemFromData = function ( data ) {
-       OO.ui.warnDeprecation( 'GroupElement#getItemFromData. Deprecated function. Use findItemFromData instead. See T76630' );
-       return this.findItemFromData( data );
-};
-
 /**
  * Find items by their data.
  *
@@ -2460,18 +2448,6 @@ OO.ui.mixin.GroupElement.prototype.findItemsFromData = function ( data ) {
        return items;
 };
 
-/**
- * Find items by their data.
- *
- * @deprecated Since v0.25.0; use {@link #findItemsFromData} instead.
- * @param {Object} data Item data to search for
- * @return {OO.ui.Element[]} Items with equivalent data
- */
-OO.ui.mixin.GroupElement.prototype.getItemsFromData = function ( data ) {
-       OO.ui.warnDeprecation( 'GroupElement#getItemsFromData. Deprecated function. Use findItemsFromData instead. See T76630' );
-       return this.findItemsFromData( data );
-};
-
 /**
  * Add items to the group.
  *
@@ -6732,17 +6708,6 @@ OO.ui.SelectWidget.prototype.findSelectedItem = function () {
        return null;
 };
 
-/**
- * Get selected item.
- *
- * @deprecated Since v0.25.0; use {@link #findSelectedItem} instead.
- * @return {OO.ui.OptionWidget|null} Selected item, `null` if no item is selected
- */
-OO.ui.SelectWidget.prototype.getSelectedItem = function () {
-       OO.ui.warnDeprecation( 'SelectWidget#getSelectedItem: Deprecated function. Use findSelectedItem instead. See T76630.' );
-       return this.findSelectedItem();
-};
-
 /**
  * Find highlighted item.
  *
@@ -8182,17 +8147,6 @@ OO.ui.MultiselectWidget.prototype.findSelectedItems = function () {
        } );
 };
 
-/**
- * Get options that are selected.
- *
- * @deprecated Since v0.25.0; use {@link #findSelectedItems} instead.
- * @return {OO.ui.MultioptionWidget[]} Selected options
- */
-OO.ui.MultiselectWidget.prototype.getSelectedItems = function () {
-       OO.ui.warnDeprecation( 'MultiselectWidget#getSelectedItems: Deprecated function. Use findSelectedItems instead. See T76630.' );
-       return this.findSelectedItems();
-};
-
 /**
  * Find the data of options that are selected.
  *
@@ -8204,17 +8158,6 @@ OO.ui.MultiselectWidget.prototype.findSelectedItemsData = function () {
        } );
 };
 
-/**
- * Get the data of options that are selected.
- *
- * @deprecated Since v0.25.0; use {@link #findSelectedItemsData} instead.
- * @return {Object[]|string[]} Values of selected options
- */
-OO.ui.MultiselectWidget.prototype.getSelectedItemsData = function () {
-       OO.ui.warnDeprecation( 'MultiselectWidget#getSelectedItemsData: Deprecated function. Use findSelectedItemsData instead. See T76630.' );
-       return this.findSelectedItemsData();
-};
-
 /**
  * Select options by reference. Options not mentioned in the `items` array will be deselected.
  *
@@ -11373,7 +11316,8 @@ OO.ui.FieldLayout = function OoUiFieldLayout( fieldWidget, config ) {
                        },
                        classes: [ 'oo-ui-fieldLayout-help' ],
                        framed: false,
-                       icon: 'info'
+                       icon: 'info',
+                       label: OO.ui.msg( 'ooui-field-help' )
                } );
                if ( config.help instanceof OO.ui.HtmlSnippet ) {
                        this.popupButtonWidget.getPopup().$body.html( config.help.toString() );
@@ -11744,7 +11688,8 @@ OO.ui.FieldsetLayout = function OoUiFieldsetLayout( config ) {
                        },
                        classes: [ 'oo-ui-fieldsetLayout-help' ],
                        framed: false,
-                       icon: 'info'
+                       icon: 'info',
+                       label: OO.ui.msg( 'ooui-field-help' )
                } );
                if ( config.help instanceof OO.ui.HtmlSnippet ) {
                        this.popupButtonWidget.getPopup().$body.html( config.help.toString() );
@@ -12030,6 +11975,371 @@ OO.ui.HorizontalLayout = function OoUiHorizontalLayout( config ) {
 OO.inheritClass( OO.ui.HorizontalLayout, OO.ui.Layout );
 OO.mixinClass( OO.ui.HorizontalLayout, OO.ui.mixin.GroupElement );
 
+/**
+ * NumberInputWidgets combine a {@link OO.ui.TextInputWidget text input} (where a value
+ * can be entered manually) and two {@link OO.ui.ButtonWidget button widgets}
+ * (to adjust the value in increments) to allow the user to enter a number.
+ *
+ *     @example
+ *     // Example: A NumberInputWidget.
+ *     var numberInput = new OO.ui.NumberInputWidget( {
+ *         label: 'NumberInputWidget',
+ *         input: { value: 5 },
+ *         min: 1,
+ *         max: 10
+ *     } );
+ *     $( 'body' ).append( numberInput.$element );
+ *
+ * @class
+ * @extends OO.ui.TextInputWidget
+ *
+ * @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 {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 {boolean} [showButtons=true] Whether to show the plus and minus buttons.
+ */
+OO.ui.NumberInputWidget = function OoUiNumberInputWidget( config ) {
+       var $field = $( '<div>' )
+               .addClass( 'oo-ui-numberInputWidget-field' );
+
+       // Configuration initialization
+       config = $.extend( {
+               allowInteger: false,
+               min: -Infinity,
+               max: Infinity,
+               step: 1,
+               pageStep: null,
+               showButtons: true
+       }, config );
+
+       // For backward compatibility
+       $.extend( config, config.input );
+       this.input = this;
+
+       // Parent constructor
+       OO.ui.NumberInputWidget.parent.call( this, $.extend( config, {
+               type: 'number'
+       } ) );
+
+       if ( config.showButtons ) {
+               this.minusButton = new OO.ui.ButtonWidget( $.extend(
+                       {
+                               disabled: this.isDisabled(),
+                               tabIndex: -1,
+                               classes: [ 'oo-ui-numberInputWidget-minusButton' ],
+                               icon: 'subtract'
+                       },
+                       config.minusButton
+               ) );
+               this.minusButton.$element.attr( 'aria-hidden', 'true' );
+               this.plusButton = new OO.ui.ButtonWidget( $.extend(
+                       {
+                               disabled: this.isDisabled(),
+                               tabIndex: -1,
+                               classes: [ 'oo-ui-numberInputWidget-plusButton' ],
+                               icon: 'add'
+                       },
+                       config.plusButton
+               ) );
+               this.plusButton.$element.attr( 'aria-hidden', 'true' );
+       }
+
+       // Events
+       this.$input.on( {
+               keydown: this.onKeyDown.bind( this ),
+               'wheel mousewheel DOMMouseScroll': this.onWheel.bind( this )
+       } );
+       if ( config.showButtons ) {
+               this.plusButton.connect( this, {
+                       click: [ 'onButtonClick', +1 ]
+               } );
+               this.minusButton.connect( this, {
+                       click: [ 'onButtonClick', -1 ]
+               } );
+       }
+
+       // Build the field
+       $field.append( this.$input );
+       if ( config.showButtons ) {
+               $field
+                       .prepend( this.minusButton.$element )
+                       .append( this.plusButton.$element );
+       }
+
+       // Initialization
+       this.setAllowInteger( config.allowInteger || config.isInteger );
+       this.setRange( config.min, config.max );
+       this.setStep( config.step, config.pageStep );
+       // Set the validation method after we set allowInteger and range
+       // so that it doesn't immediately call setValidityFlag
+       this.setValidation( this.validateNumber.bind( this ) );
+
+       this.$element
+               .addClass( 'oo-ui-numberInputWidget' )
+               .toggleClass( 'oo-ui-numberInputWidget-buttoned', config.showButtons )
+               .append( $field );
+};
+
+/* Setup */
+
+OO.inheritClass( OO.ui.NumberInputWidget, OO.ui.TextInputWidget );
+
+/* Methods */
+
+/**
+ * Set whether only integers are allowed
+ *
+ * @param {boolean} flag
+ */
+OO.ui.NumberInputWidget.prototype.setAllowInteger = function ( flag ) {
+       this.allowInteger = !!flag;
+       this.setValidityFlag();
+};
+// Backward compatibility
+OO.ui.NumberInputWidget.prototype.setIsInteger = OO.ui.NumberInputWidget.prototype.setAllowInteger;
+
+/**
+ * Get whether only integers are allowed
+ *
+ * @return {boolean} Flag value
+ */
+OO.ui.NumberInputWidget.prototype.getAllowInteger = function () {
+       return this.allowInteger;
+};
+// Backward compatibility
+OO.ui.NumberInputWidget.prototype.getIsInteger = OO.ui.NumberInputWidget.prototype.getAllowInteger;
+
+/**
+ * Set the range of allowed values
+ *
+ * @param {number} min Minimum allowed value
+ * @param {number} max Maximum allowed value
+ */
+OO.ui.NumberInputWidget.prototype.setRange = function ( min, max ) {
+       if ( min > max ) {
+               throw new Error( 'Minimum (' + min + ') must not be greater than maximum (' + max + ')' );
+       }
+       this.min = min;
+       this.max = max;
+       this.$input.attr( 'min', this.min );
+       this.$input.attr( 'max', this.max );
+       this.setValidityFlag();
+};
+
+/**
+ * Get the current range
+ *
+ * @return {number[]} Minimum and maximum values
+ */
+OO.ui.NumberInputWidget.prototype.getRange = function () {
+       return [ this.min, this.max ];
+};
+
+/**
+ * Set the stepping deltas
+ *
+ * @param {number} step Normal step
+ * @param {number|null} pageStep Page step. If null, 10 * step will be used.
+ */
+OO.ui.NumberInputWidget.prototype.setStep = function ( step, pageStep ) {
+       if ( step <= 0 ) {
+               throw new Error( 'Step value must be positive' );
+       }
+       if ( pageStep === null ) {
+               pageStep = step * 10;
+       } else if ( pageStep <= 0 ) {
+               throw new Error( 'Page step value must be positive' );
+       }
+       this.step = step;
+       this.pageStep = pageStep;
+       this.$input.attr( 'step', this.step );
+};
+
+/**
+ * @inheritdoc
+ */
+OO.ui.NumberInputWidget.prototype.setValue = function ( value ) {
+       if ( value === '' ) {
+               // Some browsers allow a value in the input even if there isn't one reported by $input.val()
+               // so here we make sure an 'empty' value is actually displayed as such.
+               this.$input.val( '' );
+       }
+       return OO.ui.NumberInputWidget.parent.prototype.setValue.call( this, value );
+};
+
+/**
+ * Get the current stepping values
+ *
+ * @return {number[]} Step and page step
+ */
+OO.ui.NumberInputWidget.prototype.getStep = function () {
+       return [ this.step, this.pageStep ];
+};
+
+/**
+ * Get the current value of the widget as a number
+ *
+ * @return {number} May be NaN, or an invalid number
+ */
+OO.ui.NumberInputWidget.prototype.getNumericValue = function () {
+       return +this.getValue();
+};
+
+/**
+ * Adjust the value of the widget
+ *
+ * @param {number} delta Adjustment amount
+ */
+OO.ui.NumberInputWidget.prototype.adjustValue = function ( delta ) {
+       var n, v = this.getNumericValue();
+
+       delta = +delta;
+       if ( isNaN( delta ) || !isFinite( delta ) ) {
+               throw new Error( 'Delta must be a finite number' );
+       }
+
+       if ( isNaN( v ) ) {
+               n = 0;
+       } else {
+               n = v + delta;
+               n = Math.max( Math.min( n, this.max ), this.min );
+               if ( this.allowInteger ) {
+                       n = Math.round( n );
+               }
+       }
+
+       if ( n !== v ) {
+               this.setValue( n );
+       }
+};
+/**
+ * Validate input
+ *
+ * @private
+ * @param {string} value Field value
+ * @return {boolean}
+ */
+OO.ui.NumberInputWidget.prototype.validateNumber = function ( value ) {
+       var n = +value;
+       if ( value === '' ) {
+               return !this.isRequired();
+       }
+
+       if ( isNaN( n ) || !isFinite( n ) ) {
+               return false;
+       }
+
+       if ( this.allowInteger && Math.floor( n ) !== n ) {
+               return false;
+       }
+
+       if ( n < this.min || n > this.max ) {
+               return false;
+       }
+
+       return true;
+};
+
+/**
+ * Handle mouse click events.
+ *
+ * @private
+ * @param {number} dir +1 or -1
+ */
+OO.ui.NumberInputWidget.prototype.onButtonClick = function ( dir ) {
+       this.adjustValue( dir * this.step );
+};
+
+/**
+ * Handle mouse wheel events.
+ *
+ * @private
+ * @param {jQuery.Event} event
+ */
+OO.ui.NumberInputWidget.prototype.onWheel = function ( event ) {
+       var delta = 0;
+
+       if ( !this.isDisabled() && this.$input.is( ':focus' ) ) {
+               // Standard 'wheel' event
+               if ( event.originalEvent.deltaMode !== undefined ) {
+                       this.sawWheelEvent = true;
+               }
+               if ( event.originalEvent.deltaY ) {
+                       delta = -event.originalEvent.deltaY;
+               } else if ( event.originalEvent.deltaX ) {
+                       delta = event.originalEvent.deltaX;
+               }
+
+               // Non-standard events
+               if ( !this.sawWheelEvent ) {
+                       if ( event.originalEvent.wheelDeltaX ) {
+                               delta = -event.originalEvent.wheelDeltaX;
+                       } else if ( event.originalEvent.wheelDeltaY ) {
+                               delta = event.originalEvent.wheelDeltaY;
+                       } else if ( event.originalEvent.wheelDelta ) {
+                               delta = event.originalEvent.wheelDelta;
+                       } else if ( event.originalEvent.detail ) {
+                               delta = -event.originalEvent.detail;
+                       }
+               }
+
+               if ( delta ) {
+                       delta = delta < 0 ? -1 : 1;
+                       this.adjustValue( delta * this.step );
+               }
+
+               return false;
+       }
+};
+
+/**
+ * Handle key down events.
+ *
+ * @private
+ * @param {jQuery.Event} e Key down event
+ */
+OO.ui.NumberInputWidget.prototype.onKeyDown = function ( e ) {
+       if ( !this.isDisabled() ) {
+               switch ( e.which ) {
+                       case OO.ui.Keys.UP:
+                               this.adjustValue( this.step );
+                               return false;
+                       case OO.ui.Keys.DOWN:
+                               this.adjustValue( -this.step );
+                               return false;
+                       case OO.ui.Keys.PAGEUP:
+                               this.adjustValue( this.pageStep );
+                               return false;
+                       case OO.ui.Keys.PAGEDOWN:
+                               this.adjustValue( -this.pageStep );
+                               return false;
+               }
+       }
+};
+
+/**
+ * @inheritdoc
+ */
+OO.ui.NumberInputWidget.prototype.setDisabled = function ( disabled ) {
+       // Parent method
+       OO.ui.NumberInputWidget.parent.prototype.setDisabled.call( this, disabled );
+
+       if ( this.minusButton ) {
+               this.minusButton.setDisabled( this.isDisabled() );
+       }
+       if ( this.plusButton ) {
+               this.plusButton.setDisabled( this.isDisabled() );
+       }
+
+       return this;
+};
+
 }( OO ) );
 
 //# sourceMappingURL=oojs-ui-core.js.map
\ No newline at end of file