]> git.datanom.net - qtadmin.git/blob - js/timer.js
41d6e3f21897fac1862a54556491d3acd9a6d31c
[qtadmin.git] / js / timer.js
1 /* vim: set ts=4 tw=0 sw=4 noet: */
2 var timerRef=setInterval(function(){myTimer()}, 1000);
3 var timeStart = new Date().getTime() + timeout;
4 var last = -1;
5
6 function myTimer() {
7 var elapsed = new Date().getTime();
8 var expire = timeStart - elapsed;
9 var timeLeft = Math.round(((expire % 86400000) % 3600000) / 60000);
10
11 if (timeLeft < 0) {
12 clearInterval(timerRef);
13 console.log('Session expired, reload page');
14 last = -1;
15 location.reload();
16 } else if (timeLeft == 1) {
17 if (timeLeft < last || last == -1) {
18 last = timeLeft;
19 timeLeft = '< ' + timeLeft + ' min';
20 /*console.log('Session soon to expire');*/
21 document.getElementById("time").style.background = "red";
22 document.getElementById("timer").innerHTML = timeLeft;
23 }
24 } else {
25 if ((timeLeft < last && timeLeft > 0) || last == -1) {
26 last = timeLeft;
27 /*console.log('Session valid < ' + timeLeft);*/
28 timeLeft = '< ' + timeLeft + ' min';
29 document.getElementById("timer").innerHTML = timeLeft;
30 }
31 }
32 }
This page took 0.098839 seconds and 6 git commands to generate.