From f7c1431c1f9bbd7f40934fe32f30449cd81f99a3 Mon Sep 17 00:00:00 2001 From: Daniel Skogly Date: Thu, 18 Jun 2015 12:55:54 +0200 Subject: Added hasNgClick-check in getVisibleClickable There's a fair amount of angular-sites running around, so including ngClick (with all its valid variations) seems like a good idea. I added a hasNgClick-check in the if block that checks if an element is clickable regardless of tagName.--- content_scripts/link_hints.coffee | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee index 15af15c5..770a4639 100644 --- a/content_scripts/link_hints.coffee +++ b/content_scripts/link_hints.coffee @@ -166,12 +166,25 @@ class LinkHintsMode if (element.getAttribute("aria-hidden")?.toLowerCase() in ["", "true"] or element.getAttribute("aria-disabled")?.toLowerCase() in ["", "true"]) return [] # This element should never have a link hint. + + # checks for every valid version of ng-click + ngPrefixes = ['', 'data-', 'x-'] + ngSeparators = ['-', ':', '_'] + ng = 'ng' + click = 'click' + hasNgClick: (element) -> + for prefix in ngPrefixes + for separator in ngSeparators + attr = prefix + ng + separator + click + if element.attributes.hasOwnProperty(attr) + return true # Check for attributes that make an element clickable regardless of its tagName. if (element.hasAttribute("onclick") or element.getAttribute("role")?.toLowerCase() in ["button", "link"] or element.getAttribute("class")?.toLowerCase().indexOf("button") >= 0 or - element.getAttribute("contentEditable")?.toLowerCase() in ["", "contentEditable", "true"]) + element.getAttribute("contentEditable")?.toLowerCase() in ["", "contentEditable", "true"]) or + hasNgClick element isClickable = true # Check for jsaction event listeners on the element. -- cgit v1.2.3 From 2ea38efb65759a6a396bec7134c65880e71f9bcb Mon Sep 17 00:00:00 2001 From: Daniel Skogly Date: Thu, 18 Jun 2015 13:09:55 +0200 Subject: Proper function definition Changed from : to =--- content_scripts/link_hints.coffee | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee index 770a4639..1f15bfe8 100644 --- a/content_scripts/link_hints.coffee +++ b/content_scripts/link_hints.coffee @@ -166,25 +166,26 @@ class LinkHintsMode if (element.getAttribute("aria-hidden")?.toLowerCase() in ["", "true"] or element.getAttribute("aria-disabled")?.toLowerCase() in ["", "true"]) return [] # This element should never have a link hint. - - # checks for every valid version of ng-click - ngPrefixes = ['', 'data-', 'x-'] - ngSeparators = ['-', ':', '_'] - ng = 'ng' - click = 'click' - hasNgClick: (element) -> - for prefix in ngPrefixes - for separator in ngSeparators - attr = prefix + ng + separator + click - if element.attributes.hasOwnProperty(attr) - return true + + # checks for every valid version of ng-click + ngPrefixes = ['', 'data-', 'x-'] + ngSeparators = ['-', ':', '_'] + ng = 'ng' + click = 'click' + hasNgClick = () -> + for prefix in ngPrefixes + for separator in ngSeparators + attr = prefix + ng + separator + click + if element.attributes.hasOwnProperty(attr) + return true + return false # Check for attributes that make an element clickable regardless of its tagName. if (element.hasAttribute("onclick") or element.getAttribute("role")?.toLowerCase() in ["button", "link"] or element.getAttribute("class")?.toLowerCase().indexOf("button") >= 0 or element.getAttribute("contentEditable")?.toLowerCase() in ["", "contentEditable", "true"]) or - hasNgClick element + hasNgClick isClickable = true # Check for jsaction event listeners on the element. -- cgit v1.2.3 From 8c161c8e03d112f74ca4fde8981927276c1388a5 Mon Sep 17 00:00:00 2001 From: Daniel Skogly Date: Thu, 18 Jun 2015 13:29:06 +0200 Subject: Proper function call CoffeeScript is not my native tongue.--- content_scripts/link_hints.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee index 1f15bfe8..2f9c6af2 100644 --- a/content_scripts/link_hints.coffee +++ b/content_scripts/link_hints.coffee @@ -185,7 +185,7 @@ class LinkHintsMode element.getAttribute("role")?.toLowerCase() in ["button", "link"] or element.getAttribute("class")?.toLowerCase().indexOf("button") >= 0 or element.getAttribute("contentEditable")?.toLowerCase() in ["", "contentEditable", "true"]) or - hasNgClick + hasNgClick() isClickable = true # Check for jsaction event listeners on the element. -- cgit v1.2.3 From 481c162aa047ab5c7169069303bcdbed73051e8d Mon Sep 17 00:00:00 2001 From: Daniel Skogly Date: Fri, 19 Jun 2015 22:07:08 +0200 Subject: Clarifications to ngClick check --- content_scripts/link_hints.coffee | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee index 2f9c6af2..37758c95 100644 --- a/content_scripts/link_hints.coffee +++ b/content_scripts/link_hints.coffee @@ -167,25 +167,26 @@ class LinkHintsMode element.getAttribute("aria-disabled")?.toLowerCase() in ["", "true"]) return [] # This element should never have a link hint. - # checks for every valid version of ng-click + # The quite popular (http://w3techs.com/technologies/market/javascript_library/20) JavaScript framework AngularJS + # uses the proprietary click attribute "ng-click". This checks for every valid way it may occur. ngPrefixes = ['', 'data-', 'x-'] ngSeparators = ['-', ':', '_'] - ng = 'ng' - click = 'click' hasNgClick = () -> for prefix in ngPrefixes for separator in ngSeparators - attr = prefix + ng + separator + click - if element.attributes.hasOwnProperty(attr) + attr = "#{prefix}ng#{separator}click" + if element.hasAttribute(attr) return true return false + + if hasNgClick() + isClickable = true # Check for attributes that make an element clickable regardless of its tagName. if (element.hasAttribute("onclick") or element.getAttribute("role")?.toLowerCase() in ["button", "link"] or element.getAttribute("class")?.toLowerCase().indexOf("button") >= 0 or - element.getAttribute("contentEditable")?.toLowerCase() in ["", "contentEditable", "true"]) or - hasNgClick() + element.getAttribute("contentEditable")?.toLowerCase() in ["", "contentEditable", "true"]) isClickable = true # Check for jsaction event listeners on the element. -- cgit v1.2.3 From 1042251c210b22036c3a847df46b1c44b7d87cfe Mon Sep 17 00:00:00 2001 From: Daniel Skogly Date: Fri, 19 Jun 2015 23:44:48 +0200 Subject: More concise comment Because I apparently can't read docs properly!--- content_scripts/link_hints.coffee | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee index 37758c95..327d622a 100644 --- a/content_scripts/link_hints.coffee +++ b/content_scripts/link_hints.coffee @@ -167,8 +167,7 @@ class LinkHintsMode element.getAttribute("aria-disabled")?.toLowerCase() in ["", "true"]) return [] # This element should never have a link hint. - # The quite popular (http://w3techs.com/technologies/market/javascript_library/20) JavaScript framework AngularJS - # uses the proprietary click attribute "ng-click". This checks for every valid way it may occur. + # Check for AngularJS listeners on the element. ngPrefixes = ['', 'data-', 'x-'] ngSeparators = ['-', ':', '_'] hasNgClick = () -> -- cgit v1.2.3 From 26547bc1f17df068ae131b512f5419cb2aefecb0 Mon Sep 17 00:00:00 2001 From: Daniel Skogly Date: Sat, 20 Jun 2015 11:51:53 +0200 Subject: Tweaks In regards to https://github.com/philc/vimium/commit/9475c51932fc3331e515886b0495c5b86a1a9e65--- content_scripts/link_hints.coffee | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee index 327d622a..ba550c04 100644 --- a/content_scripts/link_hints.coffee +++ b/content_scripts/link_hints.coffee @@ -167,19 +167,19 @@ class LinkHintsMode element.getAttribute("aria-disabled")?.toLowerCase() in ["", "true"]) return [] # This element should never have a link hint. - # Check for AngularJS listeners on the element. + # Check for AngularJS listeners on the element. These are becoming increasingly preferred instead of + # Javascript's native onclick listeners. ngPrefixes = ['', 'data-', 'x-'] ngSeparators = ['-', ':', '_'] hasNgClick = () -> for prefix in ngPrefixes for separator in ngSeparators attr = "#{prefix}ng#{separator}click" - if element.hasAttribute(attr) + if element.hasAttribute attr return true return false - if hasNgClick() - isClickable = true + isClickable ||= hasNgClick() # Check for attributes that make an element clickable regardless of its tagName. if (element.hasAttribute("onclick") or -- cgit v1.2.3 From 2cc7dc1d2164b5dbb27bcc1d4bc0517402dd7581 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Wed, 1 Jul 2015 06:12:02 +0100 Subject: Re-work angularJS checks. Re-working of @poacher2k's ideas from #1745. - check whether AngularJS is being used. - avoid building the AngularJS attribute strings multiple times. - avoid building them *at all* if AngularJS is not being used. --- content_scripts/link_hints.coffee | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee index 327d622a..aae94686 100644 --- a/content_scripts/link_hints.coffee +++ b/content_scripts/link_hints.coffee @@ -168,18 +168,21 @@ class LinkHintsMode return [] # This element should never have a link hint. # Check for AngularJS listeners on the element. - ngPrefixes = ['', 'data-', 'x-'] - ngSeparators = ['-', ':', '_'] - hasNgClick = () -> - for prefix in ngPrefixes - for separator in ngSeparators - attr = "#{prefix}ng#{separator}click" - if element.hasAttribute(attr) - return true - return false - - if hasNgClick() - isClickable = true + @checkForAngularJs ?= do -> + angularElements = document.body.getElementsByClassName "ng-scope" + if angularElements.length == 0 + -> false + else + ngAttributes = [] + for prefix in [ '', 'data-', 'x-' ] + for separator in [ '-', ':', '_' ] + ngAttributes.push "#{prefix}ng#{separator}click" + (element) -> + for attribute in ngAttributes + return true if element.hasAttribute attribute + false + + isClickable ||= @checkForAngularJs element # Check for attributes that make an element clickable regardless of its tagName. if (element.hasAttribute("onclick") or -- cgit v1.2.3 From 81fed96e2600917b23e810062beafd688aa17460 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Thu, 2 Jul 2015 05:21:48 +0100 Subject: Better angularJS detection. See @mrmr1993's comment in 2cc7dc1d2164b5dbb27bcc1d4bc0517402dd7581. --- content_scripts/link_hints.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee index aae94686..8e106b0f 100644 --- a/content_scripts/link_hints.coffee +++ b/content_scripts/link_hints.coffee @@ -169,7 +169,7 @@ class LinkHintsMode # Check for AngularJS listeners on the element. @checkForAngularJs ?= do -> - angularElements = document.body.getElementsByClassName "ng-scope" + angularElements = document.getElementsByClassName "ng-scope" if angularElements.length == 0 -> false else -- cgit v1.2.3