Remove duplicate code related to dom traversal in Polymer.dom.

This commit is contained in:
Steven Orvell 2016-01-05 10:45:52 -08:00
parent 7c20170d69
commit 555252b6b6
3 changed files with 26 additions and 44 deletions

View File

@ -26,28 +26,6 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
return TreeApi.arrayCopy(this.node.querySelectorAll(selector));
},
_query: function(matcher, node) {
node = node || this.node;
var list = [];
this._queryElements(node.childNodes, matcher, list);
return list;
},
_queryElements: function(elements, matcher, list) {
for (var i=0, l=elements.length, c; (i<l) && (c=elements[i]); i++) {
if (c.nodeType === Node.ELEMENT_NODE) {
this._queryElement(c, matcher, list);
}
}
},
_queryElement: function(node, matcher, list) {
if (matcher(node)) {
list.push(node);
}
this._queryElements(node.childNodes, matcher, list);
},
getOwnerRoot: function() {
var n = this.node;
while (n) {

View File

@ -354,28 +354,6 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
}, this.node);
},
_query: function(matcher, node) {
node = node || this.node;
var list = [];
this._queryElements(TreeApi.Logical.getChildNodes(node), matcher, list);
return list;
},
_queryElements: function(elements, matcher, list) {
for (var i=0, l=elements.length, c; (i<l) && (c=elements[i]); i++) {
if (c.nodeType === Node.ELEMENT_NODE) {
this._queryElement(c, matcher, list);
}
}
},
_queryElement: function(node, matcher, list) {
if (matcher(node)) {
list.push(node);
}
this._queryElements(TreeApi.Logical.getChildNodes(node), matcher, list);
},
getDestinationInsertionPoints: function() {
return this.node._destinationInsertionPoints || [];
},

View File

@ -21,6 +21,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
'use strict';
var Settings = Polymer.Settings;
var TreeApi = Polymer.TreeApi;
var DomApi = function(node) {
this.node = needsToWrap ? DomApi.wrap(node) : node;
@ -134,6 +135,31 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
if (this.observer) {
this.observer.notify();
}
},
// NOTE: `_query` is used primarily for ShadyDOM's querySelector impl,
// but it's also generally useful to recurse through the element tree
// and is used by Polymer's styling system.
_query: function(matcher, node) {
node = node || this.node;
var list = [];
this._queryElements(TreeApi.Logical.getChildNodes(node), matcher, list);
return list;
},
_queryElements: function(elements, matcher, list) {
for (var i=0, l=elements.length, c; (i<l) && (c=elements[i]); i++) {
if (c.nodeType === Node.ELEMENT_NODE) {
this._queryElement(c, matcher, list);
}
}
},
_queryElement: function(node, matcher, list) {
if (matcher(node)) {
list.push(node);
}
this._queryElements(TreeApi.Logical.getChildNodes(node), matcher, list);
}
};