In the YUI 3 Gallery: Adam Moore's YUI TreeView Port

By YUI TeamFebruary 19, 2010

click through to run this example in the browserAs the YUI Team wraps up work on the core widget foundation for YUI 3, one of the things we're seeing in the YUI 3 Gallery is transitional solutions that help flesh out YUI 3 implementations. Some of these, like Julien Lecomte's SimpleMenu, are pure YUI 3, and others, like Adam Moore's TreeView module, help bridge the gap between YUI 2 and 3 and will likely be replaced by other gallery modules or shipping YUI 3 widgets down the road.

Adam's TreeView port is a conversion of the popular TreeView Control from YUI 2. The YUI 3 Gallery version runs on the YUI 3 foundation and makes use of Dav Glass's gallery-port module to bridge some of the API changes. Not all of the features in the YUI 2 version are supported (date editing and animation, for example, aren't included), but it's trivial to get a standard TreeView running with this gallery module. All of the code comes off the CDN and can be combo-handled.

And here's some sample code. Script and CSS file inclusion:

<link type="text/css" rel="stylesheet" 
     /gallery-treeview.css" />
<script type="text/javascript" 


<div id="treeView"></div>

Implementation script:

<script language="javascript">

//Create a YUI instance that uses the treeview gallery module
YUI().use('gallery-treeview', function(Y) {

//Associate the YAHOO variable with and instance of Dav Glass's
//Port utility:
var YAHOO = Y.Port();

//Instantiate the Tree using standard YUI 2 syntax:
var tree = new YAHOO.widget.TreeView("treeView", [
	{type:'Text', label:'Cars',expanded:true, children:[
			'Aston Martin',
			{type: 'Text', label:'GM', href:"", expanded:false, children:[
	{type:'Text', label:'Computers', editable:true, children: [
// Render the tree:

Click through for a working version of this example.