Repository URL to install this package:
|
Version:
0.0.11-rc1 ▾
|
var constants = require('./helpers/constants');
/**
* Open a popup window to the supplied url.
*
* @param {String} url - the url to open
* @returns {Object}
*/
function open(url) {
var width = 700;
var height = 600;
var left = 0;
var top = 0;
var windowName = 'connect-zoom-account-to-doodle';
// window.screen is not available on IE11
if (window && window.screen) {
left = window.screen.width / 2 - width / 2;
top = window.screen.height / 2 - height / 2;
}
return window.open(
url,
windowName,
'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=' +
width +
', height=' +
height +
', top=' +
top +
', left=' +
left
);
}
/**
* Checks is the supplied window has been closed.
*
* @param {Object} win - the window object to check
* @param {Number|Undefined} timeoutMs - the timeout in milliseconds
* @returns {Promise}
*/
function checkIfWindowClosed(win, timeoutMs) {
// 180000 milliseconds is 3 minutes
var timeout = 180000;
if (typeof timeoutMs === 'number') {
timeout = timeoutMs;
}
return new Promise(function(resolve, reject) {
var closingTimerId = setTimeout(function() {
reject(new Error(constants.errors.WINDOW_NOT_CLOSED_WITHIN_TIMEOUT));
}, timeout);
var timer = setInterval(function() {
if (win && win.closed) {
window.clearInterval(timer);
window.clearInterval(closingTimerId);
resolve(true);
}
}, 100);
});
}
module.exports = {
checkIfWindowClosed: checkIfWindowClosed,
open: open,
};