Skip to content

Commit

Permalink
Add closest() polyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
jimchamp committed Mar 1, 2022
1 parent cbbb3b2 commit 1b289ce
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions openlibrary/plugins/openlibrary/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,25 @@ jQuery(function () {
import(/* webpackChunkName: "details-polyfill" */ 'details-polyfill');
}

// Polyfill for .matches()
if (!Element.prototype.matches) {
Element.prototype.matches =
Element.prototype.msMatchesSelector ||
Element.prototype.webkitMatchesSelector;
}

// Polyfill for .closest()
if (!Element.prototype.closest) {
Element.prototype.closest = function(s) {
let el = this;
do {
if (Element.prototype.matches.call(el, s)) return el;
el = el.parentElement || el.parentNode;
} while (el !== null && el.nodeType === 1);
return null;
};
}

const $markdownTextAreas = $('textarea.markdown');
// Live NodeList is cast to static array to avoid infinite loops
const $carouselElements = $('.carousel--progressively-enhanced');
Expand Down

0 comments on commit 1b289ce

Please sign in to comment.