summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/extensions/element.js
diff options
context:
space:
mode:
authorValery Sizov <valery@gitlab.com>2017-03-06 18:50:59 +0200
committerValery Sizov <valery@gitlab.com>2017-03-06 18:50:59 +0200
commit710e4df933ba2070dcc104a18de834c23dd1e5be (patch)
treedee3817e1ddc46179cdb6e0b3008a9e94b5440d5 /app/assets/javascripts/extensions/element.js
parent13caadea7a123d1dc5f3475d360cd07f1aef4acb (diff)
parentb63c41e12e9e6f7e9fd1d79bedf56bd42cc17035 (diff)
downloadgitlab-ce-710e4df933ba2070dcc104a18de834c23dd1e5be.tar.gz
Merge branch 'master' of gitlab.com:gitlab-org/gitlab-ce into orderable-issues
Diffstat (limited to 'app/assets/javascripts/extensions/element.js')
-rw-r--r--app/assets/javascripts/extensions/element.js20
1 files changed, 20 insertions, 0 deletions
diff --git a/app/assets/javascripts/extensions/element.js b/app/assets/javascripts/extensions/element.js
new file mode 100644
index 00000000000..90ab79305a7
--- /dev/null
+++ b/app/assets/javascripts/extensions/element.js
@@ -0,0 +1,20 @@
+/* global Element */
+/* eslint-disable consistent-return, max-len, no-empty, func-names */
+
+Element.prototype.closest = Element.prototype.closest || function closest(selector, selectedElement = this) {
+ if (!selectedElement) return;
+ 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 (s) {
+ const matches = (this.document || this.ownerDocument).querySelectorAll(s);
+ let i = matches.length - 1;
+ while (i >= 0 && matches.item(i) !== this) { i -= 1; }
+ return i > -1;
+ };