diff options
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 6 | ||||
| -rw-r--r-- | lib/dom_utils.coffee | 15 |
2 files changed, 12 insertions, 9 deletions
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index f14c5d07..39bfaacb 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -436,10 +436,10 @@ extend window, # Initialize UI components which are only installed in the main/top frame. initializeTopFrameUIComponents = do -> - Frame.addEventListener "initializeTopFrameUIComponents", Utils.makeIdempotent Vomnibar.init.bind Vomnibar + Frame.addEventListener "initializeTopFrameUIComponents", Utils.makeIdempotent -> + DomUtils.documentReady Vomnibar.init.bind Vomnibar - Utils.makeIdempotent -> - DomUtils.documentReady -> Frame.postMessage "initializeTopFrameUIComponents" + Utils.makeIdempotent -> Frame.postMessage "initializeTopFrameUIComponents" # Initialize UI components which are only installed in all frames (i.e., the HUD). initializeAllFrameUIComponents = Utils.makeIdempotent -> 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 |
