From 89df06fa6c00c9295ff064308c03f770b01d79be Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sat, 2 Apr 2016 11:54:04 +0100 Subject: Rework DomUtils.documentReady(). There seems to be an issue on this page: - http://i.imgur.com/PdmUjij.jpg whereby "DOMContentLoaded" isn't firing. The page structure is unusual (involving a shadow-DOM element), which might be the source of the problem. What happens is that the "DOMContentLoaded" event fires as required, but the document state is still "loading". Here, we just say that if the "DOMContentLoaded" handler has fired once, then we're good to go. --- lib/dom_utils.coffee | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'lib/dom_utils.coffee') diff --git a/lib/dom_utils.coffee b/lib/dom_utils.coffee index eb11e295..3fc08b78 100644 --- a/lib/dom_utils.coffee +++ b/lib/dom_utils.coffee @@ -2,13 +2,16 @@ DomUtils = # # Runs :callback if the DOM has loaded, otherwise runs it on load # - documentReady: (callback) -> - if document.readyState == "loading" - window.addEventListener "DOMContentLoaded", handler = -> - window.removeEventListener "DOMContentLoaded", handler + documentReady: do -> + isReady = false + (callback) -> + if document.readyState == "loading" and not isReady + window.addEventListener "DOMContentLoaded", handler = -> + isReady = true + window.removeEventListener "DOMContentLoaded", handler + callback() + else callback() - else - callback() createElement: (tagName) -> element = document.createElement tagName -- cgit v1.2.3