X-Git-Url: http://git.datanom.net/qtadmin.git/blobdiff_plain/e488b174ce9e9a9ff27a9cb33528f7cdd194f7bc..0f9549a5088b1a76553e8af3f2ae14afb2a5e3c9:/js/timer.js?ds=inline diff --git a/js/timer.js b/js/timer.js index 3976030..f68f084 100644 --- a/js/timer.js +++ b/js/timer.js @@ -1,6 +1,7 @@ /* vim: set ts=4 tw=4 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(); @@ -8,14 +9,24 @@ function myTimer() { var timeLeft = Math.round(((expire % 86400000) % 3600000) / 60000); if (timeLeft < 0) { - /*timeLeft = 'Expired'; - document.getElementById("time").style.background = "red";*/ 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 { - //timeLeft += 1; - timeLeft = '< ' + timeLeft + ' min'; + if ((timeLeft < last && timeLeft > 0) || last == -1) { + last = timeLeft; + console.log('Session valid < ' + timeLeft); + timeLeft = '< ' + timeLeft + ' min'; + document.getElementById("timer").innerHTML = timeLeft; + } } - - document.getElementById("timer").innerHTML = timeLeft; }