Skip to content

Commit

Permalink
refactor: move dom to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
hornta committed Jul 17, 2024
1 parent 8c3df92 commit 56176cb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/melonjs/src/system/device.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getParent } from "./../video/video.js";
import save from "./save.ts";
import { prefixed } from "./../utils/agent.ts";
import { DOMContentLoaded } from "./dom.js";
import { DOMContentLoaded } from "./dom.ts";
import * as device_platform from "./platform.ts";
import { BLUR, eventEmitter, FOCUS } from "./event.ts";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,19 @@ function _domReady() {
}

// https://developer.mozilla.org/en-US/docs/Web/API/Window/DOMContentLoaded_event
export function DOMContentLoaded(fn) {
export const DOMContentLoaded = (fn: () => void) => {
// If the DOM is already ready
if (isDOMReady) {
// Execute the function immediately
fn.call(globalThis, []);
fn();
} else {
// else add the function to the DOM_READY event
eventEmitter.addListenerOnce(DOM_READY, fn.bind(globalThis));
// bind dom load event if not done yet
if (!readyBound) {
// directly call domReady if document is already "ready"
if (
nodeJS === true ||
nodeJS ||
(typeof globalThis.document !== "undefined" &&
globalThis.document.readyState === "complete")
) {
Expand All @@ -81,4 +81,4 @@ export function DOMContentLoaded(fn) {
readyBound = true;
}
}
}
};

0 comments on commit 56176cb

Please sign in to comment.