Update OOjs UI to v0.22.3
[lhc/web/wiklou.git] / resources / lib / oojs-ui / oojs-ui-windows.js
index 62a0633..b8e6cd1 100644 (file)
@@ -1,12 +1,12 @@
 /*!
- * OOjs UI v0.22.2
+ * OOjs UI v0.22.3
  * https://www.mediawiki.org/wiki/OOjs_UI
  *
  * Copyright 2011–2017 OOjs UI Team and other contributors.
  * Released under the MIT license
  * http://oojs.mit-license.org
  *
- * Date: 2017-06-28T19:51:59Z
+ * Date: 2017-07-11T22:12:33Z
  */
 ( function ( OO ) {
 
@@ -912,6 +912,44 @@ OO.ui.WindowInstance = function OOuiWindowInstance() {
 
 OO.initClass( OO.ui.WindowInstance );
 
+/**
+ * Check if window is opening.
+ *
+ * @return {boolean} Window is opening
+ */
+OO.ui.WindowInstance.prototype.isOpening = function () {
+       return this.deferreds.opened.state() === 'pending';
+};
+
+/**
+ * Check if window is opened.
+ *
+ * @return {boolean} Window is opened
+ */
+OO.ui.WindowInstance.prototype.isOpened = function () {
+       return this.deferreds.opened.state() === 'resolved' &&
+               this.deferreds.closing.state() === 'pending';
+};
+
+/**
+ * Check if window is closing.
+ *
+ * @return {boolean} Window is closing
+ */
+OO.ui.WindowInstance.prototype.isClosing = function () {
+       return this.deferreds.closing.state() === 'resolved' &&
+               this.deferreds.closed.state() === 'pending';
+};
+
+/**
+ * Check if window is closed.
+ *
+ * @return {boolean} Window is closed
+ */
+OO.ui.WindowInstance.prototype.isClosed = function () {
+       return this.deferreds.closed.state() === 'resolved';
+};
+
 /**
  * Window managers are used to open and close {@link OO.ui.Window windows} and control their presentation.
  * Managed windows are mutually exclusive. If a new window is opened while a current window is opening
@@ -1108,7 +1146,7 @@ OO.ui.WindowManager.prototype.afterWindowResize = function () {
  */
 OO.ui.WindowManager.prototype.isOpening = function ( win ) {
        return win === this.currentWindow && !!this.lifecycle &&
-               this.lifecycle.opened.state() === 'pending';
+               this.lifecycle.isOpening();
 };
 
 /**
@@ -1119,8 +1157,7 @@ OO.ui.WindowManager.prototype.isOpening = function ( win ) {
  */
 OO.ui.WindowManager.prototype.isClosing = function ( win ) {
        return win === this.currentWindow && !!this.lifecycle &&
-               this.lifecycle.closing.state() === 'resolved' &&
-               this.lifecycle.closed.state() === 'pending';
+               this.lifecycle.isClosing();
 };
 
 /**
@@ -1131,8 +1168,7 @@ OO.ui.WindowManager.prototype.isClosing = function ( win ) {
  */
 OO.ui.WindowManager.prototype.isOpened = function ( win ) {
        return win === this.currentWindow && !!this.lifecycle &&
-               this.lifecycle.opened.state() === 'resolved' &&
-               this.lifecycle.closing.state() === 'pending';
+               this.lifecycle.isOpened();
 };
 
 /**
@@ -1261,7 +1297,8 @@ OO.ui.WindowManager.prototype.getCurrentWindow = function () {
  * @fires opening
  */
 OO.ui.WindowManager.prototype.openWindow = function ( win, data, lifecycle, compatOpening ) {
-       var manager = this;
+       var error,
+               manager = this;
        data = data || {};
 
        // Internal parameter 'lifecycle' allows this method to always return
@@ -1298,21 +1335,16 @@ OO.ui.WindowManager.prototype.openWindow = function ( win, data, lifecycle, comp
 
        // Error handling
        if ( !this.hasWindow( win ) ) {
-               compatOpening.reject( new OO.ui.Error(
-                       'Cannot open window: window is not attached to manager'
-               ) );
-               lifecycle.deferreds.opening.reject( new OO.ui.Error(
-                       'Cannot open window: window is not attached to manager'
-               ) );
-               return lifecycle;
+               error = 'Cannot open window: window is not attached to manager';
+       } else if ( this.lifecycle && this.lifecycle.isOpened() ) {
+               error = 'Cannot open window: another window is open';
+       } else if ( this.preparingToOpen || ( this.lifecycle && this.lifecycle.isOpening() ) ) {
+               error = 'Cannot open window: another window is opening';
        }
-       if ( this.preparingToOpen || ( this.lifecycle && this.lifecycle.closing.state() !== 'resolved' ) ) {
-               compatOpening.reject( new OO.ui.Error(
-                       'Cannot open window: another window is opening or open'
-               ) );
-               lifecycle.deferreds.opening.reject( new OO.ui.Error(
-                       'Cannot open window: another window is opening or open'
-               ) );
+
+       if ( error ) {
+               compatOpening.reject( new OO.ui.Error( error ) );
+               lifecycle.deferreds.opening.reject( new OO.ui.Error( error ) );
                return lifecycle;
        }
 
@@ -1386,9 +1418,9 @@ OO.ui.WindowManager.prototype.closeWindow = function ( win, data ) {
                error = 'Cannot close window: no window is currently open';
        } else if ( !win ) {
                error = 'Cannot close window: window is not attached to manager';
-       } else if ( win !== this.currentWindow ) {
+       } else if ( win !== this.currentWindow || this.lifecycle.isClosed() ) {
                error = 'Cannot close window: window already closed with different data';
-       } else if ( this.preparingToClose || lifecycle.closing.state() === 'resolved' ) {
+       } else if ( this.preparingToClose || this.lifecycle.isClosing() ) {
                error = 'Cannot close window: window already closing with different data';
        }