easytimer.js
easytimer.js copied to clipboard
Timer is not running but seconds are updated
Version: 4.5.3
I use EasyTimer for a bookmarklet. If any of you don't remember how a bookmarklet works, just imagine that you copied and pasted the whole code into console whenever you press a bookmarklet button.
I organised a timer:
var countdownTimer = new easytimer.Timer();
countdownTimer.start({
countdown: true,
startValues: { minutes: 10, seconds: 0 },
});
Then I started debugging. If I start the timer, then again click my bookmarklet button, this situation occurres:
countdownTimer.addEventListener("secondsUpdated", function (e) {
if (!countdownTimer.isRunning()){
debugger;
return;
}
jQuery("#countdown-" + taskUserStarted).html(
pad(countdownTimer.getTimeValues().minutes, 2) +
":" +
pad(countdownTimer.getTimeValues().seconds, 2)
);
});
Namely the interpreter stops at the debugger mark.
This is a crutch, of course. But the result is achieved and the problem seems localised.
But this looks paradoxical to me - either seconds are updated or the timer is not running. Here we have a situation when the timer is not running, but seconds are still updated (though figures are not changed - they will be zeroes). I suppose, it may be a bug in the library.
What do you think?
Hi!
First of all, sorry for the late response.
I think that your bookmarklet may be starting a new timer every time is pressed and these timers are assigned to the countdownTimer variable. Then you have multiple timers running but you only have access to the last timer created. I guess you have to protect your code to only run one timer at the same time, or change your code to allow multiple timers running.
For example, you can use your taskUserStarted variable to store the timers, something like:
var timers = window.timers || {}; // I guess you run this code in window context
var timers[taskUserStarted] = new easytimer.Timer();
countdownTimer.start({
countdown: true,
startValues: { minutes: 10, seconds: 0 },
});
countdownTimer.addEventListener("secondsUpdated", function (e) {
if (! timers[taskUserStarted].isRunning()){
debugger;
return;
}
jQuery("#countdown-" + taskUserStarted).html(
pad( timers[taskUserStarted].getTimeValues().minutes, 2) +
":" +
pad( timers[taskUserStarted].getTimeValues().seconds, 2)
);
});
I hope this helps you.
Best regards!
I close the issue for now, if you need some help just tell me!