element-closest-polyfill
Advanced tools
Comparing version
28
index.js
@@ -1,17 +0,15 @@ | ||
(function () { | ||
if (!Element.prototype.matches) { | ||
Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector; | ||
} | ||
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 (!Element.prototype.closest) { | ||
Element.prototype.closest = function (s) { | ||
var el = this; | ||
do { | ||
if (el.matches(s)) return el; | ||
el = el.parentElement || el.parentNode; | ||
} while (el !== null && el.nodeType === 1); | ||
return null; | ||
}; | ||
} | ||
})(); | ||
do { | ||
if (el.matches(s)) return el; | ||
el = el.parentElement || el.parentNode; | ||
} while (el !== null && el.nodeType === 1); | ||
return null; | ||
}; | ||
} |
{ | ||
"name": "element-closest-polyfill", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "A minimal polyfill for Element.closest", | ||
@@ -18,3 +18,10 @@ "license": "MIT", | ||
"package" | ||
] | ||
} | ||
], | ||
"scripts": { | ||
"test": "jest --silent=false --verbose=true", | ||
"prepublishOnly": "npm test" | ||
}, | ||
"devDependencies": { | ||
"jest": "^26.2.2" | ||
} | ||
} |
@@ -5,3 +5,3 @@ # element-closest-polyfill | ||
A minimal polyfill for [`Element.closest()`](https://developer.mozilla.org/en-US/docs/Web/API/Element/closest), using MDN's implementation. Mostly meant for Microsoft IE. | ||
A minimal polyfill for [`Element.closest()`](https://developer.mozilla.org/en-US/docs/Web/API/Element/closest) and [`Element.matches()`](https://developer.mozilla.org/en-US/docs/Web/API/Element/matches), using MDN's implementation. Mostly meant for Microsoft IE9+. | ||
@@ -20,2 +20,2 @@ ## Install | ||
import 'element-closest-polyfill'; | ||
``` | ||
``` |
4468
67.65%5
25%60
328.57%20
5.26%1
Infinity%