Skip to content

Commit

Permalink
Clean up patch and add test cases (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludo committed Jun 2, 2014
1 parent 5eccbd5 commit 3c12a51
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
20 changes: 13 additions & 7 deletions javascripts/src/jquery.treetable.js
Expand Up @@ -344,15 +344,17 @@

// Remove node from DOM (<tr>)
node.row.remove();

// Remove node from parent children list
if (node.parentId) {
this.tree[node.parentId].removeChild(node);
if (node.parentId != null) {
node.parentNode().removeChild(node);
}

// Clean up Tree object (so Node objects are GC-ed)
delete this.tree[node.id];
this.nodes.splice($.inArray(node, this.nodes), 1);

return this;
}

Tree.prototype.render = function() {
Expand All @@ -379,10 +381,14 @@
};

Tree.prototype.unloadBranch = function(node) {
var children, i;

for (i = 0; i < node.children.length; i++) {
this.removeNode(node.children[i]);
// Use a copy of the children array to not have other functions interfere
// with this function if they manipulate the children array
// (eg removeNode).
var children = node.children.slice(0),
i;

for (i = 0; i < children.length; i++) {
this.removeNode(children[i]);
}

// Reset node's collection of children
Expand Down
14 changes: 11 additions & 3 deletions javascripts/test/jquery.treetable.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3c12a51

Please sign in to comment.