Skip to content

Commit

Permalink
fix(isSkipLink): cache first page link (#1525)
Browse files Browse the repository at this point in the history
  • Loading branch information
straker authored May 1, 2019
1 parent 9cea13d commit 6a1bcba
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions lib/commons/dom/is-skip-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,21 @@ dom.isSkipLink = function(element) {
return false;
}

// define a skip link as any anchor element whose href starts with `#...`
// and which precedes the first anchor element whose href doesn't start
// with `#...` (that is, a link to a page)
const firstPageLink = axe.utils.querySelectorAll(
axe._tree,
'a:not([href^="#"]):not([href^="/#"]):not([href^="javascript"])'
)[0];
let firstPageLink;
if (typeof axe._cache.firstPageLink !== 'undefined') {
firstPageLink = axe._cache.firstPageLink;
} else {
// define a skip link as any anchor element whose href starts with `#...`
// and which precedes the first anchor element whose href doesn't start
// with `#...` (that is, a link to a page)
firstPageLink = axe.utils.querySelectorAll(
axe._tree,
'a:not([href^="#"]):not([href^="/#"]):not([href^="javascript"])'
)[0];

// null will signify no first page link
axe._cache.firstPageLink = firstPageLink || null;
}

// if there are no page links then all all links will need to be
// considered as skip links
Expand Down

0 comments on commit 6a1bcba

Please sign in to comment.