Jquery file tree - how to return the name of a folder in a folder

I installed and try to configure the Jquery File Tree so that when the folder name is clicked, the name and path of the folder will be returned to the calling function. Currently, it only expands and collapses folders and returns the file name with a file click.

So I also need to return the folder and cannot see where this is caused.

I am using php connector. Below is the link where I downloaded the sample code: http://abeautifulsite.net/blog/2008/03/jquery-file-tree/

thanks ed

+4
source share
2 answers

Not sure if there is an "API" way. But if you look at the source code (line 64-81)

if( $(this).parent().hasClass('directory') ) { if( $(this).parent().hasClass('collapsed') ) { // Expand if( !o.multiFolder ) { $(this).parent().parent().find('UL').slideUp({ duration: o.collapseSpeed, easing: o.collapseEasing }); $(this).parent().parent().find('LI.directory').removeClass('expanded').addClass('collapsed'); } $(this).parent().find('UL').remove(); // cleanup showTree( $(this).parent(), escape($(this).attr('rel').match( /.*\// )) ); $(this).parent().removeClass('collapsed').addClass('expanded'); } else { // Collapse $(this).parent().find('UL').slideUp({ duration: o.collapseSpeed, easing: o.collapseEasing }); $(this).parent().removeClass('expanded').addClass('collapsed'); } } else { h($(this).attr('rel')); } 

It looks like you can call another function inside the hasClass('directory') if hasClass('directory') , and it will work.

So you could:

Change line 36 to

 fileTree: function(o, h, dire) { 

Between 65 and 66 add

 dire($(this).attr('rel')); 

If you want to have more control / flexibility / information, you can do dire($(this)); , and it will send a jQuery object instead of the rel attribute.

Example:

 $(document).ready( function() { $('#container_id').fileTree({ root: '/some/folder/' }, function(file) { // do something when a file is clicked }, function(dir){ // do something when a dir is clicked }); }); 

I have not tested it, you may need to change a couple of things.

+8
source

This worked very well, I just changed the last function to โ€œterribleโ€, as if it were code between lines 65 and 66

  ... function(dire){ // do something when a dir is clicked } 
+1
source

All Articles