From 57418a9ad6104c487b67fcfd27ec8503858e5a14 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Mon, 29 Dec 2014 18:55:06 +0000 Subject: Use UIComponent for Vomnibar iframe --- content_scripts/ui_component.coffee | 2 +- content_scripts/vimium_frontend.coffee | 3 +-- content_scripts/vomnibar.coffee | 42 ++++++++++------------------------ 3 files changed, 14 insertions(+), 33 deletions(-) (limited to 'content_scripts') diff --git a/content_scripts/ui_component.coffee b/content_scripts/ui_component.coffee index d89f0cc8..696cb42c 100644 --- a/content_scripts/ui_component.coffee +++ b/content_scripts/ui_component.coffee @@ -42,7 +42,7 @@ class UIComponent @showing = true @iframeElement.focus() - hide: (focusWindow=true)-> + hide: (focusWindow = true)-> if @showing @iframeElement.setAttribute "style", @hideStyle window.focus() if focusWindow diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 2de08c39..ae275f0c 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -139,8 +139,6 @@ initializePreDomReady = -> getActiveState: -> { enabled: isEnabledForUrl, passKeys: passKeys } setState: setState currentKeyQueue: (request) -> keyQueue = request.keyQueue - vomnibarShow: -> Vomnibar.show() - vomnibarClose: -> Vomnibar.close() chrome.runtime.onMessage.addListener (request, sender, sendResponse) -> # In the options page, we will receive requests from both content and background scripts. ignore those @@ -202,6 +200,7 @@ initializeOnDomReady = -> # Tell the background page we're in the dom ready state. chrome.runtime.connect({ name: "domReady" }) CursorHider.init() + Vomnibar.init() registerFrame = -> # Don't register frameset containers; focusing them is no use. diff --git a/content_scripts/vomnibar.coffee b/content_scripts/vomnibar.coffee index 10f75652..6b82d31c 100644 --- a/content_scripts/vomnibar.coffee +++ b/content_scripts/vomnibar.coffee @@ -2,7 +2,7 @@ # This wraps the vomnibar iframe, which we inject into the page to provide the vomnibar. # Vomnibar = - vomnibarElement: null + vomnibarUI: null activate: -> @open {completer:"omni"} activateInNewTab: -> @open { @@ -35,41 +35,23 @@ Vomnibar = newTab: true } + init: -> + unless @vomnibarUI? + @vomnibarUI = new UIComponent "pages/vomnibar.html", "vomnibarFrame", @handleMessage.bind this + + handleMessage: (event) -> + if event.data == "hide" + @hide() + + # This function opens the vomnibar. It accepts options, a map with the values: # completer - The completer to fetch results from. # query - Optional. Text to prefill the Vomnibar with. # selectFirst - Optional, boolean. Whether to select the first entry. # newTab - Optional, boolean. Whether to open the result in a new tab. - open: (options) -> - unless @vomnibarElement? - @vomnibarElement = document.createElement "iframe" - @vomnibarElement.className = "vomnibarFrame" - @vomnibarElement.seamless = "seamless" - @hide() - - options.frameId = frameId - - optionStrings = [] - for option of options - if typeof options[option] == "boolean" - optionStrings.push option if options[option] - else - optionStrings.push "#{option}=#{escape(options[option])}" - - @vomnibarElement.src = "#{chrome.runtime.getURL "pages/vomnibar.html"}?#{optionStrings.join "&"}" - document.documentElement.appendChild @vomnibarElement - - @vomnibarElement.focus() - - close: -> - @hide() - @vomnibarElement?.remove() - - show: -> - @vomnibarElement?.style.display = "block" + open: (options) -> @vomnibarUI.activate options - hide: -> - @vomnibarElement?.style.display = "none" + hide: -> @vomnibarUI?.hide() root = exports ? window root.Vomnibar = Vomnibar -- cgit v1.2.3