diff options
| author | Stephen Blott | 2015-07-01 06:12:02 +0100 |
|---|---|---|
| committer | Stephen Blott | 2015-07-01 06:12:05 +0100 |
| commit | 2cc7dc1d2164b5dbb27bcc1d4bc0517402dd7581 (patch) | |
| tree | 2784937bb83849959ebbfc221ed0566514abf01e | |
| parent | 1042251c210b22036c3a847df46b1c44b7d87cfe (diff) | |
| download | vimium-2cc7dc1d2164b5dbb27bcc1d4bc0517402dd7581.tar.bz2 | |
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.
| -rw-r--r-- | content_scripts/link_hints.coffee | 27 |
1 files 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 |
