Files
remark42/frontend/app/common/closest-polyfill.ts
T
Misha VyrtsevandUmputun 61e594786c Define remark host in runtime (#325)
* convert closest-polyfill to ts

* make remark respect host property in client setup
2019-05-13 10:51:17 -05:00

18 lines
562 B
TypeScript

if (!Element.prototype.matches) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Element.prototype.matches = (Element.prototype as any).msMatchesSelector || Element.prototype.webkitMatchesSelector;
}
if (!Element.prototype.closest) {
Element.prototype.closest = function(s: string) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let el: any = this;
do {
if (el.matches(s)) return el;
el = el.parentElement || el.parentNode;
} while (el !== null && el.nodeType === 1);
return null;
};
}