Skip to content

Commit d53ab57

Browse files
author
Steven Orvell
committed
add back deepContains (got removed incorrectly in merge).
1 parent 0233d6d commit d53ab57

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/lib/dom-api.html

+22
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,28 @@
5252
Polymer.dom.flush();
5353
},
5454

55+
/**
56+
* Check that the given node is a descendant of `this`,
57+
* ignoring ShadowDOM boundaries
58+
* @param {Node} node
59+
* @return {Boolean} true if `node` is a descendant or equal to `this`
60+
*/
61+
deepContains: function(node) {
62+
// fast path, use shallow `contains`.
63+
if (this.node.contains(node)) {
64+
return true;
65+
}
66+
var n = node;
67+
// wrap document for SD polyfill
68+
var wrappedDocument = wrap(document);
69+
// walk from node to `this` or `document`
70+
while (n && n !== wrappedDocument && n !== this.node) {
71+
// use logical parentnode, or native ShadowRoot host
72+
n = Polymer.dom(n).parentNode || n.host;
73+
}
74+
return n === this.node;
75+
},
76+
5577
_lazyDistribute: function(host) {
5678
// note: only try to distribute if the root is not clean; this ensures
5779
// we don't distribute before initial distribution

0 commit comments

Comments
 (0)