@findify/mjs
Version:
Findify widgets
36 lines (29 loc) • 702 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
/**
* Find closest element by child
* @param selector Parent selector
*/
exports.default = function (selector) {
return function (el) {
var matchesFn;
var parent;
['matches', 'webkitMatchesSelector', 'mozMatchesSelector', 'msMatchesSelector', 'oMatchesSelector'].some(function (fn) {
if (typeof document.body[fn] === 'function') {
matchesFn = fn;
return true;
}
return false;
});
while (el) {
parent = el.parentElement;
if (parent && parent[matchesFn](selector)) {
return parent;
}
el = parent;
}
return null;
};
};