From 83fddcac19c2a0801d7c8ea415a219013a9b96c2 Mon Sep 17 00:00:00 2001 From: Wes Date: Fri, 16 Mar 2012 14:38:28 +0000 Subject: [PATCH] issue #8: clicking links inside nodes doesn't collapse nodes now. --- jquery.jOrgChart.js | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/jquery.jOrgChart.js b/jquery.jOrgChart.js index 10cf348..1ca18d4 100644 --- a/jquery.jOrgChart.js +++ b/jquery.jOrgChart.js @@ -147,7 +147,6 @@ // Method that recursively builds the tree function buildNode($node, $appendTo, level, opts) { - var $table = $(""); var $tbody = $(""); @@ -168,7 +167,7 @@ .end() .html(); - var new_node_id = $node.attr("id") + var new_node_id = $node.attr("id"); if (typeof new_node_id !== 'undefined' && new_node_id !== false) { $nodeDiv = $("
").addClass("node").attr("id", $node.attr("id")).append($nodeContent); }else{ @@ -178,20 +177,20 @@ // Expand and contract nodes if ($childNodes.length > 0) { $nodeDiv.click(function() { - var $this = $(this); - var $tr = $this.closest("tr"); + var $this = $(this); + var $tr = $this.closest("tr"); - if($tr.hasClass('contracted')){ - $this.css('cursor','n-resize'); - $tr.removeClass('contracted').addClass('expanded'); - $tr.nextAll("tr").css('visibility', ''); - }else{ - $this.css('cursor','s-resize'); - $tr.removeClass('expanded').addClass('contracted'); - $tr.nextAll("tr").css('visibility', 'hidden'); - } - }); - } + if($tr.hasClass('contracted')){ + $this.css('cursor','n-resize'); + $tr.removeClass('contracted').addClass('expanded'); + $tr.nextAll("tr").css('visibility', ''); + }else{ + $this.css('cursor','s-resize'); + $tr.removeClass('expanded').addClass('contracted'); + $tr.nextAll("tr").css('visibility', 'hidden'); + } + }); + } $nodeCell.append($nodeDiv); $nodeRow.append($nodeCell); @@ -259,6 +258,12 @@ $table.append($tbody); $appendTo.append($table); + + /* Prevent trees collapsing if a link inside a node is clicked */ + $nodeDiv.children('a').click(function(e){ + console.log(e); + e.stopPropagation(); + }); }; })(jQuery);