diff options
author | Saptak Sengupta <saptak013@gmail.com> | 2018-11-09 16:45:31 +0530 |
---|---|---|
committer | Michał Gołębiowski-Owczarek <m.goleb@gmail.com> | 2018-11-09 12:15:31 +0100 |
commit | 9b77def560212d12fef2d0b9c12aa50727e3e5d7 (patch) | |
tree | b059ef809c20fd23bc8b5f5a96f90ffbd7a36971 /src/core | |
parent | 549b32a05afc42a2d0f450ffa82537c3ec25630f (diff) | |
download | jquery-9b77def560212d12fef2d0b9c12aa50727e3e5d7.tar.gz jquery-9b77def560212d12fef2d0b9c12aa50727e3e5d7.zip |
Core: Recognize Shadow DOM in attachment checks
Allow `isAttached` to check Shadow DOM for attachment.
Fixes gh-3504
Closes gh-3996
Ref gh-3977
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/isAttached.js | 22 |
1 files changed, 22 insertions, 0 deletions
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; +} ); |