aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--content_scripts/vimium_frontend.coffee6
-rw-r--r--lib/dom_utils.coffee9
2 files changed, 8 insertions, 7 deletions
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee
index 351a2690..a3ab051b 100644
--- a/content_scripts/vimium_frontend.coffee
+++ b/content_scripts/vimium_frontend.coffee
@@ -1140,9 +1140,9 @@ CursorHider =
window.addEventListener "scroll", @onScroll
initializePreDomReady()
-window.addEventListener("DOMContentLoaded", registerFrame)
-window.addEventListener("unload", unregisterFrame)
-window.addEventListener("DOMContentLoaded", initializeOnDomReady)
+DomUtils.documentReady initializeOnDomReady
+DomUtils.documentReady registerFrame
+window.addEventListener "unload", unregisterFrame
window.onbeforeunload = ->
chrome.runtime.sendMessage(
diff --git a/lib/dom_utils.coffee b/lib/dom_utils.coffee
index ba5e279f..7a75dd6a 100644
--- a/lib/dom_utils.coffee
+++ b/lib/dom_utils.coffee
@@ -2,10 +2,11 @@ DomUtils =
#
# Runs :callback if the DOM has loaded, otherwise runs it on load
#
- documentReady: do ->
- loaded = false
- window.addEventListener("DOMContentLoaded", -> loaded = true)
- (callback) -> if loaded then callback() else window.addEventListener("DOMContentLoaded", callback)
+ documentReady: (func) ->
+ if document.readyState == "loading"
+ window.addEventListener "DOMContentLoaded", func
+ else
+ func()
#
# Adds a list of elements to a page.