Skip to content

Commit

Permalink
Merge pull request #2170 from Polymer/fix-2154
Browse files Browse the repository at this point in the history
Fixes #2154: ensure Polymer.dom always sees wrapped nodes when Shadow…
  • Loading branch information
kevinpschaaf committed Jul 30, 2015
2 parents 098b299 + fc90aa0 commit b87e773
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
17 changes: 15 additions & 2 deletions src/lib/dom-api.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@
}
};

// ensure nodes are wrapped if SD polyfill is present
if (window.wrap && Settings.useShadow && !Settings.useNativeShadow) {
DomApi = function(node) {
this.node = wrap(node);
if (this.patch) {
this.patch();
}
};
}

DomApi.prototype = {

flush: function() {
Expand Down Expand Up @@ -135,6 +145,10 @@
return node;
},

_hasCachedOwnerRoot: function(node) {
return Boolean(node._ownerShadyRoot !== undefined);
},

getOwnerRoot: function() {
return this._ownerShadyRootForNode(this.node);
},
Expand Down Expand Up @@ -321,8 +335,7 @@

_removeOwnerShadyRoot: function(node) {
// optimization: only reset the tree if node is actually in a root
var hasCachedRoot = factory(node).getOwnerRoot() !== undefined;
if (hasCachedRoot) {
if (this._hasCachedOwnerRoot(node)) {
var c$ = factory(node).childNodes;
for (var i=0, l=c$.length, n; (i<l) && (n=c$[i]); i++) {
this._removeOwnerShadyRoot(n);
Expand Down
8 changes: 6 additions & 2 deletions test/unit/polymer-dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ suite('Polymer.dom', function() {
assert(Polymer.dom(p).querySelectorAll('content').length, 1);
});

test('querySelector document', function() {
assert.ok(Polymer.dom().querySelector('body'));
});

test('projection', function() {
var projected = Polymer.dom(testElement.root).querySelector('#projected');
assert.equal(projected.textContent, 'projected');
Expand Down Expand Up @@ -531,7 +535,7 @@ suite('Polymer.dom', function() {
test('Polymer.dom importNode shallow', function() {
var a = document.createElement('div');
a.innerHTML = '<x-clonate><span>1</span><span>2</span></x-clonate>';
var b = Polymer.dom(wrap(document)).importNode(Polymer.dom(a).firstElementChild);
var b = Polymer.dom(document).importNode(Polymer.dom(a).firstElementChild);
Polymer.dom(document.body).appendChild(b);
assert.equal(Polymer.dom(b).childNodes.length, 0, 'shallow import has incorrect children');
if (b.shadyRoot) {
Expand All @@ -542,7 +546,7 @@ suite('Polymer.dom', function() {
test('Polymer.dom importNode deep', function() {
var a = document.createElement('div');
a.innerHTML = '<x-clonate><span>1</span><span>2</span></x-clonate>';
var b = Polymer.dom(wrap(document)).importNode(a, true);
var b = Polymer.dom(document).importNode(a, true);
Polymer.dom(document.body).appendChild(b);
assert.equal(Polymer.dom(b.firstElementChild).childNodes.length, 2, 'deep copy has incorrect children');
if (b.shadyRoot) {
Expand Down

0 comments on commit b87e773

Please sign in to comment.