Enhance timer: Pause during input edits

This commit is contained in:
o-psi 2023-10-24 20:07:10 +00:00
parent b05e5bb575
commit 2a3156cd59
1 changed files with 19 additions and 0 deletions

View File

@ -76,6 +76,18 @@ document.addEventListener("DOMContentLoaded", function() {
}
}
function pauseForEdit() {
wasRunningBeforeEdit = !isPaused; // check if timer was running
pauseTimer();
}
function restartAfterEdit() {
if (wasRunningBeforeEdit) {
startTimer();
}
}
// Start timer when page is loaded
startTimer();
@ -84,4 +96,11 @@ document.addEventListener("DOMContentLoaded", function() {
// Toggle timer when button is clicked
document.getElementById("toggleTimer").addEventListener('click', toggleTimer);
// Function to pause the timer when the time input is clicked
document.getElementById("time_worked").addEventListener('focus', pauseForEdit);
// Function to restart the timer when the time input is clicked away from
document.getElementById("time_worked").addEventListener('blur', restartAfterEdit);
});