diff --git a/ui/media/js/utils.js b/ui/media/js/utils.js index 50f5f162..69801571 100644 --- a/ui/media/js/utils.js +++ b/ui/media/js/utils.js @@ -20,6 +20,19 @@ function getNextSibling(elem, selector) { } } +function findClosestAncestor(element, selector) { + if (!element || !element.parentNode) { + // reached the top of the DOM tree, return null + return null; + } else if (element.parentNode.matches(selector)) { + // found an ancestor that matches the selector, return it + return element.parentNode; + } else { + // continue searching upwards + return findClosestAncestor(element.parentNode, selector); + } +} + /* Panel Stuff */