Tree functions

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I need a tree (of folders), can anyone give me some ideas/input, how
do I control collapse, explode etc?

Showing the entire tree will be too much, so I need to show a part of
it only....


Re: Tree functions

Quoted text here. Click to load it

You could use jquery's tree view:

with an XHR call.

An example would be a tree of mp3s to be browsed.

You could return using XHR the exact folders paths as xhtml snippets,
(or pure json if a purist)
 <li><a class="dir" href="/path/to/folder">/path/to/folder</a></li>
 <li><a class="file" href="/path/to/folder/track01.mp3">/path/to/

you would insert this into the DOM at the node clicked on, and bind an
onclick even to the link.
I guess you could use jQuery of prototype/scriptaculous, perhaps
behaviour to bind based on className

when clicked it would XHR to list.php which returns the next snippet,
or sends the URL to an embedded player.

You would get the actual tree like so, sorry for any typos:

function returnData($strDir,$strReturnType)
 $arrResults = array();
 $entry = '';
 $d = '';
 $boolDirs = false;
 $boolFiles = false;
 if($strReturnType =='files')
  $boolFiles = true;
  $boolDirs = true;
 $d = dir($strDir);
 while ( false !== ($entry = $d->read()) )
  if( $boolDirs )
   if( is_dir($strDir.$entry) && ($entry!='.') && ($entry!='..') )
    $arrResults[] = $entry;
   if( !is_dir($strDir.$entry)
   && (strpos($entry,'tmp') === false)
   && ($entry!='404.mp3'))
    $arrResults[] = $entry;
 return $arrResults;

calling it like this:

$arrResults = returnData($strDir,$strReturnType);
$arrResultsFiles = returnData($strDir,"files");

it's inefficient I guess, but would get you what you need

For a more apache based way, you could use javascript to hijack the
link returning false, but using XHR to request the page which
using rewrites would change the requested path from
/music/path/to/folder to

I guess the key is hijacking the links, so your javascript is
unobtrusive, and using javascript/rewrites to request the appropriate
data, which you then insert as first child of the parent node (you
clicked on)
Fisheye has uses something similar to browse the code
bottom left

Site Timeline