Update OOUI to v0.33.4
[lhc/web/wiklou.git] / resources / lib / ooui / oojs-ui-windows.js
index 59b2c0c..d6f9989 100644 (file)
@@ -1,12 +1,12 @@
 /*!
- * OOUI v0.32.1
+ * OOUI v0.33.4
  * https://www.mediawiki.org/wiki/OOUI
  *
  * Copyright 2011–2019 OOUI Team and other contributors.
  * Released under the MIT license
  * http://oojs.mit-license.org
  *
- * Date: 2019-06-05T16:24:08Z
+ * Date: 2019-07-23T03:23:32Z
  */
 ( function ( OO ) {
 
@@ -120,10 +120,12 @@ OO.ui.ActionWidget.prototype.getModes = function () {
  *     MyProcessDialog.static.name = 'myProcessDialog';
  *     // An action set that uses modes ('edit' and 'help' mode, in this example).
  *     MyProcessDialog.static.actions = [
- *         { action: 'continue', modes: 'edit', label: 'Continue',
- *           flags: [
- *               'primary', 'progressive'
- *         ] },
+ *         {
+ *           action: 'continue',
+ *           modes: 'edit',
+ *           label: 'Continue',
+ *           flags: [ 'primary', 'progressive' ]
+ *         },
  *         { action: 'help', modes: 'edit', label: 'Help' },
  *         { modes: 'edit', label: 'Cancel', flags: 'safe' },
  *         { action: 'back', modes: 'help', label: 'Back', flags: 'safe' }
@@ -1413,6 +1415,7 @@ OO.ui.WindowManager.prototype.openWindow = function ( win, data, lifecycle, comp
                                                compatOpening.notify( { state: 'ready' } );
                                                lifecycle.deferreds.opened.resolve( data );
                                                compatOpening.resolve( manager.compatOpened.promise(), data );
+                                               manager.togglePreventIosScrolling( true );
                                        }, function () {
                                                lifecycle.deferreds.opened.reject();
                                                compatOpening.reject();
@@ -1503,6 +1506,7 @@ OO.ui.WindowManager.prototype.closeWindow = function ( win, data ) {
                compatOpened = manager.compatOpened;
                manager.compatOpened = null;
                compatOpened.resolve( compatClosing.promise(), data );
+               manager.togglePreventIosScrolling( false );
                setTimeout( function () {
                        win.hold( data ).then( function () {
                                compatClosing.notify( { state: 'hold' } );
@@ -1676,6 +1680,47 @@ OO.ui.WindowManager.prototype.updateWindowSize = function ( win ) {
        return this;
 };
 
+/**
+ * Prevent scrolling of the document on iOS devices that don't respect `body { overflow: hidden; }`.
+ *
+ * This function is called when the window is opened (ready), and so the background is covered up,
+ * and the user won't see that we're doing weird things to the scroll position.
+ *
+ * @private
+ * @param {boolean} on
+ * @chainable
+ * @return {OO.ui.WindowManager} The manager, for chaining
+ */
+OO.ui.WindowManager.prototype.togglePreventIosScrolling = function ( on ) {
+       var
+               isIos = /ipad|iphone|ipod/i.test( navigator.userAgent ),
+               $body = $( this.getElementDocument().body ),
+               scrollableRoot = OO.ui.Element.static.getRootScrollableElement( $body[ 0 ] ),
+               stackDepth = $body.data( 'windowManagerGlobalEvents' ) || 0;
+
+       // Only if this is the first/last WindowManager (see #toggleGlobalEvents)
+       if ( !isIos || stackDepth !== 1 ) {
+               return this;
+       }
+
+       if ( on ) {
+               // We can't apply this workaround for non-fullscreen dialogs, because the user would see the
+               // scroll position change. If they have content that needs scrolling, you're out of luck…
+               // Always remember the scroll position in case dialog is closed with different size.
+               this.iosOrigScrollPosition = scrollableRoot.scrollTop;
+               if ( this.getCurrentWindow().getSize() === 'full' ) {
+                       $body.add( $body.parent() ).addClass( 'oo-ui-windowManager-ios-modal-ready' );
+               }
+       } else {
+               // Always restore ability to scroll in case dialog was opened with different size.
+               $body.add( $body.parent() ).removeClass( 'oo-ui-windowManager-ios-modal-ready' );
+               if ( this.getCurrentWindow().getSize() === 'full' ) {
+                       scrollableRoot.scrollTop = this.iosOrigScrollPosition;
+               }
+       }
+       return this;
+};
+
 /**
  * Bind or unbind global events for scrolling.
  *
@@ -3234,6 +3279,9 @@ OO.ui.ProcessDialog = function OoUiProcessDialog( config ) {
 
        // Initialization
        this.$element.addClass( 'oo-ui-processDialog' );
+       if ( OO.ui.isMobile() ) {
+               this.$element.addClass( 'oo-ui-isMobile' );
+       }
 };
 
 /* Setup */
@@ -3328,21 +3376,23 @@ OO.ui.ProcessDialog.prototype.initialize = function () {
  * @inheritdoc
  */
 OO.ui.ProcessDialog.prototype.getActionWidgetConfig = function ( config ) {
-       var isMobile = OO.ui.isMobile();
-
-       // Default to unframed on mobile
-       config = $.extend( { framed: !isMobile }, config );
-       // Change back buttons to icon only on mobile
-       if (
-               isMobile &&
-               (
-                       config.flags === 'back' ||
-                       ( Array.isArray( config.flags ) && config.flags.indexOf( 'back' ) !== -1 )
-               )
-       ) {
+       function checkFlag( flag ) {
+               return config.flags === flag ||
+                       ( Array.isArray( config.flags ) && config.flags.indexOf( flag ) !== -1 );
+       }
+
+       config = $.extend( { framed: true }, config );
+       if ( checkFlag( 'close' ) ) {
+               // Change close buttons to icon only.
+               $.extend( config, {
+                       icon: 'close',
+                       invisibleLabel: true
+               } );
+       } else if ( checkFlag( 'back' ) ) {
+               // Change back buttons to icon only.
                $.extend( config, {
                        icon: 'previous',
-                       label: ''
+                       invisibleLabel: true
                } );
        }
 
@@ -3433,13 +3483,13 @@ OO.ui.ProcessDialog.prototype.fitLabel = function () {
                navigationWidth = size.width - 20;
        }
 
-       safeWidth = this.$safeActions.is( ':visible' ) ? this.$safeActions.width() : 0;
-       primaryWidth = this.$primaryActions.is( ':visible' ) ? this.$primaryActions.width() : 0;
+       safeWidth = this.$safeActions.width();
+       primaryWidth = this.$primaryActions.width();
        biggerWidth = Math.max( safeWidth, primaryWidth );
 
        labelWidth = this.title.$element.width();
 
-       if ( 2 * biggerWidth + labelWidth < navigationWidth ) {
+       if ( !OO.ui.isMobile() && 2 * biggerWidth + labelWidth < navigationWidth ) {
                // We have enough space to center the label
                leftWidth = rightWidth = biggerWidth;
        } else {