summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/commons/polyfills/element.js
diff options
context:
space:
mode:
authorMike Greiling <mgreiling@gitlab.com>2017-03-13 21:48:32 +0000
committerAlfredo Sumaran <alfredo@gitlab.com>2017-03-13 21:48:32 +0000
commit29e0cb4b91b3800ef4974c54b8473e6e4fb28e16 (patch)
tree3b0f9d9e221755caa71be35a34f2fbc9072ebf0e /app/assets/javascripts/commons/polyfills/element.js
parent88206d67c38e87685bbacc14cfd60ee9dc42ac7f (diff)
downloadgitlab-ce-29e0cb4b91b3800ef4974c54b8473e6e4fb28e16.tar.gz
Organize our polyfills and standardize on core-js
Diffstat (limited to 'app/assets/javascripts/commons/polyfills/element.js')
-rw-r--r--app/assets/javascripts/commons/polyfills/element.js20
1 files changed, 20 insertions, 0 deletions
diff --git a/app/assets/javascripts/commons/polyfills/element.js b/app/assets/javascripts/commons/polyfills/element.js
new file mode 100644
index 00000000000..9a1f73bf2ac
--- /dev/null
+++ b/app/assets/javascripts/commons/polyfills/element.js
@@ -0,0 +1,20 @@
+Element.prototype.closest = Element.prototype.closest ||
+ function closest(selector, selectedElement = this) {
+ if (!selectedElement) return null;
+ return selectedElement.matches(selector) ?
+ selectedElement :
+ Element.prototype.closest(selector, selectedElement.parentElement);
+ };
+
+Element.prototype.matches = Element.prototype.matches ||
+ Element.prototype.matchesSelector ||
+ Element.prototype.mozMatchesSelector ||
+ Element.prototype.msMatchesSelector ||
+ Element.prototype.oMatchesSelector ||
+ Element.prototype.webkitMatchesSelector ||
+ function matches(selector) {
+ const elms = (this.document || this.ownerDocument).querySelectorAll(selector);
+ let i = elms.length - 1;
+ while (i >= 0 && elms.item(i) !== this) { i -= 1; }
+ return i > -1;
+ };