Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions timer/plugin.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
import Inspire from "@inspirejs/core";

export const hasCSS = true;

Inspire.hooks.add("init-start", me => {
// Create timer, if needed
this.duration = document.body.getAttribute("data-duration");
let duration = document.body.getAttribute("data-duration");

if (this.duration > 0) {
if (duration > 0) {
document.body.insertAdjacentHTML(
"beforeend",
`<div id="timer" style="transition-duration: ${this.duration * 60}s;"></div>`,
`<div id="timer" style="transition-duration: ${duration * 60}s;"></div>`,
);

addEventListener("load", evt => {
// Start the countdown on load — or right away if the plugin loaded after
// the load event already fired, so a late load isn't missed.
let start = () => {
timer.className = "end";

setTimeout(() => timer.classList.add("overtime"), this.duration * 60000);
});
setTimeout(() => timer.classList.add("overtime"), duration * 60000);
};

if (document.readyState === "complete") {
start();
}
else {
addEventListener("load", start);
}
}
});