amis/examples/polyfills/cloest.ts

26 lines
623 B
TypeScript
Raw Normal View History

2019-08-05 11:11:08 +08:00
/**
* @file
* @author mdn
*/
if (!Element.prototype.matches) {
Element.prototype.matches = Element.prototype.msMatchesSelector
|| Element.prototype.webkitMatchesSelector;
}
if (!Element.prototype.closest) {
Element.prototype.closest = function (s) {
var el = this;
if (!document.documentElement.contains(el)) {
return null;
}
do {
if (el.matches(s)) {
return el;
}
el = el.parentElement;
} while (el !== null);
return null;
};
}