diff options
| -rw-r--r-- | content_scripts/hud.coffee | 16 | ||||
| -rw-r--r-- | content_scripts/ui_component.coffee | 7 | ||||
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 9 | ||||
| -rw-r--r-- | content_scripts/vomnibar.coffee | 8 | ||||
| -rw-r--r-- | lib/dom_utils.coffee | 11 |
5 files changed, 32 insertions, 19 deletions
diff --git a/content_scripts/hud.coffee b/content_scripts/hud.coffee index 0d3a6f95..b2780491 100644 --- a/content_scripts/hud.coffee +++ b/content_scripts/hud.coffee @@ -22,15 +22,17 @@ HUD = @_showForDurationTimerId = setTimeout((=> @hide()), duration) show: (text) -> - @init() - clearTimeout(@_showForDurationTimerId) - @hudUI.activate {name: "show", text} - @tween.fade 1.0, 150 + DomUtils.documentComplete => + @init() + clearTimeout(@_showForDurationTimerId) + @hudUI.activate {name: "show", text} + @tween.fade 1.0, 150 showFindMode: (@findMode = null) -> - @init() - @hudUI.activate name: "showFindMode" - @tween.fade 1.0, 150 + DomUtils.documentComplete => + @init() + @hudUI.activate name: "showFindMode" + @tween.fade 1.0, 150 search: (data) -> @findMode.findInPlace data.query diff --git a/content_scripts/ui_component.coffee b/content_scripts/ui_component.coffee index 59e4fe41..203f0c8c 100644 --- a/content_scripts/ui_component.coffee +++ b/content_scripts/ui_component.coffee @@ -68,10 +68,9 @@ class UIComponent # Post a message (if provided), then call continuation (if provided). We wait for documentReady() to ensure # that the @iframePort set (so that we can use @iframePort.use()). postMessage: (message = null, continuation = null) -> - DomUtils.documentReady => - @iframePort.use (port) -> - port.postMessage message if message? - continuation?() + @iframePort?.use (port) -> + port.postMessage message if message? + continuation?() activate: (@options = null) -> @postMessage @options, => diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 9dd68278..07322250 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -143,7 +143,7 @@ initializeOnEnabledStateKnown = (isEnabledForUrl) -> if isEnabledForUrl # We only initialize (and activate) the Vomnibar in the top frame. Also, we do not initialize the # Vomnibar until we know that Vimium is enabled. Thereafter, there's no more initialization to do. - Vomnibar.init() if DomUtils.isTopFrame() + DomUtils.documentComplete Vomnibar.init.bind Vomnibar if DomUtils.isTopFrame() initializeOnEnabledStateKnown = -> # @@ -637,10 +637,11 @@ window.HelpDialog ?= abort: -> @helpUI.hide false if @isShowing() toggle: (request) -> - @helpUI ?= new UIComponent "pages/help_dialog.html", "vimiumHelpDialogFrame", -> - if @isShowing() + DomUtils.documentComplete => + @helpUI ?= new UIComponent "pages/help_dialog.html", "vimiumHelpDialogFrame", -> + if @helpUI? and @isShowing() @helpUI.hide() - else + else if @helpUI? @helpUI.activate extend request, name: "activate", focus: true diff --git a/content_scripts/vomnibar.coffee b/content_scripts/vomnibar.coffee index cbd2892c..49c4288e 100644 --- a/content_scripts/vomnibar.coffee +++ b/content_scripts/vomnibar.coffee @@ -56,10 +56,10 @@ Vomnibar = # selectFirst - Optional, boolean. Whether to select the first entry. # newTab - Optional, boolean. Whether to open the result in a new tab. open: (sourceFrameId, options) -> - @init() - # The Vomnibar cannot coexist with the help dialog (it causes focus issues). - HelpDialog.abort() - @vomnibarUI.activate extend options, { name: "activate", sourceFrameId, focus: true } + if @vomnibarUI? + # The Vomnibar cannot coexist with the help dialog (it causes focus issues). + HelpDialog.abort() + @vomnibarUI.activate extend options, { name: "activate", sourceFrameId, focus: true } root = exports ? window root.Vomnibar = Vomnibar diff --git a/lib/dom_utils.coffee b/lib/dom_utils.coffee index b247e93b..8e953405 100644 --- a/lib/dom_utils.coffee +++ b/lib/dom_utils.coffee @@ -13,6 +13,17 @@ DomUtils = (callback) -> if isReady then callback() else callbacks.push callback + documentComplete: do -> + [isComplete, callbacks] = [document.readyState == "complete", []] + unless isComplete + window.addEventListener "load", onLoad = -> + window.removeEventListener "load", onLoad + isComplete = true + callback() for callback in callbacks + callbacks = null + + (callback) -> if isComplete then callback() else callbacks.push callback + createElement: (tagName) -> element = document.createElement tagName if element instanceof HTMLElement |
