Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
Merge pull request #433 from arv/reprojection-scaffold-demo
Browse files Browse the repository at this point in the history
Fix issue with redistribution when shadow is present
  • Loading branch information
dfreedm committed May 8, 2014
2 parents 73a758b + 3e60260 commit b760852
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
14 changes: 8 additions & 6 deletions src/ShadowRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,13 +355,13 @@
// 1.3.2.2.1
destributeNodeInto(pool[j], shadow);
}

} else {
// 1.3.3
this.distributionResolution(shadowTree);
}

// 1.3.3
this.distributionResolution(shadowTree);
}
}

for (var child = node.firstChild; child; child = child.nextSibling) {
this.distributionResolution(child);
}
Expand All @@ -376,6 +376,8 @@
var content = node;
this.updateDependentAttributes(content.getAttribute('select'));

var anyDistributed = false;

// 1.1
for (var i = 0; i < pool.length; i++) {
var node = pool[i];
Expand All @@ -384,13 +386,13 @@
if (matches(node, content)) {
destributeNodeInto(node, content);
pool[i] = undefined;
anyDistributed = true;
}
}

// 1.2
// Fallback content
var distributedNodes = getDistributedNodes(content);
if (distributedNodes && distributedNodes.length === 0) {
if (!anyDistributed) {
for (var child = content.firstChild;
child;
child = child.nextSibling) {
Expand Down
4 changes: 2 additions & 2 deletions test/js/Document.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ htmlSuite('Document', function() {

test('getElementsByTagName', function() {
var elements = document.getElementsByTagName('body');
assert.isTrue(elements instanceof NodeList);
assert.isTrue(elements instanceof HTMLCollection);
assert.equal(elements.length, 1);
assert.isTrue(elements[0] instanceof HTMLElement);

Expand All @@ -58,7 +58,7 @@ htmlSuite('Document', function() {
assert.equal(doc.body, elements.item(0));

var elements2 = doc.getElementsByTagName('body');
assert.isTrue(elements2 instanceof NodeList);
assert.isTrue(elements2 instanceof HTMLCollection);
assert.equal(elements2.length, 1);
assert.isTrue(elements2[0] instanceof HTMLElement);
assert.equal(doc.body, elements2[0]);
Expand Down
30 changes: 29 additions & 1 deletion test/js/reprojection.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,35 @@ suite('Shadow DOM reprojection', function() {

testRender();
testRender();
});

test('Regression 432', function() {
// https://github.com/Polymer/ShadowDOM/issues/432

var xFoo = document.createElement('x-foo');
xFoo.innerHTML = '<div>Hello</div>';
var div = xFoo.firstChild;

var xBarSr = xFoo.createShadowRoot();

var xFooSr = xFoo.createShadowRoot();
xFooSr.innerHTML = '<x-zot><content></content></x-zot><shadow></shadow>';
var xZot = xFooSr.firstChild;
var content = xZot.firstChild;
var shadow = xZot.lastChild;

xZotSr = xZot.createShadowRoot();
xZotSr.innerHTML = '<content></content>';
var content2 = xZotSr.firstChild;

xFoo.offsetWidth;

assertArrayEqual(content.getDistributedNodes(), [div]);
assertArrayEqual(shadow.getDistributedNodes(), [div]);
assertArrayEqual(content2.getDistributedNodes(), [div]);

assertArrayEqual(div.getDestinationInsertionPoints(), [content, content2]);


assert.equal(getVisualInnerHtml(xFoo), '<x-zot><div>Hello</div></x-zot>');
});
});

0 comments on commit b760852

Please sign in to comment.