Actions

API15

JHTMLBehavior/tree

From Joomla! Documentation

< API15:JHTMLBehavior
Revision as of 17:21, 22 March 2010 by Doxiki (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

[Edit Descripton]

Description:JHTMLBehavior/tree

Contents

Syntax

tree($id, $params=array(), $root=array())
Parameter Name Default Value Description
$id
$params array()
$root array()

Defined in

libraries/joomla/html/html/behavior.php

Importing

jimport( 'joomla.html.html.behavior' );

Source Body

function tree($id, $params = array(), $root = array())
{
        static $trees;
 
        if (!isset($trees)) {
                $trees = array();
        }
 
        // Include mootools framework
        JHTMLBehavior::mootools();
        JHTML::script('mootree.js');
        JHTML::stylesheet('mootree.css');
 
        if (isset($trees[$id]) && ($trees[$id])) {
                return;
        }
 
        // Setup options object
        $opt['div']             = (array_key_exists('div', $params)) ? $params['div'] : $id.'_tree';
        $opt['mode']    = (array_key_exists('mode', $params)) ? $params['mode'] : 'folders';
        $opt['grid']    = (array_key_exists('grid', $params)) ? '\\'.$params['grid'] : '\\true';
        $opt['theme']   = (array_key_exists('theme', $params)) ? $params['theme'] : JURI::root(true).'/media/system/images/mootree.gif';
 
        // Event handlers
        $opt['onExpand']        = (array_key_exists('onExpand', $params)) ? '\\'.$params['onExpand'] : null;
        $opt['onSelect']        = (array_key_exists('onSelect', $params)) ? '\\'.$params['onSelect'] : null;
        $opt['onClick']         = (array_key_exists('onClick', $params)) ? '\\'.$params['onClick'] : '\\function(node){  window.open(node.data.url, $chk(node.data.target) ? node.data.target : \'_self\'); }';
        $options = JHTMLBehavior::_getJSObject($opt);
 
        // Setup root node
        $rt['text']             = (array_key_exists('text', $root)) ? $root['text'] : 'Root';
        $rt['id']               = (array_key_exists('id', $root)) ? $root['id'] : null;
        $rt['color']    = (array_key_exists('color', $root)) ? $root['color'] : null;
        $rt['open']             = (array_key_exists('open', $root)) ? '\\'.$root['open'] : '\\true';
        $rt['icon']             = (array_key_exists('icon', $root)) ? $root['icon'] : null;
        $rt['openicon'] = (array_key_exists('openicon', $root)) ? $root['openicon'] : null;
        $rt['data']             = (array_key_exists('data', $root)) ? $root['data'] : null;
        $rootNode = JHTMLBehavior::_getJSObject($rt);
 
        $treeName               = (array_key_exists('treeName', $params)) ? $params['treeName'] : '';
 
        $js = '         window.addEvent(\'domready\', function(){
                tree'.$treeName.' = new MooTreeControl('.$options.','.$rootNode.');
                tree'.$treeName.'.adopt(\''.$id.'\');})';
 
        // Attach tooltips to document
        $document =& JFactory::getDocument();
        $document->addScriptDeclaration($js);
 
        // Set static array
        $trees[$id] = true;
        return;
}

[Edit See Also] SeeAlso:JHTMLBehavior/tree

Examples

<CodeExamplesForm />