/*!
- * 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 ) {
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
*/
OO.ui.WindowManager.prototype.isOpening = function ( win ) {
return win === this.currentWindow && !!this.lifecycle &&
- this.lifecycle.opened.state() === 'pending';
+ this.lifecycle.isOpening();
};
/**
*/
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();
};
/**
*/
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();
};
/**
* @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
// 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;
}
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';
}