From d53ab5736f72edf8b5cbc50de60fb12afd1eef89 Mon Sep 17 00:00:00 2001 From: Steven Orvell Date: Wed, 4 Nov 2015 17:18:26 -0800 Subject: [PATCH] add back deepContains (got removed incorrectly in merge). --- src/lib/dom-api.html | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/lib/dom-api.html b/src/lib/dom-api.html index ac5a7a07e3..875054bc1f 100644 --- a/src/lib/dom-api.html +++ b/src/lib/dom-api.html @@ -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