-
Notifications
You must be signed in to change notification settings - Fork 755
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add Object.values polyfill for node <=6 (#4274)
* fix: add Object.values polyfill for node <=6 * rename file * forgot to commit eslint
- Loading branch information
Showing
5 changed files
with
120 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Spelled incorrectly intentionally (backwards compatibility). | ||
export function pollyfillElementsFromPoint() { | ||
if (document.elementsFromPoint) return document.elementsFromPoint; | ||
if (document.msElementsFromPoint) return document.msElementsFromPoint; | ||
|
||
var usePointer = (function () { | ||
var element = document.createElement('x'); | ||
element.style.cssText = 'pointer-events:auto'; | ||
return element.style.pointerEvents === 'auto'; | ||
})(); | ||
|
||
var cssProp = usePointer ? 'pointer-events' : 'visibility'; | ||
var cssDisableVal = usePointer ? 'none' : 'hidden'; | ||
|
||
var style = document.createElement('style'); | ||
style.innerHTML = usePointer | ||
? '* { pointer-events: all }' | ||
: '* { visibility: visible }'; | ||
|
||
return function (x, y) { | ||
var current, i, d; | ||
var elements = []; | ||
var previousPointerEvents = []; | ||
|
||
// startup | ||
document.head.appendChild(style); | ||
|
||
while ( | ||
(current = document.elementFromPoint(x, y)) && | ||
elements.indexOf(current) === -1 | ||
) { | ||
// push the element and its current style | ||
elements.push(current); | ||
|
||
previousPointerEvents.push({ | ||
value: current.style.getPropertyValue(cssProp), | ||
priority: current.style.getPropertyPriority(cssProp) | ||
}); | ||
|
||
// add "pointer-events: none", to get to the underlying element | ||
current.style.setProperty(cssProp, cssDisableVal, 'important'); | ||
} | ||
|
||
// Due to negative index, documentElement could actually not be the last, | ||
// so we'll simply move it to the end | ||
if (elements.indexOf(document.documentElement) < elements.length - 1) { | ||
elements.splice(elements.indexOf(document.documentElement), 1); | ||
elements.push(document.documentElement); | ||
} | ||
|
||
// restore the previous pointer-events values | ||
for ( | ||
i = previousPointerEvents.length; | ||
!!(d = previousPointerEvents[--i]); | ||
|
||
) { | ||
elements[i].style.setProperty( | ||
cssProp, | ||
d.value ? d.value : '', | ||
d.priority | ||
); | ||
} | ||
|
||
// teardown; | ||
document.head.removeChild(style); | ||
|
||
return elements; | ||
}; | ||
} | ||
|
||
if (typeof window.addEventListener === 'function') { | ||
document.elementsFromPoint = pollyfillElementsFromPoint(); | ||
} |