Fix weird period clock input issue

This commit is contained in:
Neale Pickett 2014-01-19 20:26:34 -07:00
parent 02b833cdde
commit 73059dcd82
1 changed files with 19 additions and 14 deletions

View File

@ -84,22 +84,25 @@ function startTimer(element) {
var duration = 0; var duration = 0;
var className; var className;
// Heartbeat
function pulse() {
if (! running) {
element.className = className + " paused";
return;
}
refresh();
}
// Re-calculate and update displayed time // Re-calculate and update displayed time
function refresh (force) { function refresh() {
var remain = Math.ceil(element.remaining() / 1000); var remain = Math.ceil(element.remaining() / 1000);
var min = Math.floor(Math.abs(remain) / 60); var min = Math.floor(Math.abs(remain) / 60);
var sec = Math.abs(remain) % 60; var sec = Math.abs(remain) % 60;
if (! running) {
element.className = className + " paused";
if (! force) {
return;
}
}
// Set classes // Set classes
if ((! className) && (remain <= 20)) { if ((! className) && (remain <= 20)) {
element.className = className + " lowtime"; element.className = "lowtime";
} else { } else {
element.className = className; element.className = className;
} }
@ -132,7 +135,7 @@ function startTimer(element) {
return; return;
} }
element.set(sec * 1000, className); element.set(sec * 1000, className, true);
} }
// Return remaining time in milliseconds // Return remaining time in milliseconds
@ -147,13 +150,16 @@ function startTimer(element) {
// Set timer to [d] milliseconds. // Set timer to [d] milliseconds.
// Put element into class [cn], if set. // Put element into class [cn], if set.
element.set = function(t, cn) { // If [stealth] is set, don't refresh
element.set = function(t, cn, stealth) {
startTime = (new Date()).getTime(); startTime = (new Date()).getTime();
set_duration = t; set_duration = t;
duration = t; duration = t;
className = cn; className = cn;
refresh(true); if (! stealth) {
refresh();
}
} }
// Start timer // Start timer
@ -171,13 +177,12 @@ function startTimer(element) {
duration = element.remaining(); duration = element.remaining();
running = false; running = false;
} }
refresh();
} }
element.readOnly = true; element.readOnly = true;
element.addEventListener("input", inputHandler); element.addEventListener("input", inputHandler);
timer_updates.push(refresh); timer_updates.push(pulse);
} }
// Transition state machine based on state // Transition state machine based on state