Tree functions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jodleren

    #1

    Tree functions

    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

    #2
    Re: Tree functions

    On 25 Mar, 21:37, "jodleren" <sonn...@hot.ee wrote:
    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:


    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($str Dir,$strReturnT ype)
    {
    $arrResults = array();
    $entry = '';
    $d = '';
    $boolDirs = false;
    $boolFiles = false;
    if($strReturnTy pe =='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.m p3'))
    {
    $arrResults[] = $entry;
    }
    }
    }
    $d->close();
    return $arrResults;
    }

    calling it like this:

    $arrResults = returnData($str Dir,$strReturnT ype);
    $arrResultsFile s = returnData($str Dir,"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

    bottom left

    Comment

    Working...