|
|
@@ -100,7 +100,6 @@ export function listenViaDelegation(container: HTMLElement, eventType, childClas
|
|
|
}
|
|
|
|
|
|
// from https://developer.mozilla.org/en-US/docs/Web/API/Element/closest
|
|
|
-// TODO: research leaner fallback
|
|
|
const matchesMethod =
|
|
|
Element.prototype.matches ||
|
|
|
(Element.prototype as any).matchesSelector ||
|
|
|
@@ -109,28 +108,13 @@ const matchesMethod =
|
|
|
(Element.prototype as any).oMatchesSelector ||
|
|
|
(Element.prototype as any).webkitMatchesSelector
|
|
|
|
|
|
-;[
|
|
|
- 'matches',
|
|
|
- 'matchesSelector',
|
|
|
- 'mozMatchesSelector',
|
|
|
- 'msMatchesSelector',
|
|
|
- 'oMatchesSelector',
|
|
|
- 'webkitMatchesSelector'
|
|
|
-].forEach(function(name) {
|
|
|
- if (Element.prototype[name]) {
|
|
|
- console.log(name + ' exists')
|
|
|
- } else {
|
|
|
- console.log(name + ' does NOT exist')
|
|
|
- }
|
|
|
-})
|
|
|
-
|
|
|
const closestMethod = Element.prototype.closest || function(selector) {
|
|
|
let el = this
|
|
|
if (!document.documentElement.contains(el)) {
|
|
|
return null
|
|
|
}
|
|
|
do {
|
|
|
- if (matchesMethod.call(el, selector)) {
|
|
|
+ if (elementMatches(el, selector)) {
|
|
|
return el
|
|
|
}
|
|
|
el = el.parentElement || el.parentNode
|