(function($) { // Container element for organization chart var nodeDiv = "
"; var nodeContent = ""; var subtreeWrapper = ""; var mainSeparator = ""; var nodeSeparator = ""; var middleSeparator = ""; // Organization chart constructor $.fn.jCspOrgChart = function(options) { var opts = $.extend({}, $.fn.jCspOrgChart.defaults, options); this.empty(); buildNode(this, opts.data, 0, true); }; // Defaults options for organization chart $.fn.jCspOrgChart.defaults = { chartWidth : "100%", data : {name: "Root", childs: [{name: "child 1", childs: [{name: "child 1", childs: [{name: "child 1", childs: [{name: "child 1", childs: [{name: "child 1", childs: [{name: "child 1", childs: []}, {name: "child 2", childs: []}, {name: "child 3", childs: []}]}]}, {name: "child 2", childs: [{name: "child 1", childs: [{name: "child 1", childs: []}, {name: "child 2", childs: []}, {name: "child 3", childs: []}]}]}, {name: "child 3", childs: []}]}]}, {name: "child 2", childs: []}, {name: "child 3", childs: []}]}, {name: "child 2", childs: []}, {name: "child 3", childs: [{name: "child 2", childs: []}] }]} }; // main recursive function for chart creation // container: should be this at the begenning // nodeObj: should be the data element containing a JSON object // size: should be the size define options function buildNode(container, nodeObj, index, isLast) { // Creation of the new subtree var subtree = $(subtreeWrapper); // Current node creation var currentNode = $(nodeDiv); var nodeSep = $(nodeSeparator); if (index == 0 && isLast) { // single separator nodeSep.removeClass( "jCspOrgChartNodeSeparator" ).addClass( "jCspOrgChartMainSeparator" ); } else if(index == 0 && !isLast) { // first separator nodeSep.addClass("jCspOrgChartNodeFirstSeparator"); } else if (index != 0 && isLast) { // last separator nodeSep.addClass("jCspOrgChartNodeLastSeparator"); } else { // middle separator nodeSep.addClass("jCspOrgChartNodeMiddleSeparator").append($(middleSeparator)); } currentNode.append(nodeSep); currentNode.append($(nodeContent).text(nodeObj.name)); // Append current node inside his subtree subtree.append(currentNode); // Compute all childs node if (nodeObj.childs.length > 0) { currentNode.append($(mainSeparator)); // Run build node on each childs node with the current subtree and the child node size $.each(nodeObj.childs, function(idx, val){ buildNode(subtree, val, idx, idx == nodeObj.childs.length-1); }); } container.append(subtree); } })(jQuery); if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();