diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/clipboard.coffee | 4 | ||||
| -rw-r--r-- | lib/dom_utils.coffee | 29 | ||||
| -rw-r--r-- | lib/utils.coffee | 6 | 
3 files changed, 26 insertions, 13 deletions
| diff --git a/lib/clipboard.coffee b/lib/clipboard.coffee index 2b28df70..f0fb83b1 100644 --- a/lib/clipboard.coffee +++ b/lib/clipboard.coffee @@ -1,6 +1,6 @@  Clipboard =    _createTextArea: -> -    textArea = document.createElement("textarea") +    textArea = document.createElement "textarea"      textArea.style.position = "absolute"      textArea.style.left = "-100%"      textArea @@ -16,7 +16,7 @@ Clipboard =      document.body.removeChild(textArea)    paste: -> -    textArea = @._createTextArea() +    textArea = @_createTextArea()      document.body.appendChild(textArea)      textArea.focus()      document.execCommand("Paste") diff --git a/lib/dom_utils.coffee b/lib/dom_utils.coffee index 9658df2b..ee7d415f 100644 --- a/lib/dom_utils.coffee +++ b/lib/dom_utils.coffee @@ -8,12 +8,25 @@ DomUtils =      else        func() +  createElement: (tagName) -> +    element = document.createElement tagName +    if element instanceof HTMLElement +      # The document namespace provides (X)HTML elements, so we can use them directly. +      @createElement = (tagName) -> document.createElement tagName +      element +    else +      # The document namespace doesn't give (X)HTML elements, so we create them with the correct namespace +      # manually. +      @createElement = (tagName) -> +        document.createElementNS "http://www.w3.org/1999/xhtml", tagName +      @createElement(tagName) +    #    # 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 = @createElement "div"      parent.id = overlayOptions.id if overlayOptions.id?      parent.className = overlayOptions.className if overlayOptions.className?      parent.appendChild(el) for el in els @@ -82,7 +95,7 @@ DomUtils =            # NOTE(mrmr1993): This ignores floated/absolutely positioned descendants nested within inline            # children.            continue if (computedStyle.getPropertyValue("float") == "none" and -            computedStyle.getPropertyValue("position") != "absolute" and +            not (computedStyle.getPropertyValue("position") in ["absolute", "fixed"]) and              not (clientRect.height == 0 and isInlineZeroHeight() and                0 == computedStyle.getPropertyValue("display").indexOf "inline"))            childClientRect = @getVisibleClientRect child, true @@ -236,7 +249,7 @@ DomUtils =    # momentarily flash a rectangular border to give user some visual feedback    flashRect: (rect) -> -    flashEl = document.createElement("div") +    flashEl = @createElement "div"      flashEl.id = "vimiumFlash"      flashEl.className = "vimiumReset"      flashEl.style.left = rect.left + window.scrollX + "px" @@ -297,7 +310,7 @@ DomUtils =        'letterSpacing', 'wordSpacing' ]      (element, position) -> -      div = document.createElement "div" +      div = @createElement "div"        div.id = "vimium-input-textarea-caret-position-mirror-div"        document.body.appendChild div @@ -315,7 +328,7 @@ DomUtils =        if element.nodeName.toLowerCase() == "input"          div.textContent = div.textContent.replace /\s/g, "\u00a0" -      span = document.createElement "span" +      span = @createElement "span"        span.textContent = element.value.substring(position) || "."        div.appendChild span @@ -357,5 +370,11 @@ DomUtils =            text        texts.join " " +  # Get the element in the DOM hierachy that contains `element`. +  # If the element is rendered in a shadow DOM via a <content> element, the <content> element will be +  # returned, so the shadow DOM is traversed rather than passed over. +  getContainingElement: (element) -> +    element.getDestinationInsertionPoints()[0] or element.parentElement +  root = exports ? window  root.DomUtils = DomUtils diff --git a/lib/utils.coffee b/lib/utils.coffee index d4beff03..90469fad 100644 --- a/lib/utils.coffee +++ b/lib/utils.coffee @@ -19,12 +19,6 @@ Utils =      func = obj[components.pop()]      func.apply(obj, argArray) -  # Creates a single DOM element from :html -  createElementFromHtml: (html) -> -    tmp = document.createElement("div") -    tmp.innerHTML = html -    tmp.firstChild -    escapeHtml: (string) -> string.replace(/</g, "<").replace(/>/g, ">")    # Generates a unique ID | 
