Sha256: 27d13bc5c11fc3a0da8d9d94f7fb13477fe7dcabd5b80e2bf06284e92f45c6f9

Contents?: true

Size: 1.43 KB

Versions: 271

Compression:

Stored size: 1.43 KB

Contents

/* global dom */

/**
 * 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

271 entries across 271 versions & 1 rubygems

Version Path
govuk_publishing_components-21.22.1 node_modules/axe-core/lib/commons/dom/visually-overlaps.js
govuk_publishing_components-21.22.0 node_modules/axe-core/lib/commons/dom/visually-overlaps.js
govuk_publishing_components-21.21.3 node_modules/axe-core/lib/commons/dom/visually-overlaps.js
govuk_publishing_components-21.21.2 node_modules/axe-core/lib/commons/dom/visually-overlaps.js
govuk_publishing_components-21.21.1 node_modules/axe-core/lib/commons/dom/visually-overlaps.js
govuk_publishing_components-21.21.0 node_modules/axe-core/lib/commons/dom/visually-overlaps.js
govuk_publishing_components-21.20.0 node_modules/axe-core/lib/commons/dom/visually-overlaps.js
govuk_publishing_components-21.19.1 node_modules/axe-core/lib/commons/dom/visually-overlaps.js
govuk_publishing_components-21.19.0 node_modules/axe-core/lib/commons/dom/visually-overlaps.js
govuk_publishing_components-21.18.0 node_modules/axe-core/lib/commons/dom/visually-overlaps.js
govuk_publishing_components-21.17.0 node_modules/axe-core/lib/commons/dom/visually-overlaps.js