wesnolte / jOrgChart

A jQuery plugin to draw tree-like structures such as OrgCharts.
992 stars 674 forks source link

Nodes initially collapsed cannot be expanded in new version #15

Closed njsden closed 12 years ago

njsden commented 12 years ago

I had a tree with a few nodes set as class="collapsed" which made them display initially contracted but that could be expanded/contracted at will.

After downloading the new version (the one with the new License terms) I noticed that those nodes with class="collapsed' still show up contracted as expected but clicking on them does not allow them to expand anymore.

When trying to trace back the issue I found that in the new version the following line had been removed when compared to the previous one in the "Expand and contract nodes" section of the code:

$tr.nextAll("tr").fadeToggle("fast");

By adding that line back to the new version the initially collapsed nodes can now be expanded/contracted as before.

The final section of code looks like this:

// Expand and contract nodes
if ($childNodes.length > 0) {
  $nodeDiv.click(function() {
      var $this = $(this);
      var $tr = $this.closest("tr");
      // Added line below to fix issue when node initially collapsed cannot be expanded!
      //            (copied from former version of the library)
      $tr.nextAll("tr").fadeToggle("fast");

      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');
      }
    });
}

I tested this on Internet Explorer 8.0.7601.17514 on Windows 7.

Awesome work on the library by the way! The functionality is great!

wesnolte commented 12 years ago

Thanks for the heads up. There was a deeper issue that your testing brought to light.