mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-06 08:08:10 +08:00
23 lines
524 B
JavaScript
23 lines
524 B
JavaScript
const DOMWalkers = {
|
|
*walk(...treeWalkerArgs) {
|
|
const walker = document.createTreeWalker(...treeWalkerArgs);
|
|
let node = walker.nextNode();
|
|
while (node) {
|
|
yield node;
|
|
node = walker.nextNode();
|
|
}
|
|
return;
|
|
},
|
|
|
|
*walkBackwards(node) {
|
|
if (!node) { return; }
|
|
if (node.childNodes.length > 0) {
|
|
for (let i = node.childNodes.length - 1; i >= 0; i--) {
|
|
yield *this.walkBackwards(node.childNodes[i]);
|
|
}
|
|
}
|
|
yield node;
|
|
return;
|
|
},
|
|
}
|
|
export default DOMWalkers
|