Connecting Tech Pros Worldwide Forums | Help | Site Map

Tree functions

jodleren
Guest
 
Posts: n/a
#1: Mar 25 '07
Hello!

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....

BR
Sonnich


shimmyshack
Guest
 
Posts: n/a
#2: Mar 26 '07

re: Tree functions


On 25 Mar, 21:37, "jodleren" <sonn...@hot.eewrote:
Quote:
Hello!
>
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....
>
BR
Sonnich
You could use jquery's tree view:
http://be.twixt.us/jquery/treeView.php

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)
<ul>
<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/
folder/track01.mp3</a></li>
</ul>

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;
}
else
{
$boolDirs = true;
}
$d = dir($strDir);
while ( false !== ($entry = $d->read()) )
{
if( $boolDirs )
{
if( is_dir($strDir.$entry) && ($entry!='.') && ($entry!='..') )
{
$arrResults[] = $entry;
}
}
else
{
if( !is_dir($strDir.$entry)
&& (strpos($entry,'tmp') === false)
&& ($entry!='404.mp3'))
{
$arrResults[] = $entry;
}
}
}
$d->close();
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
/list.php?path=/music/path/to/folder

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
http://fisheye5.cenqua.com
bottom left

Closed Thread