X-Git-Url: http://git.datanom.net/qtadmin.git/blobdiff_plain/6df4b8055a0e63b554ed211760ab1aa5cb431306..70c7fd5765720621553b3ddaff1009c795f49a76:/js/timer.js diff --git a/js/timer.js b/js/timer.js index a7e9c1d..41d6e3f 100644 --- a/js/timer.js +++ b/js/timer.js @@ -1,20 +1,32 @@ /* vim: set ts=4 tw=0 sw=4 noet: */ -var timerRef=setInterval(function(){myTimer()},1000); +var timerRef=setInterval(function(){myTimer()}, 1000); var timeStart = new Date().getTime() + timeout; +var last = -1; function myTimer() { - var elapsed = new Date().getTime(); - var expire = timeStart - elapsed; - var timeLeft = Math.round(((expire % 86400000) % 3600000) / 60000); + var elapsed = new Date().getTime(); + var expire = timeStart - elapsed; + var timeLeft = Math.round(((expire % 86400000) % 3600000) / 60000); - if (timeLeft < 0) { - timeLeft = 'Expired'; - document.getElementById("time").style.background = "red"; - clearInterval(timerRef); - } else { - timeLeft += 1; - timeLeft = '< ' + timeLeft + ' min'; - } - - document.getElementById("timer").innerHTML = timeLeft; + if (timeLeft < 0) { + clearInterval(timerRef); + console.log('Session expired, reload page'); + last = -1; + location.reload(); + } else if (timeLeft == 1) { + if (timeLeft < last || last == -1) { + last = timeLeft; + timeLeft = '< ' + timeLeft + ' min'; + /*console.log('Session soon to expire');*/ + document.getElementById("time").style.background = "red"; + document.getElementById("timer").innerHTML = timeLeft; + } + } else { + if ((timeLeft < last && timeLeft > 0) || last == -1) { + last = timeLeft; + /*console.log('Session valid < ' + timeLeft);*/ + timeLeft = '< ' + timeLeft + ' min'; + document.getElementById("timer").innerHTML = timeLeft; + } + } }