From 5ea0f75a00b592956981bf8f6f7a0d2fa89620ae Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Mon, 29 Dec 2014 09:33:34 +0000 Subject: Close UIComponent iframes when pressing esc by default --- content_scripts/ui_component.coffee | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'content_scripts') diff --git a/content_scripts/ui_component.coffee b/content_scripts/ui_component.coffee index c0889e7f..f47719e5 100644 --- a/content_scripts/ui_component.coffee +++ b/content_scripts/ui_component.coffee @@ -14,6 +14,8 @@ class UIComponent document.documentElement.appendChild @iframeElement @hide() + @addEventListener "message", handleHideMessage + # Open a port and pass it to the iframe via window.postMessage. openPort: -> messageChannel = new MessageChannel() @@ -30,6 +32,7 @@ class UIComponent handleMessage: (event) -> for listener in @messageEventListeners retVal = listener.call this, event + retVal ?= true return false unless retVal true @@ -60,7 +63,15 @@ class UIComponent hide: -> return unless @iframeElement? @iframeElement.setAttribute "style", @hideStyle + window.focus() @showing = false +handleHideMessage = (event) -> + if event.data == "hide" + @hide() + false + else + true + root = exports ? window root.UIComponent = UIComponent -- cgit v1.2.3