MCPcopy Create free account
hub / github.com/shipshapecode/tether / getScrollParents

Function getScrollParents

src/js/utils/parents.js:3–44  ·  view source on GitHub ↗
(el)

Source from the content-addressed store, hash-verified

1import { isUndefined } from './type-check';
2
3export function getScrollParents(el) {
4 // In firefox if the el is inside an iframe with display: none; window.getComputedStyle() will return null;
5 // https://bugzilla.mozilla.org/show_bug.cgi?id=548397
6 const computedStyle = getComputedStyle(el) || {};
7 const { position } = computedStyle;
8 let parents = [];
9
10 if (position === 'fixed') {
11 return [el];
12 }
13
14 let parent = el;
15 while ((parent = parent.parentNode) && parent && parent.nodeType === 1) {
16 let style;
17 try {
18 style = getComputedStyle(parent);
19 } catch (err) {
20 // Intentionally blank
21 }
22
23 if (isUndefined(style) || style === null) {
24 parents.push(parent);
25 return parents;
26 }
27
28 const { overflow, overflowX, overflowY } = style;
29 if (/(auto|scroll|overlay)/.test(overflow + overflowY + overflowX)) {
30 if (position !== 'absolute' || ['relative', 'absolute', 'fixed'].indexOf(style.position) >= 0) {
31 parents.push(parent);
32 }
33 }
34 }
35
36 parents.push(el.ownerDocument.body);
37
38 // If the node is within a frame, account for the parent window scroll
39 if (el.ownerDocument !== document) {
40 parents.push(el.ownerDocument.defaultView);
41 }
42
43 return parents;
44}
45
46export function getOffsetParent(el) {
47 return el.offsetParent || document.documentElement;

Callers 2

parents.spec.jsFile · 0.90
setOptionsMethod · 0.90

Calls 1

isUndefinedFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…