t('YUI treeview settings'), 'page callback' => 'drupal_get_form', 'page arguments' => array('yui_treeview_settings_form'), 'access callback' => 'user_access', 'access arguments' => array('administer site configuration'), 'description' => t("View/Modify YUI treeview settings"), ); $items['yui_treeview/sample'] = array( 'page callback' => 'yui_treeview_sample', 'access callback' => 'user_access', 'access arguments' => array('Access YUI treeview'), 'type' => MENU_CALLBACK ); return $items; } /* * implementation of hook_perm(). */ function yui_treeview_perm() { $array = array('Access YUI treeview'); return $array; } /* *The settings page. */ function yui_treeview_settings_form() { $form = array(); return system_settings_form($form); } function yui_treeview_sample() { $nodes[] = (object)array('parent' => 0, 'id' => 1, 'label' => 'YUI', 'href' => 'http://developer.yahoo.com/yui'); $nodes[] = (object)array('parent' => 1, 'id' => 2, 'label' => 'Editor', 'href' => 'http://developer.yahoo.com/yui/editor'); $nodes[] = (object)array('parent' => 1, 'id' => 3, 'label' => 'Button', 'href' => 'http://developer.yahoo.com/yui/button'); $id = build_treeview($nodes); return '
foobar
'; } function build_treeview($nodes) { $nodeJS = "var root = tree.getRoot();\n"; foreach ($nodes as $node) { $parent = ($node->parent == 0 ? 'root' : 'node_' . $node->parent); $nodeJS .= "var node_$node->id = new YAHOO.widget.TextNode(" . drupal_to_js($node) . ", $parent, false);\n"; } return render_treeview($nodeJS); } /* * Add the javascript/CSS needed to render the treeview */ function render_treeview($nodes) { if (!user_access('Access YUI treeview')) { return; } static $id; $id++; $yui_source = variable_get('yui_source','http://yui.yahooapis.com/2.5.2'); yui_add_css('treeview', $yui_source, '/build/fonts/fonts-min.css'); yui_add_css('treeview', $yui_source, '/build/treeview/assets/skins/sam/treeview.css'); yui_add_js('treeview', $yui_source, '/build/yahoo-dom-event/yahoo-dom-event.js'); yui_add_js('treeview', $yui_source, '/build/treeview/treeview-min.js'); drupal_add_js(" YAHOO.util.Event.onContentReady('treeview-$id', function() { tree = new YAHOO.widget.TreeView('treeview-' + $id); $nodes tree.draw(); });", "inline", "footer"); return "treeview-$id"; }