From 93b842c5d4134baf5fe0dfb3e04061fce7ff9bf2 Mon Sep 17 00:00:00 2001 From: Adhityaa Date: Thu, 14 Jun 2018 14:27:57 +0530 Subject: [PATCH] commento.js: use a separate function to autoload --- frontend/js/commento.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/frontend/js/commento.js b/frontend/js/commento.js index e0fcf93..1b251d2 100644 --- a/frontend/js/commento.js +++ b/frontend/js/commento.js @@ -1294,13 +1294,18 @@ }); } - // There's no danger of both main()s being called because if the first one is - // called later, the second `main()` wouldn't have executed because readyState - // woldn't have been "interactive" or "complete" at registration. If the - // second main() executes, the first would never execute because - // DOMContentLoaded wouldn't be fired in the future. - document.addEventListener("DOMContentLoaded", main); - if (document.readyState == "interactive" || document.readyState == "complete") + var autoInitted = false; + function autoInit() { + if (autoInitted) + return; + autoInitted = true; + main(); + } + + if (document.readyState != "complete" && document.readyState != "interactive") + document.addEventListener("load", autoInit); + else + autoInit(); }(window, document));