Skip to content

Commit

Permalink
add back deepContains (got removed incorrectly in merge).
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Orvell committed Nov 5, 2015
1 parent 0233d6d commit d53ab57
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/lib/dom-api.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,28 @@
Polymer.dom.flush();
},

/**
* Check that the given node is a descendant of `this`,
* ignoring ShadowDOM boundaries
* @param {Node} node
* @return {Boolean} true if `node` is a descendant or equal to `this`
*/
deepContains: function(node) {
// fast path, use shallow `contains`.
if (this.node.contains(node)) {
return true;
}
var n = node;
// wrap document for SD polyfill
var wrappedDocument = wrap(document);
// walk from node to `this` or `document`
while (n && n !== wrappedDocument && n !== this.node) {
// use logical parentnode, or native ShadowRoot host
n = Polymer.dom(n).parentNode || n.host;
}
return n === this.node;
},

_lazyDistribute: function(host) {
// note: only try to distribute if the root is not clean; this ensures
// we don't distribute before initial distribution
Expand Down

0 comments on commit d53ab57

Please sign in to comment.