-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathscreensaver.js
51 lines (42 loc) · 1.44 KB
/
screensaver.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
/*
Screensaver
Switch to defined screensaver view, if no mousemovement or
click event detected for the defined seconds
*/
var screensaverView = 'screensaver';
var prevScreensaverView = 'home';
var screensaverSeconds = 120;
var debounce;
var activateScreensaver = function () {
screensaverTimeout = null;
if (vis.activeView !== screensaverView) {
// screensaver not active yet
console.log('Enabled screensaver');
prevScreensaverView = vis.activeView;
vis.changeView(screensaverView);
}
};
var handleScreensaverEvents = function () {
if (debounce) {
return;
}
// debounce mousemove/touchmove events
debounce = setTimeout(function () {
debounce = null;
}, 500);
// clear timer if already running
if (screensaverTimeout) {
clearTimeout(screensaverTimeout);
}
if (screensaverView === vis.activeView) {
// screensaver active and clicked -> disable
console.log('Disable screensaver');
vis.changeView(prevScreensaverView);
}
// restart timer
screensaverTimeout = setTimeout(activateScreensaver, screensaverSeconds * 1000);
};
var screensaverTimeout = setTimeout(activateScreensaver, screensaverSeconds * 1000);
document.addEventListener('click', handleScreensaverEvents);
document.addEventListener('mousemove', handleScreensaverEvents);
document.addEventListener('touchmove', handleScreensaverEvents);