mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-14 01:37:26 +00:00
Switch to recursive getElementsByTagName implementation.
This commit is contained in:
@@ -212,22 +212,14 @@ function defineProperties(obj, properties) {
|
|||||||
|
|
||||||
/** {document,Element}.getElementsByTagName() is the only traversal method required by nwmatcher. */
|
/** {document,Element}.getElementsByTagName() is the only traversal method required by nwmatcher. */
|
||||||
function getElementsByTagName(tagName) {
|
function getElementsByTagName(tagName) {
|
||||||
const stack = [this];
|
// Only return Element/Document nodes
|
||||||
const matches = [];
|
if (this.nodeType!==1 && this.nodeType!==9 || this.type==='directive') return [];
|
||||||
const isWildCard = tagName === '*';
|
return Array.prototype.concat.apply(
|
||||||
const tagNameUpper = tagName.toUpperCase();
|
// Add current element if it matches tag
|
||||||
while (stack.length !== 0) {
|
(tagName === '*' || (this.tagName && (this.tagName == tagName || this.nodeName === tagName.toUpperCase()))) ? [this] : [],
|
||||||
const el = stack.pop();
|
// Check children recursively
|
||||||
let child = el.lastChild;
|
this.children.map(child => getElementsByTagName.call(child, tagName))
|
||||||
while (child) {
|
);
|
||||||
if (child.nodeType === 1) stack.push(child);
|
|
||||||
child = child.previousSibling;
|
|
||||||
}
|
|
||||||
if (isWildCard || (el.tagName != null && (el.tagName === tagNameUpper || el.tagName.toUpperCase() === tagNameUpper))) {
|
|
||||||
matches.push(el);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return matches;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user