forked from jquery/jquery
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Core: Allow shadow DOM in attachment check
Allow isAttached to check shadow DOM for attachment. This change allows isAttached() function to address shadowDOM elements even if the browser doesn't support getRootNode() Ref jquerygh-3504, jquerygh-3977
- Loading branch information
Showing
2 changed files
with
29 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
define( [ | ||
"./document" | ||
], function( document ) { | ||
"use strict"; | ||
|
||
return function getShadowRoot( elem ) { | ||
|
||
// Check if browser supports Shadow DOM | ||
if ( document.head.createShadowRoot || document.head.attachShadow ) { | ||
|
||
// check for support of getRootNode function | ||
while ( typeof elem.getRootNode !== "function" ) { | ||
var doc = elem.ownerDocument; | ||
elem = doc && doc.host ? doc.host : doc; | ||
} | ||
return elem.getRootNode( { composed: true } ); | ||
} | ||
|
||
return false; | ||
}; | ||
|
||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
define( [ | ||
"../core", | ||
"./getShadowRoot", | ||
"../selector" // Get jQuery.contains | ||
], function( jQuery ) { | ||
], function( jQuery, getShadowRoot ) { | ||
"use strict"; | ||
|
||
return function isAttached( obj ) { | ||
return jQuery.contains( obj.ownerDocument, obj ); | ||
}; | ||
// Replace the use of contains function to check attachment (gh-3504) | ||
return function isAttached( elem ) { | ||
|
||
return jQuery.contains( elem.ownerDocument, elem ) || | ||
getShadowRoot( elem ) === elem.ownerDocument; | ||
}; | ||
} ); |