diff options
| author | Stephen Blott | 2015-04-29 13:38:37 +0100 |
|---|---|---|
| committer | Stephen Blott | 2015-04-29 13:38:37 +0100 |
| commit | acfa46cea94e951bc4955affe90db04675eda882 (patch) | |
| tree | 2b6abf8264a9158fb6f9fecb002a60502c67ce93 /content_scripts/ui_component.coffee | |
| parent | dafe48a3e5f17d2b3380813a8dc9e5122def60b8 (diff) | |
| parent | 38d54bff35477939b837b917d1148e7e6b02e0cb (diff) | |
| download | vimium-acfa46cea94e951bc4955affe90db04675eda882.tar.bz2 | |
Merge pull request #1614 from mrmr1993/shadowDom-UIComponents
Use a shadowDom for the Vomnibar (and all UIComponents)
Diffstat (limited to 'content_scripts/ui_component.coffee')
| -rw-r--r-- | content_scripts/ui_component.coffee | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/content_scripts/ui_component.coffee b/content_scripts/ui_component.coffee index 77c52d3d..21431bd7 100644 --- a/content_scripts/ui_component.coffee +++ b/content_scripts/ui_component.coffee @@ -5,12 +5,29 @@ class UIComponent options: null constructor: (iframeUrl, className, @handleMessage) -> + styleSheet = document.createElement "style" + styleSheet.type = "text/css" + # Default to everything hidden while the stylesheet loads. + styleSheet.innerHTML = "* {display: none !important;}" + # Load stylesheet. + xhr = new XMLHttpRequest() + xhr.onload = (e) -> styleSheet.innerHTML = xhr.responseText + xhr.open "GET", chrome.runtime.getURL("content_scripts/vimium.css"), true + xhr.send() + @iframeElement = document.createElement "iframe" - @iframeElement.className = className - @iframeElement.seamless = "seamless" - @iframeElement.src = chrome.runtime.getURL iframeUrl + extend @iframeElement, + className: className + seamless: "seamless" + src: chrome.runtime.getURL iframeUrl @iframeElement.addEventListener "load", => @openPort() - document.documentElement.appendChild @iframeElement + shadowWrapper = document.createElement "div" + # PhantomJS doesn't support createShadowRoot, so guard against its non-existance. + shadowDOM = shadowWrapper.createShadowRoot?() ? shadowWrapper + shadowDOM.appendChild styleSheet + shadowDOM.appendChild @iframeElement + document.documentElement.appendChild shadowWrapper + @showing = true # The iframe is visible now. # Hide the iframe, but don't interfere with the focus. @hide false |
