From 9b77def560212d12fef2d0b9c12aa50727e3e5d7 Mon Sep 17 00:00:00 2001 From: Saptak Sengupta Date: Fri, 9 Nov 2018 16:45:31 +0530 Subject: Core: Recognize Shadow DOM in attachment checks Allow `isAttached` to check Shadow DOM for attachment. Fixes gh-3504 Closes gh-3996 Ref gh-3977 --- src/core/isAttached.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/core/isAttached.js (limited to 'src/core') diff --git a/src/core/isAttached.js b/src/core/isAttached.js new file mode 100644 index 000000000..efa2465a9 --- /dev/null +++ b/src/core/isAttached.js @@ -0,0 +1,22 @@ +define( [ + "../core", + "../var/documentElement", + "../selector" // jQuery.contains +], function( jQuery, documentElement ) { + "use strict"; + + var isAttached = function( elem ) { + return jQuery.contains( elem.ownerDocument, elem ); + }, + composed = { composed: true }; + + // Check attachment across shadow DOM boundaries when possible (gh-3504) + if ( documentElement.attachShadow ) { + isAttached = function( elem ) { + return jQuery.contains( elem.ownerDocument, elem ) || + elem.getRootNode( composed ) === elem.ownerDocument; + }; + } + + return isAttached; +} ); -- cgit v1.2.3