aboutsummaryrefslogtreecommitdiffstats
path: root/core/src/Polyfill/closest.js
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/Polyfill/closest.js')
-rw-r--r--core/src/Polyfill/closest.js19
1 files changed, 19 insertions, 0 deletions
diff --git a/core/src/Polyfill/closest.js b/core/src/Polyfill/closest.js
new file mode 100644
index 00000000000..1c608646127
--- /dev/null
+++ b/core/src/Polyfill/closest.js
@@ -0,0 +1,19 @@
+// https://developer.mozilla.org/en-US/docs/Web/API/Element/closest#Polyfill
+
+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
+
+ do {
+ if (el.matches(s)) return el
+ el = el.parentElement || el.parentNode
+ } while (el !== null && el.nodeType === 1)
+ return null
+ }
+}