fix polyfills, add ie11 support

This commit is contained in:
Hakim El Hattab
2020-05-26 09:46:50 +02:00
parent b074050a6d
commit e6244a57b5
17 changed files with 129 additions and 142 deletions

View File

@ -85,6 +85,27 @@ export const transformElement = ( element, transform ) => {
}
/**
* Element.matches with IE support.
*
* @param {HTMLElement} target The element to match
* @param {String} selector The CSS selector to match
* the element against
*
* @return {Boolean}
*/
export const matchesSelector = ( target, selector ) => {
// There's some overhead doing this each time, we don't
// want to rewrite the element prototype but should still
// be enough to feature detect once at startup...
let matchesMethod = parent.matches || parent.matchesSelector || parent.msMatchesSelector;
// If we find a match, we're all set
return !!( matchesMethod && matchesMethod.call( target, selector ) );
}
/**
* Find the closest parent that matches the given
* selector.
@ -102,13 +123,8 @@ export const closestParent = ( target, selector ) => {
while( parent ) {
// There's some overhead doing this each time, we don't
// want to rewrite the element prototype but should still
// be enough to feature detect once at startup...
let matchesMethod = parent.matches || parent.matchesSelector || parent.msMatchesSelector;
// If we find a match, we're all set
if( matchesMethod && matchesMethod.call( parent, selector ) ) {
if( matchesSelector( parent, selector ) ) {
return parent;
}