(el)
| 1 | import { isUndefined } from './type-check'; |
| 2 | |
| 3 | export 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 | |
| 46 | export function getOffsetParent(el) { |
| 47 | return el.offsetParent || document.documentElement; |
no test coverage detected
searching dependent graphs…