Non-Visual Widgets¶
Timer¶
A non-visual timer object. Extends Callback directly (no DOM element).
Constructor: new Widgets.Timer({duration})
Options:
duration– timer duration in seconds
Methods:
Method |
Description |
|---|---|
|
Start the timer. Optional duration overrides the default. |
|
Stop the timer and fire |
|
Cancel the timer and fire |
|
Return whether the timer is running. |
|
Return elapsed time in seconds. |
|
Return remaining time in seconds. |
|
Set default duration. |
|
Return default duration. |
Callbacks:
expired– fired when the timer completes.cancelled– fired when the timer is cancelled.
let timer = new Widgets.Timer({duration: 5.0});
timer.add_callback('expired', (w) => {
console.log("Timer finished!");
});
timer.start();
// Check status
console.log("Running:", timer.is_set());
console.log("Elapsed:", timer.elapsed_time());