Sha256: 7a2bea336c8cf03083ecaaff0bbf559121995d3c7f9d5bf8a9714d77131174ec

Contents?: true

Size: 1.47 KB

Versions: 104

Compression:

Stored size: 1.47 KB

Contents

/* global dom */
/* eslint complexity: ["error",15] */

/**
 * Checks whether a parent element visually overlaps a rectangle, either directly or via scrolling.
 * @method visuallyOverlaps
 * @memberof axe.commons.dom
 * @instance
 * @param {DOMRect} rect
 * @param {Element} parent
 * @return {boolean} True if rect is visually contained within parent
 */
dom.visuallyOverlaps = function(rect, parent) {
	var parentRect = parent.getBoundingClientRect();
	var parentTop = parentRect.top;
	var parentLeft = parentRect.left;
	var parentScrollArea = {
		top: parentTop - parent.scrollTop,
		bottom: parentTop - parent.scrollTop + parent.scrollHeight,
		left: parentLeft - parent.scrollLeft,
		right: parentLeft - parent.scrollLeft + parent.scrollWidth
	};

	//In theory, we should just be able to look at the scroll area as a superset of the parentRect,
	//but that's not true in Firefox
	if (
		(rect.left > parentScrollArea.right && rect.left > parentRect.right) ||
		(rect.top > parentScrollArea.bottom && rect.top > parentRect.bottom) ||
		(rect.right < parentScrollArea.left && rect.right < parentRect.left) ||
		(rect.bottom < parentScrollArea.top && rect.bottom < parentRect.top)
	) {
		return false;
	}

	var style = window.getComputedStyle(parent);

	if (rect.left > parentRect.right || rect.top > parentRect.bottom) {
		return (
			style.overflow === 'scroll' ||
			style.overflow === 'auto' ||
			parent instanceof HTMLBodyElement ||
			parent instanceof HTMLHtmlElement
		);
	}

	return true;
};

Version data entries

104 entries across 104 versions & 1 rubygems

Version Path
govuk_publishing_components-21.16.3 node_modules/axe-core/lib/commons/dom/visually-overlaps.js
govuk_publishing_components-21.16.2 node_modules/axe-core/lib/commons/dom/visually-overlaps.js
govuk_publishing_components-21.16.1 node_modules/axe-core/lib/commons/dom/visually-overlaps.js
govuk_publishing_components-21.16.0 node_modules/axe-core/lib/commons/dom/visually-overlaps.js
govuk_publishing_components-21.15.2 node_modules/axe-core/lib/commons/dom/visually-overlaps.js
govuk_publishing_components-21.15.1 node_modules/axe-core/lib/commons/dom/visually-overlaps.js
govuk_publishing_components-21.15.0 node_modules/axe-core/lib/commons/dom/visually-overlaps.js
govuk_publishing_components-21.14.0 node_modules/axe-core/lib/commons/dom/visually-overlaps.js
govuk_publishing_components-21.13.5 node_modules/axe-core/lib/commons/dom/visually-overlaps.js
govuk_publishing_components-21.13.4 node_modules/axe-core/lib/commons/dom/visually-overlaps.js
govuk_publishing_components-21.13.3 node_modules/axe-core/lib/commons/dom/visually-overlaps.js
govuk_publishing_components-21.13.2 node_modules/axe-core/lib/commons/dom/visually-overlaps.js
govuk_publishing_components-21.13.1 node_modules/axe-core/lib/commons/dom/visually-overlaps.js
govuk_publishing_components-21.13.0 node_modules/axe-core/lib/commons/dom/visually-overlaps.js
govuk_publishing_components-21.12.0 node_modules/axe-core/lib/commons/dom/visually-overlaps.js
govuk_publishing_components-21.11.0 node_modules/axe-core/lib/commons/dom/visually-overlaps.js
govuk_publishing_components-21.10.0 node_modules/axe-core/lib/commons/dom/visually-overlaps.js
govuk_publishing_components-21.9.0 node_modules/axe-core/lib/commons/dom/visually-overlaps.js
govuk_publishing_components-21.8.1 node_modules/axe-core/lib/commons/dom/visually-overlaps.js
govuk_publishing_components-21.8.0 node_modules/axe-core/lib/commons/dom/visually-overlaps.js