Update OOjs UI to v0.1.0-pre (b9d403a678)
[lhc/web/wiklou.git] / resources / lib / oojs-ui / oojs-ui.js
index 7e3aadf..990d955 100644 (file)
@@ -1,16 +1,17 @@
 /*!
- * OOjs UI v0.1.0-pre (7a0e222a75)
+ * OOjs UI v0.1.0-pre (b9d403a678)
  * https://www.mediawiki.org/wiki/OOjs_UI
  *
  * Copyright 2011–2014 OOjs Team and other contributors.
  * Released under the MIT license
  * http://oojs.mit-license.org
  *
- * Date: Wed Jun 18 2014 16:19:15 GMT-0700 (PDT)
+ * Date: 2014-06-26T23:45:59Z
  */
 ( function ( OO ) {
 
 'use strict';
+
 /**
  * Namespace for all classes, static methods and static properties.
  *
@@ -94,84 +95,85 @@ OO.ui.getLocalValue = function ( obj, lang, fallback ) {
 
 ( function () {
 
-/**
- * Message store for the default implementation of OO.ui.msg
- *
- * Environments that provide a localization system should not use this, but should override
- * OO.ui.msg altogether.
- *
- * @private
- */
-var messages = {
-       // Label text for button to exit from dialog
-       'ooui-dialog-action-close': 'Close',
-       // Tool tip for a button that moves items in a list down one place
-       'ooui-outline-control-move-down': 'Move item down',
-       // Tool tip for a button that moves items in a list up one place
-       'ooui-outline-control-move-up': 'Move item up',
-       // Tool tip for a button that removes items from a list
-       'ooui-outline-control-remove': 'Remove item',
-       // Label for the toolbar group that contains a list of all other available tools
-       'ooui-toolbar-more': 'More',
-
-       // Label for the generic dialog used to confirm things
-       'ooui-dialog-confirm-title': 'Confirm',
-       // The default prompt of a confirmation dialog
-       'ooui-dialog-confirm-default-prompt': 'Are you sure?',
-       // The default OK button text on a confirmation dialog
-       'ooui-dialog-confirm-default-ok': 'OK',
-       // The default cancel button text on a confirmation dialog
-       'ooui-dialog-confirm-default-cancel': 'Cancel'
-};
+       /**
       * Message store for the default implementation of OO.ui.msg
       *
       * Environments that provide a localization system should not use this, but should override
       * OO.ui.msg altogether.
       *
       * @private
       */
+       var messages = {
+               // Label text for button to exit from dialog
+               'ooui-dialog-action-close': 'Close',
+               // Tool tip for a button that moves items in a list down one place
+               'ooui-outline-control-move-down': 'Move item down',
+               // Tool tip for a button that moves items in a list up one place
+               'ooui-outline-control-move-up': 'Move item up',
+               // Tool tip for a button that removes items from a list
+               'ooui-outline-control-remove': 'Remove item',
+               // Label for the toolbar group that contains a list of all other available tools
+               'ooui-toolbar-more': 'More',
+
+               // Label for the generic dialog used to confirm things
+               'ooui-dialog-confirm-title': 'Confirm',
+               // The default prompt of a confirmation dialog
+               'ooui-dialog-confirm-default-prompt': 'Are you sure?',
+               // The default OK button text on a confirmation dialog
+               'ooui-dialog-confirm-default-ok': 'OK',
+               // The default cancel button text on a confirmation dialog
+               'ooui-dialog-confirm-default-cancel': 'Cancel'
+       };
 
-/**
- * Get a localized message.
- *
- * In environments that provide a localization system, this function should be overridden to
- * return the message translated in the user's language. The default implementation always returns
- * English messages.
- *
- * After the message key, message parameters may optionally be passed. In the default implementation,
- * any occurrences of $1 are replaced with the first parameter, $2 with the second parameter, etc.
- * Alternative implementations of OO.ui.msg may use any substitution system they like, as long as
- * they support unnamed, ordered message parameters.
- *
- * @abstract
- * @param {string} key Message key
- * @param {Mixed...} [params] Message parameters
- * @return {string} Translated message with parameters substituted
- */
-OO.ui.msg = function ( key ) {
-       var message = messages[key], params = Array.prototype.slice.call( arguments, 1 );
-       if ( typeof message === 'string' ) {
-               // Perform $1 substitution
-               message = message.replace( /\$(\d+)/g, function ( unused, n ) {
-                       var i = parseInt( n, 10 );
-                       return params[i - 1] !== undefined ? params[i - 1] : '$' + n;
-               } );
-       } else {
-               // Return placeholder if message not found
-               message = '[' + key + ']';
-       }
-       return message;
-};
+       /**
       * Get a localized message.
       *
       * In environments that provide a localization system, this function should be overridden to
       * return the message translated in the user's language. The default implementation always returns
       * English messages.
       *
       * After the message key, message parameters may optionally be passed. In the default implementation,
       * any occurrences of $1 are replaced with the first parameter, $2 with the second parameter, etc.
       * Alternative implementations of OO.ui.msg may use any substitution system they like, as long as
       * they support unnamed, ordered message parameters.
       *
       * @abstract
       * @param {string} key Message key
       * @param {Mixed...} [params] Message parameters
       * @return {string} Translated message with parameters substituted
       */
+       OO.ui.msg = function ( key ) {
+               var message = messages[key], params = Array.prototype.slice.call( arguments, 1 );
+               if ( typeof message === 'string' ) {
+                       // Perform $1 substitution
+                       message = message.replace( /\$(\d+)/g, function ( unused, n ) {
+                               var i = parseInt( n, 10 );
+                               return params[i - 1] !== undefined ? params[i - 1] : '$' + n;
+                       } );
+               } else {
+                       // Return placeholder if message not found
+                       message = '[' + key + ']';
+               }
+               return message;
+       };
 
-/** */
-OO.ui.deferMsg = function ( key ) {
-       return function () {
-               return OO.ui.msg( key );
+       /** */
+       OO.ui.deferMsg = function ( key ) {
+               return function () {
+                       return OO.ui.msg( key );
+               };
        };
-};
 
-/** */
-OO.ui.resolveMsg = function ( msg ) {
-       if ( $.isFunction( msg ) ) {
-               return msg();
-       }
-       return msg;
-};
+       /** */
+       OO.ui.resolveMsg = function ( msg ) {
+               if ( $.isFunction( msg ) ) {
+                       return msg();
+               }
+               return msg;
+       };
 
 } )();
+
 /**
  * DOM element abstraction.
  *
@@ -669,6 +671,7 @@ OO.ui.Element.prototype.offDOMEvent = function ( event, callback ) {
                $( el ).off( event, callback );
        };
 }() );
+
 /**
  * Embedded iframe with the same styles as its parent.
  *
@@ -899,6 +902,7 @@ OO.ui.Frame.prototype.setSize = function ( width, height ) {
        this.$element.css( { 'width': width, 'height': height } );
        return this;
 };
+
 /**
  * Container for elements in a child frame.
  *
@@ -1286,8 +1290,8 @@ OO.ui.Window.prototype.open = function ( data ) {
        // Open the window
        this.opening = $.Deferred();
 
-       // So we can restore focus on closing
-       this.$prevFocus = $( document.activeElement );
+       this.$ariaHidden = $( 'body' ).children().not( this.$element.parentsUntil( 'body' ).last() )
+               .attr( 'aria-hidden', '' );
 
        this.frame.load().done( OO.ui.bind( function () {
                this.$element.show();
@@ -1352,10 +1356,9 @@ OO.ui.Window.prototype.close = function ( data ) {
                        this.opened.resolve();
                }
                this.$element.hide();
-               // Restore focus to whatever was focused before opening
-               if ( this.$prevFocus ) {
-                       this.$prevFocus.focus();
-                       this.$prevFocus = undefined;
+               if ( this.$ariaHidden ) {
+                       this.$ariaHidden.removeAttr( 'aria-hidden' );
+                       this.$ariaHidden = undefined;
                }
                this.visible = false;
                this.closing.resolve();
@@ -1365,6 +1368,7 @@ OO.ui.Window.prototype.close = function ( data ) {
 
        return this.closing.promise();
 };
+
 /**
  * Set of mutually exclusive windows.
  *
@@ -1530,6 +1534,7 @@ OO.ui.WindowSet.prototype.addWindow = function ( win ) {
        } );
        this.$element.append( win.$element );
 };
+
 /**
  * Modal dialog window.
  *
@@ -1762,6 +1767,7 @@ OO.ui.Dialog.prototype.popPending = function () {
 
        return this;
 };
+
 /**
  * Container for elements.
  *
@@ -1791,6 +1797,7 @@ OO.ui.Layout = function OoUiLayout( config ) {
 
 OO.inheritClass( OO.ui.Layout, OO.ui.Element );
 OO.mixinClass( OO.ui.Layout, OO.EventEmitter );
+
 /**
  * User interface control.
  *
@@ -1876,6 +1883,7 @@ OO.ui.Widget.prototype.setDisabled = function ( disabled ) {
        this.wasDisabled = isDisabled;
        return this;
 };
+
 /**
  * A list of functions, called in sequence.
  *
@@ -1992,6 +2000,7 @@ OO.ui.Process.prototype.next = function ( step, context ) {
        this.steps.push( [ step, context || null ] );
        return this;
 };
+
 /**
  * Dialog for showing a confirmation/warning message.
  *
@@ -2052,8 +2061,6 @@ OO.ui.ConfirmationDialog.prototype.initialize = function () {
                this.okButton.$element,
                this.cancelButton.$element
        );
-
-       this.connect( this, { 'teardown': [ 'close', 'cancel' ] } );
 };
 
 /*
@@ -2097,11 +2104,12 @@ OO.ui.ConfirmationDialog.prototype.getTeardownProcess = function ( data ) {
                .first( function () {
                        if ( data === 'ok' ) {
                                this.opened.resolve();
-                       } else if ( data === 'cancel' ) {
+                       } else { // data === 'cancel', or no data
                                this.opened.reject();
                        }
                }, this );
 };
+
 /**
  * Element with a button.
  *
@@ -2209,6 +2217,7 @@ OO.ui.ButtonedElement.prototype.setActive = function ( value ) {
        this.$button.toggleClass( 'oo-ui-buttonedElement-active', !!value );
        return this;
 };
+
 /**
  * Element that can be automatically clipped to visible boundaies.
  *
@@ -2336,18 +2345,23 @@ OO.ui.ClippableElement.prototype.clip = function () {
        if ( clipWidth ) {
                this.$clippable.css( { 'overflow-x': 'auto', 'width': desiredWidth } );
        } else {
-               this.$clippable.css( { 'overflow-x': '', 'width': this.idealWidth || '' } );
+               this.$clippable.css( 'width', this.idealWidth || '' );
+               this.$clippable.width(); // Force reflow for https://code.google.com/p/chromium/issues/detail?id=387290
+               this.$clippable.css( 'overflow-x', '' );
        }
        if ( clipHeight ) {
                this.$clippable.css( { 'overflow-y': 'auto', 'height': desiredHeight } );
        } else {
-               this.$clippable.css( { 'overflow-y': '', 'height': this.idealHeight || '' } );
+               this.$clippable.css( 'height', this.idealHeight || '' );
+               this.$clippable.height(); // Force reflow for https://code.google.com/p/chromium/issues/detail?id=387290
+               this.$clippable.css( 'overflow-y', '' );
        }
 
        this.clipped = clipWidth || clipHeight;
 
        return this;
 };
+
 /**
  * Element with named flags that can be added, removed, listed and checked.
  *
@@ -2447,6 +2461,7 @@ OO.ui.FlaggableElement.prototype.setFlags = function ( flags ) {
        }
        return this;
 };
+
 /**
  * Element containing a sequence of child elements.
  *
@@ -2645,6 +2660,7 @@ OO.ui.GroupElement.prototype.clearItems = function () {
        this.items = [];
        return this;
 };
+
 /**
  * Element containing an icon.
  *
@@ -2732,6 +2748,7 @@ OO.ui.IconedElement.prototype.setIcon = function ( icon ) {
 OO.ui.IconedElement.prototype.getIcon = function () {
        return this.icon;
 };
+
 /**
  * Element containing an indicator.
  *
@@ -2845,6 +2862,7 @@ OO.ui.IndicatedElement.prototype.getIndicator = function () {
 OO.ui.IndicatedElement.prototype.getIndicatorTitle = function () {
        return this.indicatorTitle;
 };
+
 /**
  * Element containing a label.
  *
@@ -2943,6 +2961,7 @@ OO.ui.LabeledElement.prototype.fitLabel = function () {
        }
        return this;
 };
+
 /**
  * Popuppable element.
  *
@@ -2993,6 +3012,7 @@ OO.ui.PopuppableElement.prototype.showPopup = function () {
 OO.ui.PopuppableElement.prototype.hidePopup = function () {
        this.popup.hide();
 };
+
 /**
  * Element with a title.
  *
@@ -3059,6 +3079,7 @@ OO.ui.TitledElement.prototype.setTitle = function ( title ) {
 OO.ui.TitledElement.prototype.getTitle = function () {
        return this.title;
 };
+
 /**
  * Generic toolbar tool.
  *
@@ -3310,6 +3331,7 @@ OO.ui.Tool.prototype.destroy = function () {
        this.toolbar.disconnect( this );
        this.$element.remove();
 };
+
 /**
  * Collection of tool groups.
  *
@@ -3518,6 +3540,7 @@ OO.ui.Toolbar.prototype.releaseTool = function ( tool ) {
 OO.ui.Toolbar.prototype.getToolAccelerator = function () {
        return undefined;
 };
+
 /**
  * Factory for tools.
  *
@@ -3630,6 +3653,7 @@ OO.ui.ToolFactory.prototype.extract = function ( collection, used ) {
        }
        return names;
 };
+
 /**
  * Collection of tools.
  *
@@ -3948,6 +3972,7 @@ OO.ui.ToolGroup.prototype.destroy = function () {
        }
        this.$element.remove();
 };
+
 /**
  * Factory for tool groups.
  *
@@ -3986,6 +4011,7 @@ OO.ui.ToolGroupFactory.static.getDefaultClasses = function () {
                OO.ui.MenuToolGroup
        ];
 };
+
 /**
  * Layout made of a fieldset and optional legend.
  *
@@ -4033,6 +4059,7 @@ OO.mixinClass( OO.ui.FieldsetLayout, OO.ui.GroupElement );
 /* Static Properties */
 
 OO.ui.FieldsetLayout.static.tagName = 'div';
+
 /**
  * Layout made of a field and optional label.
  *
@@ -4148,6 +4175,7 @@ OO.ui.FieldLayout.prototype.setAlignment = function ( value ) {
 
        return this;
 };
+
 /**
  * Layout made of proportionally sized columns and rows.
  *
@@ -4308,6 +4336,7 @@ OO.ui.GridLayout.prototype.update = function () {
 OO.ui.GridLayout.prototype.getPanel = function ( x, y ) {
        return this.panels[( x * this.widths.length ) + y];
 };
+
 /**
  * Layout containing a series of pages.
  *
@@ -4726,6 +4755,7 @@ OO.ui.BookletLayout.prototype.updateOutlineWidget = function () {
 
        return this;
 };
+
 /**
  * Layout that expands to cover the entire area of its parent, with optional scrolling and padding.
  *
@@ -4758,6 +4788,7 @@ OO.ui.PanelLayout = function OoUiPanelLayout( config ) {
 /* Setup */
 
 OO.inheritClass( OO.ui.PanelLayout, OO.ui.Layout );
+
 /**
  * Page within an booklet layout.
  *
@@ -4851,6 +4882,7 @@ OO.ui.PageLayout.prototype.setActive = function ( active ) {
                this.emit( 'active', this.active );
        }
 };
+
 /**
  * Layout containing a series of mutually exclusive pages.
  *
@@ -5021,6 +5053,7 @@ OO.ui.StackLayout.prototype.setItem = function ( item ) {
 
        return this;
 };
+
 /**
  * Horizontal bar layout of tools as icon buttons.
  *
@@ -5050,6 +5083,7 @@ OO.ui.BarToolGroup.static.titleTooltips = true;
 OO.ui.BarToolGroup.static.accelTooltips = true;
 
 OO.ui.BarToolGroup.static.name = 'bar';
+
 /**
  * Popup list of tools with an icon and optional label.
  *
@@ -5202,6 +5236,7 @@ OO.ui.PopupToolGroup.prototype.setActive = function ( value ) {
                }
        }
 };
+
 /**
  * Drop down list layout of tools as labeled icon buttons.
  *
@@ -5229,6 +5264,7 @@ OO.inheritClass( OO.ui.ListToolGroup, OO.ui.PopupToolGroup );
 OO.ui.ListToolGroup.static.accelTooltips = true;
 
 OO.ui.ListToolGroup.static.name = 'list';
+
 /**
  * Drop down menu layout of tools as selectable menu items.
  *
@@ -5283,6 +5319,7 @@ OO.ui.MenuToolGroup.prototype.onUpdateState = function () {
 
        this.setLabel( labelTexts.join( ', ' ) || ' ' );
 };
+
 /**
  * Tool that shows a popup when selected.
  *
@@ -5340,6 +5377,7 @@ OO.ui.PopupTool.prototype.onSelect = function () {
 OO.ui.PopupTool.prototype.onUpdateState = function () {
        this.setActive( false );
 };
+
 /**
  * Group widget.
  *
@@ -5390,6 +5428,7 @@ OO.ui.GroupWidget.prototype.setDisabled = function ( disabled ) {
 
        return this;
 };
+
 /**
  * Item widget.
  *
@@ -5434,6 +5473,7 @@ OO.ui.ItemWidget.prototype.setElementGroup = function ( group ) {
 
        return this;
 };
+
 /**
  * Icon widget.
  *
@@ -5469,6 +5509,7 @@ OO.mixinClass( OO.ui.IconWidget, OO.ui.TitledElement );
 /* Static Properties */
 
 OO.ui.IconWidget.static.tagName = 'span';
+
 /**
  * Indicator widget.
  *
@@ -5504,6 +5545,7 @@ OO.mixinClass( OO.ui.IndicatorWidget, OO.ui.TitledElement );
 /* Static Properties */
 
 OO.ui.IndicatorWidget.static.tagName = 'span';
+
 /**
  * Container for multiple related buttons.
  *
@@ -5535,6 +5577,7 @@ OO.ui.ButtonGroupWidget = function OoUiButtonGroupWidget( config ) {
 
 OO.inheritClass( OO.ui.ButtonGroupWidget, OO.ui.Widget );
 OO.mixinClass( OO.ui.ButtonGroupWidget, OO.ui.GroupElement );
+
 /**
  * Button widget.
  *
@@ -5635,6 +5678,7 @@ OO.ui.ButtonWidget.prototype.onKeyPress = function ( e ) {
        }
        return false;
 };
+
 /**
  * Input widget.
  *
@@ -5830,6 +5874,7 @@ OO.ui.InputWidget.prototype.focus = function () {
        this.$input.focus();
        return this;
 };
+
 /**
  * Checkbox widget.
  *
@@ -5896,6 +5941,7 @@ OO.ui.CheckboxInputWidget.prototype.onEdit = function () {
                }, this ) );
        }
 };
+
 /**
  * Label widget.
  *
@@ -5948,6 +5994,7 @@ OO.ui.LabelWidget.prototype.onClick = function () {
        this.input.simulateLabelClick();
        return false;
 };
+
 /**
  * Lookup input widget.
  *
@@ -6181,6 +6228,7 @@ OO.ui.LookupInputWidget.prototype.getLookupMenuItemsFromData = function () {
        // Stub, implemented in subclass
        return [];
 };
+
 /**
  * Option widget.
  *
@@ -6398,6 +6446,7 @@ OO.ui.OptionWidget.prototype.flash = function () {
 OO.ui.OptionWidget.prototype.getData = function () {
        return this.data;
 };
+
 /**
  * Selection of options.
  *
@@ -6909,6 +6958,7 @@ OO.ui.SelectWidget.prototype.clearItems = function () {
 
        return this;
 };
+
 /**
  * Menu item widget.
  *
@@ -6935,6 +6985,7 @@ OO.ui.MenuItemWidget = function OoUiMenuItemWidget( data, config ) {
 /* Setup */
 
 OO.inheritClass( OO.ui.MenuItemWidget, OO.ui.OptionWidget );
+
 /**
  * Menu widget.
  *
@@ -7192,6 +7243,7 @@ OO.ui.MenuWidget.prototype.hide = function () {
 
        return this;
 };
+
 /**
  * Inline menu of options.
  *
@@ -7299,6 +7351,7 @@ OO.ui.InlineMenuWidget.prototype.onClick = function ( e ) {
        }
        return false;
 };
+
 /**
  * Menu section item widget.
  *
@@ -7328,6 +7381,7 @@ OO.inheritClass( OO.ui.MenuSectionItemWidget, OO.ui.OptionWidget );
 OO.ui.MenuSectionItemWidget.static.selectable = false;
 
 OO.ui.MenuSectionItemWidget.static.highlightable = false;
+
 /**
  * Create an OO.ui.OutlineWidget object.
  *
@@ -7353,6 +7407,7 @@ OO.ui.OutlineWidget = function OoUiOutlineWidget( config ) {
 /* Setup */
 
 OO.inheritClass( OO.ui.OutlineWidget, OO.ui.SelectWidget );
+
 /**
  * Creates an OO.ui.OutlineControlsWidget object.
  *
@@ -7466,6 +7521,7 @@ OO.ui.OutlineControlsWidget.prototype.onOutlineChange = function () {
        this.downButton.setDisabled( !movable || selectedItem === lastMovable );
        this.removeButton.setDisabled( !removable );
 };
+
 /**
  * Creates an OO.ui.OutlineItemWidget object.
  *
@@ -7592,6 +7648,7 @@ OO.ui.OutlineItemWidget.prototype.setLevel = function ( level ) {
 
        return this;
 };
+
 /**
  * Option widget that looks like a button.
  *
@@ -7645,6 +7702,7 @@ OO.ui.ButtonOptionWidget.prototype.setSelected = function ( state ) {
 
        return this;
 };
+
 /**
  * Select widget containing button options.
  *
@@ -7667,6 +7725,7 @@ OO.ui.ButtonSelectWidget = function OoUiButtonSelectWidget( config ) {
 /* Setup */
 
 OO.inheritClass( OO.ui.ButtonSelectWidget, OO.ui.SelectWidget );
+
 /**
  * Container for content that is overlaid and positioned absolutely.
  *
@@ -7912,6 +7971,7 @@ OO.ui.PopupWidget.prototype.display = function ( width, height, transition ) {
 
        return this;
 };
+
 /**
  * Button that shows and hides a popup.
  *
@@ -7963,6 +8023,7 @@ OO.ui.PopupButtonWidget.prototype.onClick = function ( e ) {
        }
        return false;
 };
+
 /**
  * Search widget.
  *
@@ -8116,6 +8177,7 @@ OO.ui.SearchWidget.prototype.getQuery = function () {
 OO.ui.SearchWidget.prototype.getResults = function () {
        return this.results;
 };
+
 /**
  * Text input widget.
  *
@@ -8328,6 +8390,7 @@ OO.ui.TextInputWidget.prototype.select = function () {
        this.$input.select();
        return this;
 };
+
 /**
  * Menu for a text input widget.
  *
@@ -8428,6 +8491,7 @@ OO.ui.TextInputMenuWidget.prototype.position = function () {
        this.setIdealSize( $container.width() );
        return this;
 };
+
 /**
  * Width with on and off states.
  *
@@ -8487,6 +8551,7 @@ OO.ui.ToggleWidget.prototype.setValue = function ( value ) {
        }
        return this;
 };
+
 /**
  * Button that toggles on and off.
  *
@@ -8545,6 +8610,7 @@ OO.ui.ToggleButtonWidget.prototype.setValue = function ( value ) {
 
        return this;
 };
+
 /**
  * Switch that slides on and off.
  *
@@ -8598,4 +8664,7 @@ OO.ui.ToggleSwitchWidget.prototype.onClick = function ( e ) {
                this.setValue( !this.value );
        }
 };
+
 }( OO ) );
+
+//# sourceMappingURL=oojs-ui.js.map
\ No newline at end of file