Skip to content

Instantly share code, notes, and snippets.

@Marak
Forked from tmpvar/in use here.js
Created July 12, 2010 18:02
Show Gist options
  • Select an option

  • Save Marak/472822 to your computer and use it in GitHub Desktop.

Select an option

Save Marak/472822 to your computer and use it in GitHub Desktop.
set dirty(value) {
this.ascend(function(node) { node._dirty = value; });
},
node.dirty = true; // marks current node and all parents dirty
walk : function(map, callback, depth) {
var levels = (depth) ? depth-1 : null,
fnResult = false, // false means stop!
walker = {
_stopped : false,
stop : function() {
walker._stopped = true;
},
stopped : function() {
return walker._stopped;
},
nodesWalked : 1,
};
if (typeof callback === "function") {
fnResult = callback(this, walker);
}
if (fnResult !== false &&
(levels === null || levels >= 0) &&
walker.stopped() === false)
{
map(this, function(currentNode) {
currentNode.walk(map, callback, levels);
});
}
return walker;
},
ascend : function(fn, depth) {
this.walk(function(node) {
if (node && node.parent) {
fn(node.parent);
}
},fn, depth);
},
descend : function(fn, depth) {
this.walk(
function(node) {
var l=node.children.length, i=0, result;
for (i; i<l; i++)
{
fn(node.child(i));
}
}, fn, depth);
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment