X-Git-Url: http://git.datanom.net/qtadmin.git/blobdiff_plain/243d5f04802898f814f86cc335942582eaca7313..1e354d2079b77adb249465d86e86fa8a59f9dc4e:/js/timer.js diff --git a/js/timer.js b/js/timer.js index 73ecda6..f68f084 100644 --- a/js/timer.js +++ b/js/timer.js @@ -1,7 +1,7 @@ /* vim: set ts=4 tw=4 sw=4 noet: */ var timerRef=setInterval(function(){myTimer()}, 1000); var timeStart = new Date().getTime() + timeout; -var last = 0; +var last = -1; function myTimer() { var elapsed = new Date().getTime(); @@ -11,15 +11,18 @@ function myTimer() { if (timeLeft < 0) { clearInterval(timerRef); console.log('Session expired, reload page'); - last = 0; + last = -1; location.reload(); - } else if (timeLeft < 1) { - timeLeft = 'Expired'; - console.log('Session valid < 1'); - document.getElementById("time").style.background = "red"; - document.getElementById("timer").innerHTML = timeLeft; + } 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) { + if ((timeLeft < last && timeLeft > 0) || last == -1) { last = timeLeft; console.log('Session valid < ' + timeLeft); timeLeft = '< ' + timeLeft + ' min';