diff options
| author | Stephen Blott | 2018-02-05 10:27:01 +0000 |
|---|---|---|
| committer | Stephen Blott | 2018-02-05 10:27:01 +0000 |
| commit | 065b57d30d56c5375b2ac0c06b04bd8bac0a3cf6 (patch) | |
| tree | f40e36dba63fc14875ad5a78058d31540ad15cb8 | |
| parent | f3ea08b2e8f22e21e9ff561ecc80dccd6c9f2962 (diff) | |
| download | vimium-065b57d30d56c5375b2ac0c06b04bd8bac0a3cf6.tar.bz2 | |
Create flash frame Shadow DOM element on demand.
It looks like we'll be initialising the Vomnibar on demand (see #2939,
merged). In this case, we should also initialise the flash frame on
demand. This means that *none* of Vimium's UI elements are now created
until they are needed.
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 11310dcf..26aa3492 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -237,25 +237,29 @@ setScrollPosition = ({ scrollX, scrollY }) -> Marks.setPreviousPosition() window.scrollTo scrollX, scrollY -flashFrame = -> -DomUtils.documentReady -> - # Create a shadow DOM wrapping the frame so the page's styles don't interfere with ours. - highlightedFrameElement = DomUtils.createElement "div" - # PhantomJS doesn't support createShadowRoot, so guard against its non-existance. - _shadowDOM = highlightedFrameElement.createShadowRoot?() ? highlightedFrameElement +flashFrame = do -> + highlightedFrameElement = null + + -> + highlightedFrameElement ?= do -> + # Create a shadow DOM wrapping the frame so the page's styles don't interfere with ours. + highlightedFrameElement = DomUtils.createElement "div" + # PhantomJS doesn't support createShadowRoot, so guard against its non-existance. + _shadowDOM = highlightedFrameElement.createShadowRoot?() ? highlightedFrameElement + + # Inject stylesheet. + _styleSheet = DomUtils.createElement "style" + _styleSheet.innerHTML = "@import url(\"#{chrome.runtime.getURL("content_scripts/vimium.css")}\");" + _shadowDOM.appendChild _styleSheet - # Inject stylesheet. - _styleSheet = DomUtils.createElement "style" - _styleSheet.innerHTML = "@import url(\"#{chrome.runtime.getURL("content_scripts/vimium.css")}\");" - _shadowDOM.appendChild _styleSheet + _frameEl = DomUtils.createElement "div" + _frameEl.className = "vimiumReset vimiumHighlightedFrame" + _shadowDOM.appendChild _frameEl - _frameEl = DomUtils.createElement "div" - _frameEl.className = "vimiumReset vimiumHighlightedFrame" - _shadowDOM.appendChild _frameEl + highlightedFrameElement - flashFrame = -> document.documentElement.appendChild highlightedFrameElement - setTimeout (-> highlightedFrameElement.remove()), 200 + Utils.setTimeout 200, -> highlightedFrameElement.remove() # # Called from the backend in order to change frame focus. |
