Skip to content
Browse files

Fixes #2154: ensure Polymer.dom always sees wrapped nodes when Shadow…

…DOM polyfill is in use.
  • Loading branch information...
1 parent 098b299 commit fc90aa0aeaf4c724d88fde54b4afe4978b659b4e @sorvell sorvell committed
Showing with 21 additions and 4 deletions.
  1. +15 −2 src/lib/dom-api.html
  2. +6 −2 test/unit/polymer-dom.js
View
17 src/lib/dom-api.html
@@ -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() {
@@ -135,6 +145,10 @@
return node;
},
+ _hasCachedOwnerRoot: function(node) {
+ return Boolean(node._ownerShadyRoot !== undefined);
+ },
+
getOwnerRoot: function() {
return this._ownerShadyRootForNode(this.node);
},
@@ -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);
View
8 test/unit/polymer-dom.js
@@ -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');
@@ -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) {
@@ -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) {

0 comments on commit fc90aa0

Please sign in to comment.
Something went wrong with that request. Please try again.