keeweb/app/scripts/comp/popup-notifier.js

48 lines
1.4 KiB
JavaScript
Raw Normal View History

2016-03-26 21:12:56 +01:00
'use strict';
var Backbone = require('backbone'),
2016-03-27 15:36:07 +02:00
Alerts = require('./alerts'),
Timeouts = require('../const/timeouts'),
Locale = require('../util/locale');
2016-03-26 21:12:56 +01:00
var PopupNotifier = {
init: function() {
if (window.open) {
var windowOpen = window.open;
window.open = function() {
var win = windowOpen.apply(window, arguments);
if (win) {
PopupNotifier.deferCheckClosed(win);
Backbone.trigger('popup-opened', win);
2016-03-27 15:36:07 +02:00
} else {
if (!Alerts.alertDisplayed) {
Alerts.error({
header: Locale.authPopupRequired,
body: Locale.authPopupRequiredBody
});
}
2016-03-26 21:12:56 +01:00
}
return win;
};
}
},
deferCheckClosed: function(win) {
setTimeout(PopupNotifier.checkClosed.bind(PopupNotifier, win), Timeouts.CheckWindowClosed);
},
checkClosed: function(win) {
if (win.closed) {
2016-03-27 13:54:35 +02:00
setTimeout(PopupNotifier.triggerClosed.bind(PopupNotifier, win), Timeouts.CheckWindowClosed);
2016-03-26 21:12:56 +01:00
} else {
PopupNotifier.deferCheckClosed(win);
}
2016-03-27 13:54:35 +02:00
},
triggerClosed: function(win) {
Backbone.trigger('popup-closed', win);
2016-03-26 21:12:56 +01:00
}
};
module.exports = PopupNotifier;