# all files / src/ WindowInstance.js

94.74% Statements 18/19
50% Branches 2/4
87.5% Functions 7/8
94.74% Lines 18/19

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99

    1×
    5×

    5×

    5×

    5×
    5×

    5×
    5×

    5×
    5×

    1×

    1×
    5×

    1×

    1×
    15×

    1×
    5×

     /**
     * A window instance represents the life cycle for one single opening of a window
     * until its closing.
     *
     * While OO.ui.WindowManager will reuse OO.ui.Window objects, each time a window is
     * opened, a new lifecycle starts.
     *
     * For more information, please see the [OOjs UI documentation on MediaWiki] [1].
     *
     * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Windows
     *
     * @class
     *
     * @constructor
     */
    OO.ui.WindowInstance = function OOuiWindowInstance() {
    	var deferreds = {
    		opening: $.Deferred(),
    		opened: $.Deferred(),
    		closing: $.Deferred(),
    		closed: $.Deferred()
    	};

    	/**
    	 * @private
    	 * @property {Object}
    	 */
    	this.deferreds = deferreds;

    	// Set these up as chained promises so that rejecting of
    	// an earlier stage automatically rejects the subsequent
    	// would-be stages as well.

    	/**
    	 * @property {jQuery.Promise}
    	 */
    	this.opening = deferreds.opening.promise();
    	/**
    	 * @property {jQuery.Promise}
    	 */
    	this.opened = this.opening.then( function () {
    		return deferreds.opened;
    	} );
    	/**
    	 * @property {jQuery.Promise}
    	 */
    	this.closing = this.opened.then( function () {
    		return deferreds.closing;
    	} );
    	/**
    	 * @property {jQuery.Promise}
    	 */
    	this.closed = this.closing.then( function () {
    		return deferreds.closed;
    	} );
    };

    /* Setup */

    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';
    };