diff options
Diffstat (limited to 'lib/dom_utils.coffee')
| -rw-r--r-- | lib/dom_utils.coffee | 36 | 
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/dom_utils.coffee b/lib/dom_utils.coffee index a0ac0bd3..26fa9b81 100644 --- a/lib/dom_utils.coffee +++ b/lib/dom_utils.coffee @@ -42,6 +42,42 @@ DomUtils =      document.evaluate(xpath, document.documentElement, namespaceResolver, resultType, null)    # +  # Returns all the clickable element children of contextNode. This also can include contextNode itself. +  # +  getClickableElements: (contextNode = document.documentElement) -> +    elements = Array::slice.call(contextNode?.getElementsByTagName "*") +    elements.unshift contextNode # Check the contextNode as well. +    clickableElements = [] +    for element in elements +      isClickable = false +      tagName = element.tagName.toLowerCase() +      isClickable = (-> +        if element.hasAttribute "onclick" +          true +        else if element.hasAttribute "tabindex" +          true +        else if element.getAttribute "role" in ["button", "link"] +          true +        else if element.getAttribute("class")?.toLowerCase().indexOf("button") >= 0 +          true +        else if element.getAttribute("contentEditable")?.toLowerCase() in ["", "contentEditable", "true"] +          true +        else if tagName == "a" +          true +        else if tagName == "area" +          element.hasAttribute "href" +        else if (tagName == "input" and DomUtils.isSelectable element) or tagName == "textarea" +          not (element.disabled or element.hasAttribute "readonly") +        else if (tagName == "input" and element.getAttribute("type")?.toLowerCase() != "hidden") or +                tagName in ["button", "select"] +          not element.disabled +        else +          false +      )() +      clickableElements.push element if isClickable +    clickableElements + +  #    # Returns the first visible clientRect of an element if it exists. Otherwise it returns null.    #    getVisibleClientRect: (element) ->  | 
