From dfb2c58e3d76cfc0131a1e30cba4ae8d23853726 Mon Sep 17 00:00:00 2001 From: Jez Ng Date: Sun, 19 Aug 2012 23:27:44 -0700 Subject: 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. --- lib/dom_utils.coffee | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'lib/dom_utils.coffee') 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,4 +1,19 @@ 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 # @@ -7,6 +22,19 @@ DomUtils = window.addEventListener("DOMContentLoaded", -> loaded = true) (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. # -- cgit v1.2.3