-
-
Notifications
You must be signed in to change notification settings - Fork 742
/
Copy pathtabActivity.js
54 lines (44 loc) · 1.54 KB
/
tabActivity.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* fades out tabs that are inactive */
var tabBar = require('navbar/tabBar.js')
var tabActivity = {
minFadeAge: 330000,
refreshInterval: 7500,
tabSelected: function() {
var selected = tabs.getSelected()
if (tabBar.getTab(selected).classList.contains('fade')) {
// check to see if it is still has been selected in .500 seconds
setTimeout(function (tabID) {
if (tabs.getSelected() != tabID) {
var tab = tabs.get(tabID)
if (tab) {
tabBar.getTab(tabID).classList.add('fade')
tabs.update(tabID, {'lastActivity':tab.lastActivity - tabActivity.minFadeAge})
}
}
}, 500, selected);
}
// never fade the current tab
tabBar.getTab(selected).classList.remove('fade')
},
refresh: function () {
requestAnimationFrame(function () {
var tabSet = tabs.get()
var selected = tabs.getSelected()
var time = Date.now()
tabSet.forEach(function (tab) {
if (selected == tab.id) { return }
//else
if ((time - tab.lastActivity > tabActivity.minFadeAge)) { // the tab has been inactive for greater than minActivity, and it is not currently selected
tabBar.getTab(tab.id).classList.add('fade')
} else {
tabBar.getTab(tab.id).classList.remove('fade')
}
})
})
},
initialize: function () {
setInterval(tabActivity.refresh, this.refreshInterval)
tasks.on('tab-selected', this.tabSelected)
}
}
module.exports = tabActivity