aboutsummaryrefslogtreecommitdiffstats
path: root/src/js/utils/elements.js
diff options
context:
space:
mode:
authorSam Potts <sam@potts.es>2020-04-19 16:51:31 +1000
committerGitHub <noreply@github.com>2020-04-19 16:51:31 +1000
commit6f1366bd198e52ea17ead09c0e593572c2f846db (patch)
tree6247f6a1438697f156f91e3435daa1ddc59a36fe /src/js/utils/elements.js
parentad63af5096e014785bd22eac24bc8030c0dc70d6 (diff)
parent353e19e746d5f44c0a04b6dd6571b8fb97da073d (diff)
downloadplyr-6f1366bd198e52ea17ead09c0e593572c2f846db.tar.lz
plyr-6f1366bd198e52ea17ead09c0e593572c2f846db.tar.xz
plyr-6f1366bd198e52ea17ead09c0e593572c2f846db.zip
Merge pull request #1759 from theprojectsomething/features/fullscreen-container
Features/fullscreen container
Diffstat (limited to 'src/js/utils/elements.js')
-rw-r--r--src/js/utils/elements.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/js/utils/elements.js b/src/js/utils/elements.js
index bdf18bfd..f782fc3e 100644
--- a/src/js/utils/elements.js
+++ b/src/js/utils/elements.js
@@ -237,6 +237,28 @@ export function matches(element, selector) {
return method.call(element, selector);
}
+// Closest ancestor element matching selector (also tests element itself)
+export function closest(element, selector) {
+ const {prototype} = Element;
+
+ // https://developer.mozilla.org/en-US/docs/Web/API/Element/closest#Polyfill
+ function closestElement() {
+ let el = this;
+
+ do {
+ if (matches.matches(el, selector)) return el;
+ el = el.parentElement || el.parentNode;
+ } while (el !== null && el.nodeType === 1);
+ return null;
+ }
+
+ const method =
+ prototype.closest ||
+ closestElement;
+
+ return method.call(element, selector);
+}
+
// Find all elements
export function getElements(selector) {
return this.elements.container.querySelectorAll(selector);