Hi,

I've been working for the past few days or more on a simple file
manager that uses PHP and jQuery.  Basically, where I'm at:  I'm able
to list all files in a starting directory.  When a user clicks on a
folder, it opens the clicked folder and lists all files in that
directory and so on.

I am using .load() to load in each clicked folder's contents... and
that works just fine.  But I realized a couple of days ago that in
order to add clickable events and everything, I have to use a callback
each time I use the .load() function.  So I got that.  (The callback
function essentially calls my whole jQuery JS script that is placed
inside a function named "test()").

When a user clicks on a folder (to view its contents, and by the way,
this is just an html Anchor link) that works fine.  The problem is,
when a user clicks on an already opened folder to close it, it takes
TWO (sometimes more depending on the directory depth,) clicks to close
the folder instead of one.  I'm pretty sure my logic for hiding and
showing folders is fine, because it works for the base directory when
I delete the callback in my code.

I have the feeling my callback is somehow taking my one click (when
trying to close a folder,) and duplicating it or something.

Here is what is going on with the code...

test = function() {

$(document).ready(

  function()
  {

    tree = $('#myTree');

    $('img.expandImage', tree.get(0)).click(
      function()
      {

        subbranch = $('ul', this.parentNode.parentNode).eq(0);

        # open folder
        if (subbranch.css('display') == 'none') {

          subbranch.show();
          this.src = '../img/open.gif';

          $
(this.parentNode.parentNode.getElementsByTagName("ul")).load(this.parentNode.href,
test);

        } else {

          # hide folder
          subbranch.hide();
          this.src = '../img/closed.gif';


        }

        return false;

      });

  });

}



Any help is greatly appreciated!

Andy

Reply via email to