aboutsummaryrefslogtreecommitdiffstats
path: root/content_scripts/ui_component.coffee
diff options
context:
space:
mode:
authorStephen Blott2015-03-17 11:42:58 +0000
committerStephen Blott2015-03-17 11:42:58 +0000
commit8bc811aae1118e28faa7c17e67b039c67f637274 (patch)
tree702f28f1d88fef438a717895ede5107409df54be /content_scripts/ui_component.coffee
parent9461d30b0d19fd65dc43e18bebec1fe0fd3ee818 (diff)
downloadvimium-8bc811aae1118e28faa7c17e67b039c67f637274.tar.bz2
Activate vomnibar in window.top; hide on focus, fixed.
Diffstat (limited to 'content_scripts/ui_component.coffee')
-rw-r--r--content_scripts/ui_component.coffee14
1 files changed, 12 insertions, 2 deletions
diff --git a/content_scripts/ui_component.coffee b/content_scripts/ui_component.coffee
index 64dddf67..3d8cef29 100644
--- a/content_scripts/ui_component.coffee
+++ b/content_scripts/ui_component.coffee
@@ -15,9 +15,9 @@ class UIComponent
# Hide the iframe, but don't interfere with the focus.
@hide false
- # If any frame in the current tab receives the focus, then we hide the vomnibar.
+ # If any other frame in the current tab receives the focus, then we hide the vomnibar.
chrome.runtime.onMessage.addListener (request) =>
- @hide false if @showing and request.name == "frameFocused"
+ @hide false if @showing and request.name == "frameFocused" and request.frameId != frameId
false # Free up response handler.
# Open a port and pass it to the iframe via window.postMessage.
@@ -42,11 +42,21 @@ class UIComponent
@postMessage message if message?
@iframeElement.classList.remove "vimiumUIComponentHidden"
@iframeElement.classList.add "vimiumUIComponentShowing"
+ # The window may not have the focus. We focus it now, to prevent the "focus" listener below from firing
+ # immediately.
+ window.focus()
+ window.addEventListener "focus", @onFocus = (event) =>
+ if event.target == window
+ window.removeEventListener "focus", @onFocus
+ @onFocus = null
+ @postMessage "hide"
@showing = true
hide: (focusWindow = true)->
@iframeElement.classList.remove "vimiumUIComponentShowing"
@iframeElement.classList.add "vimiumUIComponentHidden"
+ window.removeEventListener "focus", @onFocus if @onFocus
+ @onFocus = null
if focusWindow and @options?.frameId?
chrome.runtime.sendMessage
handler: "sendMessageToFrames"