aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--content_scripts/link_hints.coffee26
-rw-r--r--content_scripts/vimium_frontend.coffee17
-rw-r--r--lib/dom_utils.coffee28
-rw-r--r--popup.js2
-rw-r--r--vimium.css2
6 files changed, 39 insertions, 37 deletions
diff --git a/.gitignore b/.gitignore
index 22980f8d..1925b316 100644
--- a/.gitignore
+++ b/.gitignore
@@ -15,3 +15,4 @@ lib/clipboard.js
lib/dom_utils.js
lib/keyboard_utils.js
lib/utils.js
+options/options.js
diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee
index 34ecb431..5cdbc6a7 100644
--- a/content_scripts/link_hints.coffee
+++ b/content_scripts/link_hints.coffee
@@ -54,7 +54,14 @@ LinkHints =
@setOpenLinkMode(openInNewTab, withQueue, copyLinkUrl)
hintMarkers = @markerMatcher.fillInMarkers(@createMarkerFor(el) for el in @getVisibleClickableElements())
- @hintMarkerContainingDiv = @displayHints(hintMarkers)
+
+ DomUtils.addCssToPage(settings.get("userDefinedLinkHintCss"), "vimiumLinkHintCss")
+ # Note(philc): Append these markers as top level children instead of as child nodes to the link itself,
+ # because some clickable elements cannot contain children, e.g. submit buttons. This has the caveat
+ # that if you scroll the page and the link has position=fixed, the marker will not stay fixed.
+ @hintMarkerContainingDiv = DomUtils.addElementList(hintMarkers,
+ { id: "vimiumHintMarkerContainer", className: "vimiumReset" })
+
# handlerStack is declared by vimiumFrontend.js
handlerStack.push({
keydown: @onKeyDownInMode.bind(this, hintMarkers),
@@ -104,23 +111,6 @@ LinkHints =
marker
- displayHints: (hintMarkers) ->
- if (!document.getElementById("vimiumLinkHintCss"))
- # linkHintCss is declared by vimiumFrontend.js and contains the user supplied css overrides.
- addCssToPage(settings.get("userDefinedLinkHintCss"), "vimiumLinkHintCss")
-
- # Note(philc): Append these markers as top level children instead of as child nodes to the link itself,
- # because some clickable elements cannot contain children, e.g. submit buttons. This has the caveat
- # that if you scroll the page and the link has position=fixed, the marker will not stay fixed.
- # Also note that adding these nodes to document.body all at once is significantly faster than one-by-one.
- hintMarkerContainingDiv = document.createElement("div")
- hintMarkerContainingDiv.id = "vimiumHintMarkerContainer"
- hintMarkerContainingDiv.className = "vimiumReset"
- hintMarkerContainingDiv.appendChild(marker) for marker in hintMarkers
-
- document.documentElement.appendChild(hintMarkerContainingDiv)
- hintMarkerContainingDiv
-
#
# Returns all clickable elements that are not hidden and are in the current viewport.
# We prune invisible elements partly for performance reasons, but moreso it's to decrease the number
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee
index 0fc8d518..4de0a695 100644
--- a/content_scripts/vimium_frontend.coffee
+++ b/content_scripts/vimium_frontend.coffee
@@ -977,20 +977,6 @@ Tween =
value = (elapsed / state.duration) * (state.to - state.from) + state.from
state.onUpdate(value)
-#
-# Adds the given CSS to the page.
-#
-addCssToPage = (css, id) ->
- head = document.getElementsByTagName("head")[0]
- if (!head)
- head = document.createElement("head")
- document.documentElement.appendChild(head)
- style = document.createElement("style")
- style.id = id
- style.type = "text/css"
- style.appendChild(document.createTextNode(css))
- head.appendChild(style)
-
initializePreDomReady()
window.addEventListener("DOMContentLoaded", initializeOnDomReady)
@@ -1000,11 +986,8 @@ window.onbeforeunload = ->
scrollX: window.scrollX
scrollY: window.scrollY)
-# TODO(philc): Export a more tighter, more coherent interface.
root = exports ? window
-root.window = window
root.settings = settings
-root.addCssToPage = addCssToPage
root.HUD = HUD
root.handlerStack = handlerStack
root.frameId = frameId
diff --git a/lib/dom_utils.coffee b/lib/dom_utils.coffee
index 924afbbe..57930f80 100644
--- a/lib/dom_utils.coffee
+++ b/lib/dom_utils.coffee
@@ -1,5 +1,20 @@
DomUtils =
#
+ # Adds the given CSS to the page.
+ #
+ addCssToPage: (css, id) ->
+ return if document.getElementById(id)
+ head = document.getElementsByTagName("head")[0]
+ if (!head)
+ head = document.createElement("head")
+ document.documentElement.appendChild(head)
+ style = document.createElement("style")
+ style.id = id
+ style.type = "text/css"
+ style.appendChild(document.createTextNode(css))
+ head.appendChild(style)
+
+ #
# Runs :callback if the DOM has loaded, otherwise runs it on load
#
documentReady: do ->
@@ -8,6 +23,19 @@ DomUtils =
(callback) -> if loaded then callback() else window.addEventListener("DOMContentLoaded", callback)
#
+ # Adds a list of elements to a page.
+ # Note that adding these nodes all at once (via the parent div) is significantly faster than one-by-one.
+ #
+ addElementList: (els, overlayOptions) ->
+ parent = document.createElement("div")
+ parent.id = overlayOptions.id if overlayOptions.id?
+ parent.className = overlayOptions.className if overlayOptions.className?
+ parent.appendChild(el) for el in els
+
+ document.documentElement.appendChild(parent)
+ parent
+
+ #
# Remove an element from its DOM tree.
#
removeElement: (el) -> el.parentNode.removeChild el
diff --git a/popup.js b/popup.js
index 859f30f3..2c98e6ab 100644
--- a/popup.js
+++ b/popup.js
@@ -1,5 +1,5 @@
function onLoad() {
- document.getElementById("optionsLink").setAttribute("href", chrome.extension.getURL("options.html"));
+ document.getElementById("optionsLink").setAttribute("href", chrome.extension.getURL("options/options.html"));
chrome.tabs.getSelected(null, function(tab) {
// The common use case is to disable Vimium at the domain level.
// This regexp will match "http://www.example.com/" from "http://www.example.com/path/to/page.html".
diff --git a/vimium.css b/vimium.css
index 83e3136f..c774b604 100644
--- a/vimium.css
+++ b/vimium.css
@@ -102,7 +102,7 @@ div#vimiumHelpDialog {
margin-left:-320px;
top:50px;
-webkit-box-shadow: rgba(0, 0, 0, 0.4) 0px 0px 6px;
- overflow-y: scroll;
+ overflow-y: auto;
z-index:99999998;
}