commento.js: use a separate function to autoload

This commit is contained in:
Adhityaa 2018-06-14 14:27:57 +05:30
parent 877a9bf09f
commit 93b842c5d4

View File

@ -1294,13 +1294,18 @@
}); });
} }
// There's no danger of both main()s being called because if the first one is var autoInitted = false;
// called later, the second `main()` wouldn't have executed because readyState function autoInit() {
// woldn't have been "interactive" or "complete" at registration. If the if (autoInitted)
// second main() executes, the first would never execute because return;
// DOMContentLoaded wouldn't be fired in the future. autoInitted = true;
document.addEventListener("DOMContentLoaded", main);
if (document.readyState == "interactive" || document.readyState == "complete")
main(); main();
}
if (document.readyState != "complete" && document.readyState != "interactive")
document.addEventListener("load", autoInit);
else
autoInit();
}(window, document)); }(window, document));