From: Laurent Mazet Date: Tue, 18 Aug 2020 11:44:25 +0000 (+0200) Subject: make timer configurable X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=58c042375a91356ba065ea7f597e432f64419752;p=trivabble.git make timer configurable --- diff --git a/public/index.html b/public/index.html index 6b8cbfe..0f64a51 100644 --- a/public/index.html +++ b/public/index.html @@ -53,6 +53,7 @@

+

diff --git a/public/trivabble.js b/public/trivabble.js index 460a5ce..78361c2 100644 --- a/public/trivabble.js +++ b/public/trivabble.js @@ -1536,30 +1536,31 @@ if (!Object.prototype.hasOwnProperty.call(localStorage, "timerEnable")) { localStorage.timerEnable = Conf.ENABLE_TIMER; } - if (localStorage.timerEnable) { - activateTimer(); - } else { - desactivateTimer(); - } - } - - function activateTimer() { - document.getElementById("timer").style.display = "block"; - localStorage.timer = setInterval(function() { - document.getElementById("timer-turn").innerHTML = timerString(++localStorage.timerTurn) - document.getElementById("timer-global").innerHTML = timerString(++localStorage.timerGlobal); - }, 1000); + document.getElementById("enable-timer").onclick = function() { + setTimerState(document.getElementById("enable-timer").checked); + }; + setTimerState (localStorage.timerEnable); } - function desactivateTimer() { - document.getElementById("timer").style.display = "none"; - if (Object.prototype.hasOwnProperty.call(localStorage, "timer")) { - clearInterval(localStorage.timer); - delete(localStorage.timer); + function setTimerState(state) { + if (state) { + document.getElementById("timer").style.display = "block"; + document.getElementById("enable-timer").checked = true; + localStorage.timer = setInterval(function() { + document.getElementById("timer-turn").innerHTML = timerString(++localStorage.timerTurn) + document.getElementById("timer-global").innerHTML = timerString(++localStorage.timerGlobal); + }, 1000); + } else { + document.getElementById("timer").style.display = "none"; + document.getElementById("enable-timer").checked = false; + if (Object.prototype.hasOwnProperty.call(localStorage, "timer")) { + clearInterval(localStorage.timer); + delete(localStorage.timer); + } + localStorage.timerGlobal = localStorage.timerTurn = 0; } } - function repromptName(f) { if (localStorage.trivabblePlayerName && localStorage.trivabblePlayerName.trim()) { f();