diff options
| author | Jez Ng | 2012-08-19 23:27:44 -0700 |
|---|---|---|
| committer | Jez Ng | 2012-08-20 00:43:45 -0700 |
| commit | dfb2c58e3d76cfc0131a1e30cba4ae8d23853726 (patch) | |
| tree | 13632f0978351f03e0142a9b1fa8bafaf2302537 /lib/dom_utils.coffee | |
| parent | c2257a03126c0e7af77e3c0697498a18c7f6be06 (diff) | |
| download | vimium-dfb2c58e3d76cfc0131a1e30cba4ae8d23853726.tar.bz2 | |
More refactoring-cleanup.
* vimium_frontend now has a pretty decent set of exports
* Generic linkHints code has been moved to DomUtils, so future features
can reuse the code.
Diffstat (limited to 'lib/dom_utils.coffee')
| -rw-r--r-- | lib/dom_utils.coffee | 28 |
1 files changed, 28 insertions, 0 deletions
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 |
