Skip to content

Commit

Permalink
fix matches polyfill on IE
Browse files Browse the repository at this point in the history
  • Loading branch information
estevanmaito committed May 18, 2019
1 parent 14c9d9b commit 75c2497
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dist/sharect.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion src/helpers/getClosestElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ export default function getClosestElement(element, ancestor) {
if (Element.prototype.closest) {
return element.closest(ancestor)
} else {
// IE 9+ polyfill
// IE 9+ closest polyfill + matches polyfill
if (!Element.prototype.matches) {
Element.prototype.matches =
Element.prototype.matchesSelector ||
Element.prototype.mozMatchesSelector ||
Element.prototype.msMatchesSelector ||
Element.prototype.oMatchesSelector ||
Element.prototype.webkitMatchesSelector
}
let el = element
do {
if (el.matches(ancestor)) return el
Expand Down

0 comments on commit 75c2497

Please sign in to comment.