Skip to content

Commit

Permalink
Add explicit window object to setTimeout and setInterval calls …
Browse files Browse the repository at this point in the history
…(see #650)
  • Loading branch information
giuscris committed Feb 14, 2025
1 parent 5f87c5d commit 3a644fa
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion panel/src/ts/components/inputs/date-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function handleLongClick(element: HTMLElement, callback: (event: MouseEvent) =>
clear();
} else {
callback.call(context, event);
timer = setTimeout(() => (timer = setInterval(callback.bind(context, event), interval)), timeout);
timer = window.setTimeout(() => (timer = window.setInterval(callback.bind(context, event), interval)), timeout);
}
});
element.addEventListener("mouseout", clear);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class LinkTooltipView {
destroy() {
if (this.tooltip) {
const tooltip = this.tooltip;
setTimeout(() => tooltip.remove(), 100);
window.setTimeout(() => tooltip.remove(), 100);
}
this.tooltip = undefined;
}
Expand Down
6 changes: 3 additions & 3 deletions panel/src/ts/components/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ export class Notification {
this.containerElement.appendChild(notification);
}

let timer = setTimeout(() => this.remove(), interval);
let timer = window.setTimeout(() => this.remove(), interval);

notification.addEventListener("click", () => this.remove());

notification.addEventListener("mouseenter", () => clearTimeout(timer));

notification.addEventListener("mouseleave", () => ((timer = setTimeout(() => this.remove())), this.options.mouseleaveDelay));
notification.addEventListener("mouseleave", () => ((timer = window.setTimeout(() => this.remove())), this.options.mouseleaveDelay));

return notification;
};
Expand All @@ -84,7 +84,7 @@ export class Notification {
remove() {
this.notificationElement.classList.add("fadeout");

setTimeout(() => {
window.setTimeout(() => {
if (this.containerElement && this.notificationElement && this.notificationElement.parentNode) {
this.containerElement.removeChild(this.notificationElement);
}
Expand Down
2 changes: 1 addition & 1 deletion panel/src/ts/components/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export class Notifications {
let delay = 0;

$$("meta[name=notification]").forEach((element: HTMLMetaElement) => {
setTimeout(() => {
window.setTimeout(() => {
const data = JSON.parse(element.content);
const notification = new Notification(data.text, data.type, {
interval: data.interval,
Expand Down
4 changes: 2 additions & 2 deletions panel/src/ts/components/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class Tooltip {
const options = this.options;
const container = options.container;

this.delayTimer = setTimeout(() => {
this.delayTimer = window.setTimeout(() => {
const tooltip = document.createElement("div");
tooltip.className = "tooltip";
tooltip.setAttribute("role", "tooltip");
Expand Down Expand Up @@ -136,7 +136,7 @@ export class Tooltip {
}

if (options.timeout !== null) {
this.timeoutTimer = setTimeout(() => this.remove(), options.timeout);
this.timeoutTimer = window.setTimeout(() => this.remove(), options.timeout);
}

if (options.removeOnMouseout) {
Expand Down
2 changes: 1 addition & 1 deletion panel/src/ts/components/views/backups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class Backups {
notification.show();

if (response.status === "success") {
setTimeout(() => {
window.setTimeout(() => {
triggerDownload(response.data.uri, ($("meta[name=csrf-token]") as HTMLMetaElement).content);
}, 1000);
}
Expand Down
2 changes: 1 addition & 1 deletion panel/src/ts/components/views/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class Dashboard {
notification.show();

if (response.status === "success") {
setTimeout(() => {
window.setTimeout(() => {
button.disabled = false;
triggerDownload(response.data.uri, ($("meta[name=csrf-token]") as HTMLMetaElement).content);
}, 1000);
Expand Down
2 changes: 1 addition & 1 deletion panel/src/ts/components/views/updates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class Updates {
currentVersion.style.display = "block";
};

setTimeout(() => {
window.setTimeout(() => {
const data = { "csrf-token": ($("meta[name=csrf-token]") as HTMLMetaElement).content };

new Request(
Expand Down
4 changes: 2 additions & 2 deletions panel/src/ts/utils/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function debounce(callback: (...args: any[]) => any, delay: number, leadi
if (leading && !timer) {
result = callback.apply(context, args);
}
timer = setTimeout(() => {
timer = window.setTimeout(() => {
if (!leading) {
result = callback.apply(context, args);
}
Expand Down Expand Up @@ -44,7 +44,7 @@ export function throttle(callback: (...args: any[]) => any, delay: number) {
previous = now;
result = callback.apply(context, args);
} else if (!timer) {
timer = setTimeout(() => {
timer = window.setTimeout(() => {
previous = Date.now();
result = callback.apply(context, args);
timer = null;
Expand Down

0 comments on commit 3a644fa

Please sign in to comment.