refactor: replace DOMContentLoaded with onReady utility
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import { onReady } from "./utils";
|
||||||
|
|
||||||
const initSortFilter = (): void => {
|
const initSortFilter = (): void => {
|
||||||
const sortSelect = document.getElementById("sort-select") as HTMLSelectElement | null;
|
const sortSelect = document.getElementById("sort-select") as HTMLSelectElement | null;
|
||||||
const orderSelect = document.getElementById("order-select") as HTMLSelectElement | null;
|
const orderSelect = document.getElementById("order-select") as HTMLSelectElement | null;
|
||||||
@@ -21,4 +23,4 @@ const initSortFilter = (): void => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", initSortFilter);
|
onReady(initSortFilter);
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { onReady } from "./utils";
|
||||||
|
|
||||||
type Theme = "light" | "dark";
|
type Theme = "light" | "dark";
|
||||||
|
|
||||||
const colorSchemeQuery = window.matchMedia?.("(prefers-color-scheme: dark)") ?? null;
|
const colorSchemeQuery = window.matchMedia?.("(prefers-color-scheme: dark)") ?? null;
|
||||||
@@ -17,8 +19,4 @@ const initTheme = (): void => {
|
|||||||
colorSchemeQuery?.addEventListener("change", () => applyTheme(getPreferredTheme()));
|
colorSchemeQuery?.addEventListener("change", () => applyTheme(getPreferredTheme()));
|
||||||
};
|
};
|
||||||
|
|
||||||
if (document.readyState === "loading") {
|
onReady(initTheme);
|
||||||
document.addEventListener("DOMContentLoaded", initTheme);
|
|
||||||
} else {
|
|
||||||
initTheme();
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user