Arno Kaimbacher
87e9314b00
Some checks failed
CI Pipeline / japa-tests (push) Failing after 51s
- added lime color inside tailwind.config.js - added some utilities scripts needed for components - npm updates - changed postcss.config.js for nesting css styles - added about function to NavBar.vue
44 lines
859 B
JavaScript
44 lines
859 B
JavaScript
/**
|
|
* @param {Function} callback The function to call
|
|
* @param {number} delay The time to wait
|
|
*/
|
|
export default function timer(callback, delay) {
|
|
let id;
|
|
let started;
|
|
let remaining = delay;
|
|
let running;
|
|
|
|
this.start = function () {
|
|
running = true;
|
|
started = new Date();
|
|
id = setTimeout(callback, remaining);
|
|
};
|
|
|
|
this.pause = function () {
|
|
running = false;
|
|
clearTimeout(id);
|
|
remaining -= new Date() - started;
|
|
};
|
|
|
|
this.clear = function () {
|
|
running = false;
|
|
clearTimeout(id);
|
|
remaining = 0;
|
|
};
|
|
|
|
this.getTimeLeft = function () {
|
|
if (running) {
|
|
this.pause();
|
|
this.start();
|
|
}
|
|
|
|
return remaining;
|
|
};
|
|
|
|
this.getStateRunning = function () {
|
|
return running;
|
|
};
|
|
|
|
this.start();
|
|
}
|