Merge "Use Parser::SFH_NO_HASH/SFH_OBJECT_ARGS class const"
[lhc/web/wiklou.git] / resources / lib / oojs-ui / oojs-ui.js
index 7c0c343..d42139e 100644 (file)
@@ -1,12 +1,12 @@
 /*!
- * OOjs UI v0.1.0-pre (9ed4cf2557)
+ * OOjs UI v0.2.3
  * 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: 2014-11-22T01:21:13Z
+ * Date: 2014-11-26T23:37:00Z
  */
 ( function ( OO ) {
 
@@ -1756,11 +1756,20 @@ OO.ui.Window.prototype.getSize = function () {
  * @return {number} Content height
  */
 OO.ui.Window.prototype.getContentHeight = function () {
-       // Temporarily resize the frame so getBodyHeight() can use scrollHeight measurements
-       var bodyHeight, oldHeight = this.$frame[0].style.height;
-       this.$frame[0].style.height = '1px';
+       // Temporarily resize the frame so getBodyHeight() can use scrollHeight measurements.
+       // Disable transitions first, otherwise we'll get values from when the window was animating.
+       var bodyHeight, oldHeight, oldTransition,
+               styleObj = this.$frame[0].style;
+       oldTransition = styleObj.transition || styleObj.OTransition || styleObj.MsTransition ||
+               styleObj.MozTransition || styleObj.WebkitTransition;
+       styleObj.transition = styleObj.OTransition = styleObj.MsTransition =
+               styleObj.MozTransition = styleObj.WebkitTransition = 'none';
+       oldHeight = styleObj.height;
+       styleObj.height = '1px';
        bodyHeight = this.getBodyHeight();
-       this.$frame[0].style.height = oldHeight;
+       styleObj.height = oldHeight;
+       styleObj.transition = styleObj.OTransition = styleObj.MsTransition =
+               styleObj.MozTransition = styleObj.WebkitTransition = oldTransition;
 
        return Math.round(
                // Add buffer for border
@@ -2275,6 +2284,7 @@ OO.ui.Dialog = function OoUiDialog( config ) {
        this.actions = new OO.ui.ActionSet();
        this.attachedActions = [];
        this.currentAction = null;
+       this.onDocumentKeyDownHandler = this.onDocumentKeyDown.bind( this );
 
        // Events
        this.actions.connect( this, {
@@ -2438,6 +2448,10 @@ OO.ui.Dialog.prototype.getSetupProcess = function ( data ) {
                                );
                        }
                        this.actions.add( items );
+
+                       if ( this.constructor.static.escapable ) {
+                               this.$document.on( 'keydown', this.onDocumentKeyDownHandler );
+                       }
                }, this );
 };
 
@@ -2448,6 +2462,10 @@ OO.ui.Dialog.prototype.getTeardownProcess = function ( data ) {
        // Parent method
        return OO.ui.Dialog.super.prototype.getTeardownProcess.call( this, data )
                .first( function () {
+                       if ( this.constructor.static.escapable ) {
+                               this.$document.off( 'keydown', this.onDocumentKeyDownHandler );
+                       }
+
                        this.actions.clear();
                        this.currentAction = null;
                }, this );
@@ -2463,11 +2481,6 @@ OO.ui.Dialog.prototype.initialize = function () {
        // Properties
        this.title = new OO.ui.LabelWidget( { $: this.$ } );
 
-       // Events
-       if ( this.constructor.static.escapable ) {
-               this.$document.on( 'keydown', this.onDocumentKeyDown.bind( this ) );
-       }
-
        // Initialization
        this.$content.addClass( 'oo-ui-dialog-content' );
        this.setPendingElement( this.$head );
@@ -3444,7 +3457,15 @@ OO.inheritClass( OO.ui.ToolFactory, OO.Factory );
 
 /* Methods */
 
-/** */
+/**
+ * Get tools from the factory
+ *
+ * @param {Array} include Included tools
+ * @param {Array} exclude Excluded tools
+ * @param {Array} promote Promoted tools
+ * @param {Array} demote Demoted tools
+ * @return {string[]} List of tools
+ */
 OO.ui.ToolFactory.prototype.getTools = function ( include, exclude, promote, demote ) {
        var i, len, included, promoted, demoted,
                auto = [],
@@ -4541,7 +4562,6 @@ OO.ui.LabelElement.prototype.setLabelContent = function ( label ) {
        } else {
                this.$label.empty();
        }
-       this.$label.css( 'display', !label ? 'none' : '' );
 };
 
 /**
@@ -5909,7 +5929,7 @@ OO.ui.MessageDialog.static.actions = [
  */
 OO.ui.MessageDialog.prototype.onActionResize = function ( action ) {
        this.fitActions();
-       return OO.ui.ProcessDialog.super.prototype.onActionResize.call( this, action );
+       return OO.ui.MessageDialog.super.prototype.onActionResize.call( this, action );
 };
 
 /**
@@ -5976,7 +5996,45 @@ OO.ui.MessageDialog.prototype.getSetupProcess = function ( data ) {
  * @inheritdoc
  */
 OO.ui.MessageDialog.prototype.getBodyHeight = function () {
-       return Math.round( this.text.$element.outerHeight( true ) );
+       var bodyHeight, oldOverflow,
+               $scrollable = this.container.$element;
+
+       oldOverflow = $scrollable[0].style.overflow;
+       $scrollable[0].style.overflow = 'hidden';
+
+       // Force… ugh… something to happen
+       $scrollable.contents().hide();
+       $scrollable.height();
+       $scrollable.contents().show();
+
+       bodyHeight = Math.round( this.text.$element.outerHeight( true ) );
+       $scrollable[0].style.overflow = oldOverflow;
+
+       return bodyHeight;
+};
+
+/**
+ * @inheritdoc
+ */
+OO.ui.MessageDialog.prototype.setDimensions = function ( dim ) {
+       var $scrollable = this.container.$element;
+       OO.ui.MessageDialog.super.prototype.setDimensions.call( this, dim );
+
+       // Twiddle the overflow property, otherwise an unnecessary scrollbar will be produced.
+       // Need to do it after transition completes (250ms), add 50ms just in case.
+       setTimeout( function () {
+               var oldOverflow = $scrollable[0].style.overflow;
+               $scrollable[0].style.overflow = 'hidden';
+
+               // Force… ugh… something to happen
+               $scrollable.contents().hide();
+               $scrollable.height();
+               $scrollable.contents().show();
+
+               $scrollable[0].style.overflow = oldOverflow;
+       }, 300 );
+
+       return this;
 };
 
 /**
@@ -6035,10 +6093,9 @@ OO.ui.MessageDialog.prototype.attachActions = function () {
                special.primary.toggleFramed( false );
        }
 
+       this.manager.updateWindowSize( this );
        this.fitActions();
-       if ( !this.isOpening() ) {
-               this.manager.updateWindowSize( this );
-       }
+
        this.$body.css( 'bottom', this.$foot.outerHeight( true ) );
 };
 
@@ -6404,22 +6461,40 @@ OO.ui.BookletLayout.prototype.onStackLayoutFocus = function ( e ) {
  * @param {OO.ui.PanelLayout|null} page The page panel that is now the current panel
  */
 OO.ui.BookletLayout.prototype.onStackLayoutSet = function ( page ) {
-       var $input, layout = this;
+       var layout = this;
        if ( page ) {
                page.scrollElementIntoView( { complete: function () {
                        if ( layout.autoFocus ) {
-                               // Set focus to the first input if nothing on the page is focused yet
-                               if ( !page.$element.find( ':focus' ).length ) {
-                                       $input = page.$element.find( ':input:first' );
-                                       if ( $input.length ) {
-                                               $input[0].focus();
-                                       }
-                               }
+                               layout.focus();
                        }
                } } );
        }
 };
 
+/**
+ * Focus the first input in the current page.
+ *
+ * If no page is selected, the first selectable page will be selected.
+ * If the focus is already in an element on the current page, nothing will happen.
+ */
+OO.ui.BookletLayout.prototype.focus = function () {
+       var $input, page = this.stackLayout.getCurrentItem();
+       if ( !page && this.outlined ) {
+               this.selectFirstSelectablePage();
+               page = this.stackLayout.getCurrentItem();
+               if ( !page ) {
+                       return;
+               }
+       }
+       // Only change the focus if is not already in the current page
+       if ( !page.$element.find( ':focus' ).length ) {
+               $input = page.$element.find( ':input:first' );
+               if ( $input.length ) {
+                       $input[0].focus();
+               }
+       }
+};
+
 /**
  * Handle outline widget select events.
  *
@@ -6594,7 +6669,7 @@ OO.ui.BookletLayout.prototype.addPages = function ( pages, index ) {
 
        if ( this.outlined && items.length ) {
                this.outlineSelectWidget.addItems( items, index );
-               this.updateOutlineSelectWidget();
+               this.selectFirstSelectablePage();
        }
        this.stackLayout.addItems( pages, index );
        this.emit( 'add', pages, index );
@@ -6623,7 +6698,7 @@ OO.ui.BookletLayout.prototype.removePages = function ( pages ) {
        }
        if ( this.outlined && items.length ) {
                this.outlineSelectWidget.removeItems( items );
-               this.updateOutlineSelectWidget();
+               this.selectFirstSelectablePage();
        }
        this.stackLayout.removeItems( pages );
        this.emit( 'remove', pages );
@@ -6696,12 +6771,11 @@ OO.ui.BookletLayout.prototype.setPage = function ( name ) {
 };
 
 /**
- * Call this after adding or removing items from the OutlineSelectWidget.
+ * Select the first selectable page.
  *
  * @chainable
  */
-OO.ui.BookletLayout.prototype.updateOutlineSelectWidget = function () {
-       // Auto-select first item when nothing is selected anymore
+OO.ui.BookletLayout.prototype.selectFirstSelectablePage = function () {
        if ( !this.outlineSelectWidget.getSelectedItem() ) {
                this.outlineSelectWidget.selectItem( this.outlineSelectWidget.getFirstSelectableItem() );
        }
@@ -9732,7 +9806,7 @@ OO.ui.TextInputWidget.prototype.onIndicatorMouseDown = function ( e ) {
  */
 OO.ui.TextInputWidget.prototype.onKeyPress = function ( e ) {
        if ( e.which === OO.ui.Keys.ENTER && !this.multiline ) {
-               this.emit( 'enter' );
+               this.emit( 'enter', e );
        }
 };
 
@@ -10053,6 +10127,7 @@ OO.ui.ComboBoxWidget.prototype.setDisabled = function ( disabled ) {
  *
  * @constructor
  * @param {Object} [config] Configuration options
+ * @cfg {OO.ui.InputWidget} [input] Input widget this label is for
  */
 OO.ui.LabelWidget = function OoUiLabelWidget( config ) {
        // Configuration initialization
@@ -10377,7 +10452,6 @@ OO.ui.ButtonOptionWidget.prototype.setSelected = function ( state ) {
  *
  * @class
  * @extends OO.ui.OptionWidget
- * @mixins OO.ui.ButtonElement
  *
  * @constructor
  * @param {Object} [config] Configuration options