diff --git a/jquery.jOrgChart.js b/jquery.jOrgChart.js index ed2ed1f..0052f62 100644 --- a/jquery.jOrgChart.js +++ b/jquery.jOrgChart.js @@ -72,23 +72,23 @@ var targetID = $(this).data("tree-node"); var targetLi = $this.find("li").filter(function() { return $(this).data("tree-node") === targetID; } ); var targetUl = targetLi.children('ul'); - - var sourceID = ui.draggable.data("tree-node"); - var sourceLi = $this.find("li").filter(function() { return $(this).data("tree-node") === sourceID; } ); + + var sourceID = ui.draggable.data("tree-node"); + var sourceLi = $this.find("li").filter(function() { return $(this).data("tree-node") === sourceID; } ); var sourceUl = sourceLi.parent('ul'); if (targetUl.length > 0){ - targetUl.append(sourceLi); + targetUl.append(sourceLi); } else { - targetLi.append(""); - targetLi.children('ul').append(sourceLi); + targetLi.append(""); + targetLi.children('ul').append(sourceLi); } //Removes any empty lists if (sourceUl.children().length === 0){ sourceUl.remove(); } - + }); // handleDropEvent } // Drag and drop @@ -99,9 +99,10 @@ chartElement : 'body', depth : -1, chartClass : "jOrgChart", - dragAndDrop: false + dragAndDrop: false, + collapsible: true }; - + var nodeCount = 0; // Method that recursively builds the tree function buildNode($node, $appendTo, level, opts) { @@ -124,16 +125,16 @@ .remove() .end() .html(); - + //Increaments the node count which is used to link the source list and the org chart - nodeCount++; - $node.data("tree-node", nodeCount); - $nodeDiv = $("
").addClass("node") + nodeCount++; + $node.data("tree-node", nodeCount); + $nodeDiv = $("
").addClass("node") .data("tree-node", nodeCount) .append($nodeContent); // Expand and contract nodes - if ($childNodes.length > 0) { + if ($childNodes.length > 0 && opts.collapsible) { $nodeDiv.click(function() { var $this = $(this); var $tr = $this.closest("tr"); @@ -155,15 +156,16 @@ } }); } - + $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'); - + if(opts.collapsible){ + $nodeDiv.css('cursor','n-resize'); + } // recurse until leaves found (-1) or to the level specified if(opts.depth == -1 || (level+1 < opts.depth)) { var $downLineRow = $(""); @@ -210,11 +212,13 @@ var classList = $node.attr('class').split(/\s+/); $.each(classList, function(index,item) { if (item == 'collapsed') { - console.log($node); - $nodeRow.nextAll('tr').css('visibility', 'hidden'); - $nodeRow.removeClass('expanded'); - $nodeRow.addClass('contracted'); - $nodeDiv.css('cursor','s-resize'); + if(opts.collapsible){ + window.console && console.log($node); //firefox crashes in some versions without this check + $nodeRow.nextAll('tr').css('visibility', 'hidden'); + $nodeRow.removeClass('expanded'); + $nodeRow.addClass('contracted'); + $nodeDiv.css('cursor','s-resize'); + } } else { $nodeDiv.addClass(item); }