JHtmlBehavior/tree: Difference between revisions
From Joomla! Documentation
m clean up |
m preparing for archive only |
||
Line 89: | Line 89: | ||
===Examples=== | ===Examples=== | ||
=== Code Examples === | |||
<dpl> | <dpl> | ||
noresultsheader=\n | noresultsheader=\n | ||
category=tree | category=tree | ||
category=JHtmlBehavior | category=JHtmlBehavior | ||
namespace=CodeExample | |||
category=MethodExample | category=MethodExample | ||
include=* | include=* |
Latest revision as of 01:45, 25 March 2017
<! removed transcluded page call, red link never existed >
Syntax
static 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
public static function tree($id, $params = array(), $root = array())
{
static $trees;
if (!isset($trees)) {
$trees = array();
}
// Include mootools framework
JHtml::_('behavior.framework');
JHTML::_('script','system/mootree.js', false, true);
JHTML::_('stylesheet','system/mootree.css', array(), true);
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'] : JHTML::_('image','system/mootree.gif', '', array(), true, true);
// 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;
}
<! removed transcluded page call, red link never existed >
Examples
Code Examples