Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 26 additions & 22 deletions jquery.jOrgChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -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("<ul></ul>");
targetLi.children('ul').append(sourceLi);
targetLi.append("<ul></ul>");
targetLi.children('ul').append(sourceLi);
}

//Removes any empty lists
if (sourceUl.children().length === 0){
sourceUl.remove();
}
}); // handleDropEvent

} // Drag and drop
Expand All @@ -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) {
Expand All @@ -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 = $("<div>").addClass("node")
nodeCount++;
$node.data("tree-node", nodeCount);
$nodeDiv = $("<div>").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");
Expand All @@ -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 = $("<tr/>");
Expand Down Expand Up @@ -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);
}
Expand Down