aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Blott2015-01-12 11:47:56 +0000
committerStephen Blott2015-01-12 11:47:56 +0000
commit9ce07ada32883ac75a1d7436c026a846628181c8 (patch)
tree62ee77ec6688cbfa7bd2ddcf01b6f61054d02dd0
parent75565049e160042017486c10a61bed3a292e0c58 (diff)
downloadvimium-9ce07ada32883ac75a1d7436c026a846628181c8.tar.bz2
Fix race condition on the options page.
Fixes #1426.
-rw-r--r--content_scripts/vimium_frontend.coffee2
-rw-r--r--lib/dom_utils.coffee7
2 files changed, 8 insertions, 1 deletions
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee
index 351a2690..0f42c65b 100644
--- a/content_scripts/vimium_frontend.coffee
+++ b/content_scripts/vimium_frontend.coffee
@@ -1142,7 +1142,7 @@ CursorHider =
initializePreDomReady()
window.addEventListener("DOMContentLoaded", registerFrame)
window.addEventListener("unload", unregisterFrame)
-window.addEventListener("DOMContentLoaded", initializeOnDomReady)
+DomUtils.runWhenDOMLoaded initializeOnDomReady
window.onbeforeunload = ->
chrome.runtime.sendMessage(
diff --git a/lib/dom_utils.coffee b/lib/dom_utils.coffee
index ba5e279f..762c6418 100644
--- a/lib/dom_utils.coffee
+++ b/lib/dom_utils.coffee
@@ -178,5 +178,12 @@ DomUtils =
event.preventDefault()
@suppressPropagation(event)
+ # Calls func either now (if the DOM has already loaded), or when the DOM is loaded.
+ runWhenDOMLoaded: (func) ->
+ if document.readyState == "loading"
+ window.addEventListener "DOMContentLoaded", func
+ else
+ func()
+
root = exports ? window
root.DomUtils = DomUtils