Sha256: 95952f179b318761033607764f8a0f5cee4f0d53bdd1323a71ba971255b4b968

Contents?: true

Size: 1.21 KB

Versions: 271

Compression:

Stored size: 1.21 KB

Contents

/* global dom */

// test for hrefs that start with # or /# (for angular)
const isInternalLinkRegex = /^\/?#[^/!]/;

/**
 * Determines if element is a skip link
 * @method isSkipLink
 * @memberof axe.commons.dom
 * @instance
 * @param  {Element} element
 * @return {Boolean}
 */
dom.isSkipLink = function(element) {
	if (!isInternalLinkRegex.test(element.getAttribute('href'))) {
		return false;
	}

	let firstPageLink;
	if (typeof axe._cache.get('firstPageLink') !== 'undefined') {
		firstPageLink = axe._cache.get('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.set('firstPageLink', firstPageLink || null);
	}

	// if there are no page links then all all links will need to be
	// considered as skip links
	if (!firstPageLink) {
		return true;
	}

	return (
		element.compareDocumentPosition(firstPageLink.actualNode) ===
		element.DOCUMENT_POSITION_FOLLOWING
	);
};

Version data entries

271 entries across 271 versions & 1 rubygems

Version Path
govuk_publishing_components-30.4.1 node_modules/axe-core/lib/commons/dom/is-skip-link.js
govuk_publishing_components-30.4.0 node_modules/axe-core/lib/commons/dom/is-skip-link.js
govuk_publishing_components-30.3.0 node_modules/axe-core/lib/commons/dom/is-skip-link.js
govuk_publishing_components-30.2.1 node_modules/axe-core/lib/commons/dom/is-skip-link.js
govuk_publishing_components-30.2.0 node_modules/axe-core/lib/commons/dom/is-skip-link.js
govuk_publishing_components-30.1.0 node_modules/axe-core/lib/commons/dom/is-skip-link.js
govuk_publishing_components-30.0.0 node_modules/axe-core/lib/commons/dom/is-skip-link.js
govuk_publishing_components-29.15.3 node_modules/axe-core/lib/commons/dom/is-skip-link.js
govuk_publishing_components-29.15.2 node_modules/axe-core/lib/commons/dom/is-skip-link.js
govuk_publishing_components-29.15.1 node_modules/axe-core/lib/commons/dom/is-skip-link.js
govuk_publishing_components-29.15.0 node_modules/axe-core/lib/commons/dom/is-skip-link.js
govuk_publishing_components-29.14.0 node_modules/axe-core/lib/commons/dom/is-skip-link.js
govuk_publishing_components-29.13.0 node_modules/axe-core/lib/commons/dom/is-skip-link.js
govuk_publishing_components-29.12.1 node_modules/axe-core/lib/commons/dom/is-skip-link.js
govuk_publishing_components-29.12.0 node_modules/axe-core/lib/commons/dom/is-skip-link.js
govuk_publishing_components-29.11.0 node_modules/axe-core/lib/commons/dom/is-skip-link.js
govuk_publishing_components-29.10.0 node_modules/axe-core/lib/commons/dom/is-skip-link.js
govuk_publishing_components-29.9.0 node_modules/axe-core/lib/commons/dom/is-skip-link.js
govuk_publishing_components-29.8.0 node_modules/axe-core/lib/commons/dom/is-skip-link.js
govuk_publishing_components-29.7.0 node_modules/axe-core/lib/commons/dom/is-skip-link.js