").addClass("node").attr("id", $node.attr("id")).append($nodeContent);
+ }else{
+ $nodeDiv = $("
").addClass("node").append($nodeContent);
+ }
+
+ // Expand and contract nodes
+ if ($childNodes.length > 0) {
+ $nodeDiv.click(function() {
+ var $this = $(this);
+ var $tr = $this.closest("tr");
+ $tr.nextAll("tr").fadeToggle("fast");
+
+ if($tr.hasClass('contracted')){
+ $this.css('cursor','n-resize');
+ $tr.removeClass('contracted');
+ $tr.addClass('expanded');
+ }else{
+ $this.css('cursor','s-resize');
+ $tr.removeClass('expanded');
+ $tr.addClass('contracted');
+ }
+ });
+ }
+
+ $nodeCell.append($nodeDiv);
+ $nodeRow.append($nodeCell);
+ $tbody.append($nodeRow);
+
+ if($childNodes.length > 0) {
+ // if it can be expanded then change the cursor
+ $nodeDiv.css('cursor','n-resize').addClass('expanded');
+
+ // recurse until leaves found (-1) or to the level specified
+ if(opts.depth == -1 || (level+1 < opts.depth)) {
+ var $downLineRow = $("
|
");
+ var $downLineCell = $("
| ").attr("colspan", $childNodes.length*2);
+ $downLineRow.append($downLineCell);
- // draw the connecting line from the parent node to the horizontal line
- $downLine = $("
").addClass("line down");
- $downLineCell.append($downLine);
- $tbody.append($downLineRow);
+ // draw the connecting line from the parent node to the horizontal line
+ $downLine = $("
").addClass("line down");
+ $downLineCell.append($downLine);
+ $tbody.append($downLineRow);
- // Draw the horizontal lines
- var $linesRow = $("
|
");
- $childNodes.each(function() {
- var $left = $("
| ").addClass("line left top");
- var $right = $("
| ").addClass("line right top");
- $linesRow.append($left).append($right);
- });
+ // Draw the horizontal lines
+ var $linesRow = $("
|
");
+ $childNodes.each(function() {
+ var $left = $("
| ").addClass("line left top");
+ var $right = $("
| ").addClass("line right top");
+ $linesRow.append($left).append($right);
+ });
- // horizontal line shouldn't extend beyond the first and last child branches
- $linesRow.find("td:first")
- .removeClass("top")
- .end()
- .find("td:last")
- .removeClass("top");
+ // horizontal line shouldn't extend beyond the first and last child branches
+ $linesRow.find("td:first")
+ .removeClass("top")
+ .end()
+ .find("td:last")
+ .removeClass("top");
- $tbody.append($linesRow);
- var $childNodesRow = $("
|
");
- $childNodes.each(function() {
- var $td = $("
| ");
- $td.attr("colspan", 2);
- // recurse through children lists and items
- buildNode($(this), $td, level+1, opts);
- $childNodesRow.append($td);
- });
+ $tbody.append($linesRow);
+ var $childNodesRow = $("
|
");
+ $childNodes.each(function() {
+ var $td = $("
| ");
+ $td.attr("colspan", 2);
+ // recurse through children lists and items
+ buildNode($(this), $td, level+1, opts);
+ $childNodesRow.append($td);
+ });
- }
- $tbody.append($childNodesRow);
- }
-
- // any classes on the LI element get copied to the relevant node in the tree
- // apart from the special 'collapsed' class, which collapses the sub-tree at this point
- if ($node.attr('class') != undefined) {
- var classList = $node.attr('class').split(/\s+/);
- $.each(classList, function(index,item) {
- if (item == 'collapsed') {
- $nodeRow.nextAll('tr').css('display', 'none');
- $nodeRow.removeClass('expanded');
- $nodeRow.addClass('contracted');
- $nodeDiv.css('cursor','s-resize');
- } else {
- $nodeDiv.addClass(item);
}
- });
- }
+ $tbody.append($childNodesRow);
+ }
- $table.append($tbody);
- $appendTo.append($table);
- };
+ // any classes on the LI element get copied to the relevant node in the tree
+ // apart from the special 'collapsed' class, which collapses the sub-tree at this point
+ if ($node.attr('class') != undefined) {
+ var classList = $node.attr('class').split(/\s+/);
+ $.each(classList, function(index,item) {
+ if (item == 'collapsed') {
+ $nodeRow.nextAll('tr').css('display', 'none');
+ $nodeRow.removeClass('expanded');
+ $nodeRow.addClass('contracted');
+ $nodeDiv.css('cursor','s-resize');
+ } else {
+ $nodeDiv.addClass(item);
+ }
+ });
+ }
-})(jQuery);
+ $table.append($tbody);
+ $appendTo.append($table);
+ };
+
+})(jQuery);
\ No newline at end of file
diff --git a/jquery.jOrgChart.js b/jquery.jOrgChart.js
index 2080922..dc88db9 100644
--- a/jquery.jOrgChart.js
+++ b/jquery.jOrgChart.js
@@ -7,9 +7,7 @@
* Based on the work of Mark Lee
* http://www.capricasoftware.co.uk
*
-* ID implementation by Aleks Drevenšek
-*
-* ID implementation fixed(changed) by Adrian Hinz
+* ID implementation fixed by Adrian Hinz
*
* This software is licensed under the Creative Commons Attribution-ShareAlike
* 3.0 License.