Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Shadow DOM feature to isAttached #3996

Merged
merged 7 commits into from Nov 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 22 additions & 0 deletions 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;
} );
2 changes: 1 addition & 1 deletion src/css/curCSS.js
@@ -1,6 +1,6 @@
define( [
"../core",
"../var/isAttached",
"../core/isAttached",
"./var/rboxStyle",
"./var/rnumnonpx",
"./var/getStyles",
Expand Down
2 changes: 1 addition & 1 deletion src/css/var/isHiddenWithinTree.js
@@ -1,6 +1,6 @@
define( [
"../../core",
"../../var/isAttached"
"../../core/isAttached"

// css is assumed
], function( jQuery, isAttached ) {
Expand Down
2 changes: 1 addition & 1 deletion src/manipulation.js
@@ -1,6 +1,6 @@
define( [
"./core",
"./var/isAttached",
"./core/isAttached",
"./var/concat",
"./var/isFunction",
"./var/push",
Expand Down
2 changes: 1 addition & 1 deletion src/manipulation/buildFragment.js
@@ -1,7 +1,7 @@
define( [
"../core",
"../core/toType",
"../var/isAttached",
"../core/isAttached",
"./var/rtagName",
"./var/rscriptType",
"./wrapMap",
Expand Down
11 changes: 0 additions & 11 deletions src/var/isAttached.js

This file was deleted.

80 changes: 80 additions & 0 deletions test/unit/css.js
Expand Up @@ -641,6 +641,63 @@ QUnit.test( "show/hide detached nodes", function( assert ) {
span.remove();
} );

QUnit[ document.body.attachShadow ? "test" : "skip" ]( "show/hide shadow child nodes", function( assert ) {
assert.expect( 28 );
jQuery( "<div id='shadowHost'></div>" ).appendTo( "#qunit-fixture" );
var shadowHost = document.querySelector( "#shadowHost" );
var shadowRoot = shadowHost.attachShadow( { mode: "open" } );
shadowRoot.innerHTML = "" +
"<style>.hidden{display: none;}</style>" +
"<div class='hidden' id='shadowdiv'>" +
" <p class='hidden' id='shadowp'>" +
" <a href='#' class='hidden' id='shadowa'></a>" +
" </p>" +
" <code class='hidden' id='shadowcode'></code>" +
" <pre class='hidden' id='shadowpre'></pre>" +
" <span class='hidden' id='shadowspan'></span>" +
"</div>" +
"<table class='hidden' id='shadowtable'>" +
" <thead class='hidden' id='shadowthead'>" +
" <tr class='hidden' id='shadowtr'>" +
" <th class='hidden' id='shadowth'></th>" +
" </tr>" +
" </thead>" +
" <tbody class='hidden' id='shadowtbody'>" +
" <tr class='hidden'>" +
" <td class='hidden' id='shadowtd'></td>" +
" </tr>" +
" </tbody>" +
"</table>" +
"<ul class='hidden' id='shadowul'>" +
" <li class='hidden' id='shadowli'></li>" +
"</ul>";

var test = {
"div": "block",
"p": "block",
"a": "inline",
"code": "inline",
"pre": "block",
"span": "inline",
"table": "table",
"thead": "table-header-group",
"tbody": "table-row-group",
"tr": "table-row",
"th": "table-cell",
"td": "table-cell",
"ul": "block",
"li": "list-item"
};

jQuery.each( test, function( selector, expected ) {
var shadowChild = shadowRoot.querySelector( "#shadow" + selector );
var $shadowChild = jQuery( shadowChild );
assert.strictEqual( $shadowChild.css( "display" ), "none", "is hidden" );
$shadowChild.show();
assert.strictEqual( $shadowChild.css( "display" ), expected, "Show using correct display type for " + selector );
} );
} );

QUnit.test( "hide hidden elements (bug #7141)", function( assert ) {
assert.expect( 3 );

Expand Down Expand Up @@ -966,6 +1023,29 @@ QUnit[ jQuery.find.compile && jQuery.fn.toggle ? "test" : "skip" ]( "detached to
"cascade-hidden element in detached tree" );
} );

QUnit[ jQuery.find.compile && jQuery.fn.toggle && document.body.attachShadow ? "test" : "skip" ]( "shadow toggle()", function( assert ) {
assert.expect( 4 );
jQuery( "<div id='shadowHost'></div>" ).appendTo( "#qunit-fixture" );
var shadowHost = document.querySelector( "#shadowHost" );
var shadowRoot = shadowHost.attachShadow( { mode: "open" } );
shadowRoot.innerHTML = "" +
"<style>.hidden{display: none;}</style>" +
"<div id='shadowHiddenChild' class='hidden'></div>" +
"<div id='shadowChild'></div>";
var shadowChild = shadowRoot.querySelector( "#shadowChild" );
var shadowHiddenChild = shadowRoot.querySelector( "#shadowHiddenChild" );

var $shadowChild = jQuery( shadowChild );
assert.strictEqual( $shadowChild.css( "display" ), "block", "is visible" );
$shadowChild.toggle();
assert.strictEqual( $shadowChild.css( "display" ), "none", "is hidden" );

$shadowChild = jQuery( shadowHiddenChild );
assert.strictEqual( $shadowChild.css( "display" ), "none", "is hidden" );
$shadowChild.toggle();
assert.strictEqual( $shadowChild.css( "display" ), "block", "is visible" );
} );

QUnit.test( "jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", function( assert ) {
assert.expect( 4 );

Expand Down
32 changes: 32 additions & 0 deletions test/unit/effects.js
Expand Up @@ -220,6 +220,38 @@ supportjQuery.each( hideOptions, function( type, setup ) {

assert.expectJqData( this, $span, "olddisplay" );
} );

QUnit[ document.body.attachShadow ? "test" : "skip" ](
"Persist correct display value - " + type + " hidden, shadow child", function( assert ) {
assert.expect( 3 );

jQuery( "<div id='shadowHost'></div>" ).appendTo( "#qunit-fixture" );
mgol marked this conversation as resolved.
Show resolved Hide resolved

var shadowHost = document.querySelector( "#shadowHost" );
var shadowRoot = shadowHost.attachShadow( { mode: "open" } );
shadowRoot.innerHTML = "<style>.hidden{display: none;}</style>" +
"<span id='shadowChild' class='hidden'></span>";
var shadowChild = shadowRoot.querySelector( "#shadowChild" );

var $shadowChild = jQuery( shadowChild );
var displayNone = "none";
var display = "inline";
var clock = this.clock;

$shadowChild.fadeIn( 100, function() {
assert.equal( $shadowChild.css( "display" ), display, "Expecting shadow display: " + display );
$shadowChild.fadeOut( 100, function() {
assert.equal( $shadowChild.css( "display" ), displayNone, "Expecting shadow display: " + displayNone );
$shadowChild.fadeIn( 100, function() {
assert.equal( $shadowChild.css( "display" ), display, "Expecting shadow display: " + display );
} );
} );
} );

clock.tick( 300 );

assert.expectJqData( this, $shadowChild, "olddisplay" );
} );
} );

QUnit.test( "animate(Hash, Object, Function)", function( assert ) {
Expand Down