-
-
Save Marak/472822 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| set dirty(value) { | |
| this.ascend(function(node) { node._dirty = value; }); | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| node.dirty = true; // marks current node and all parents dirty |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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