-
Notifications
You must be signed in to change notification settings - Fork 0
/
one-tab-only.js
40 lines (34 loc) · 1.35 KB
/
one-tab-only.js
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
console.log('One tab only!');
(function() {
'use strict';
try {
var location = window.location.hash;
if (!location) {
location = (window.location.origin + '/' === window.location.href) ? '/#dashboard' : false;
}
if (location) {
var channel = new BroadcastChannel('tab');
channel.postMessage({type: 'another-tab', content: location});
channel.addEventListener('message', function(msg) {
if (msg.data.type === 'another-tab') {
// Message received from other Zammad tab, reply to it and open its location
channel.postMessage({type: 'i-got-it'});
window.focus();
if (document.hidden) {
App.Event.trigger('notifyDesktop', {
title: 'Click here to focus opened Zammad link',
timeout: 10000,
onclick: function() { window.focus(); },
});
}
window.location = window.origin + msg.data.content;
} else if (msg.data.type === 'i-got-it') {
window.close();
}
});
}
}
catch (e) {
console.error('One-tab-only error:', e);
}
})();