From b16127fc105f159ebd06b02df2853941b2aba67c Mon Sep 17 00:00:00 2001 From: Johann-S Date: Thu, 30 Nov 2017 10:54:27 +0100 Subject: Allow Tooltips/Popovers to work in shadow DOM --- js/src/util.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'js/src/util.js') diff --git a/js/src/util.js b/js/src/util.js index e9665d24f..1d804cf9d 100644 --- a/js/src/util.js +++ b/js/src/util.js @@ -142,6 +142,29 @@ const Util = { } } } + }, + + findShadowRoot(element) { + if (!document.documentElement.attachShadow) { + return null + } + + // Can find the shadow root otherwise it'll return the document + if (typeof element.getRootNode === 'function') { + const root = element.getRootNode() + return root instanceof ShadowRoot ? root : null + } + + if (element instanceof ShadowRoot) { + return element + } + + // when we don't find a shadow root + if (!element.parentNode) { + return null + } + + return Util.findShadowRoot(element.parentNode) } } -- cgit v1.2.3