[Canvas] Fix incompatible ie11 method (#50007)

* Fix incompatible ie11 method

* Comment about origin of polyfill
This commit is contained in:
Corey Robertson 2019-11-13 08:59:50 -05:00 committed by GitHub
parent 3a2e865b2f
commit 7bb968c554
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -58,6 +58,21 @@ const configuration = {
tooltipZ: 1100,
};
// Polyfill for browsers (IE11) that don't have element.closest
// From: https://developer.mozilla.org/en-US/docs/Web/API/Element/closest
function closest(s) {
let el = this;
const matchFn = el.matches ? 'matches' : 'msMatchesSelector';
do {
if (el[matchFn](s)) {
return el;
}
el = el.parentElement || el.parentNode;
} while (el !== null && el.nodeType === 1);
return null;
}
const componentLayoutState = ({
aeroStore,
setAeroStore,
@ -197,8 +212,15 @@ export const InteractivePage = compose(
})),
withProps((...props) => ({
...props,
canDragElement: element =>
!element.closest('.embeddable') || element.closest('.embPanel__header'),
canDragElement: element => {
const hasClosest = typeof element.closest === 'function';
if (hasClosest) {
return !element.closest('.embeddable') || element.closest('.embPanel__header');
} else {
return !closest.call(element, '.embeddable') || closest.call(element, '.embPanel__header');
}
},
})),
withHandlers(eventHandlers), // Captures user intent, needs to have reconciled state
() => InteractiveComponent