refactor: share dom ready
This commit is contained in:
@@ -11,3 +11,12 @@ export const parseClassList = (value: string | null): string[] => {
|
||||
.map((entry: string): string => entry.trim())
|
||||
.filter((entry: string): boolean => entry.length > 0);
|
||||
};
|
||||
|
||||
export const onReady = (fn: () => void): void => {
|
||||
if (document.readyState === "loading") {
|
||||
document.addEventListener("DOMContentLoaded", fn, { once: true });
|
||||
return;
|
||||
}
|
||||
|
||||
fn();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user