Yahoo! UI Library - Tree Control 5 : Tree : GUI Components : JavaScript DHTML examples (example source code) Organized by topic

JavaScript DHTML
C++
PHP
JavaScript DHTML Home »  GUI Components   » [  Tree  ]   
 



Yahoo! UI Library - Tree Control 5

Please note that some example is only working under IE or Firefox.


<!doctype html public "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Yahoo! UI Library - Tree Control</title>
<link rel="stylesheet" type="text/css" href="./examples/treeview/css/screen.css">
<style type="text/css">
    .emLabel, .emLabel:link, .emLabel:visited, .emLabel:hover 
        font-weight: bold;
    }
</style>
</head>
  
<body onload="treeInit()">

<link rel="stylesheet" type="text/css" href="./examples/treeview/css/menu/tree.css">

<div id="pageTitle">
  <h3>Tree Control</h3>
</div>

<script type="text/javascript" src="./build/yahoo/yahoo.js" ></script>

<!-- The following are required for the logger -->
<script type="text/javascript" src="./build/event/event.js"></script>
<script type="text/javascript" src="./build/dom/dom.js"></script>
<script type="text/javascript" src="./build/logger/logger.js"></script>
<!-- End logger reqs -->

<script type="text/javascript" src="./build/treeview/treeview-debug.js" ></script>

<style type="text/css">

/* logger default styles */
/* font size is controlled here: default 77% */
#yui-log {position:absolute;top:1em;right:1em;font-size:77%;text-align:left;}
/* width is controlled here: default 31em */
.yui-log {background-color:#AAA;border:1px solid black;font-family:monospace;z-index:9000;}
.yui-log p {margin:1px;padding:.1em;}
.yui-log button {font-family:monospace;}
.yui-log .yui-log-hd {padding:.5em;background-color:#575757;color:#FFF;}
/* height is controlled here: default 20em*/
.yui-log .yui-log-bd {width:100%;height:20em;background-color:#FFF;border:1px solid gray;overflow:auto;}
.yui-log .yui-log-ft {margin-top:.5em;margin-bottom:1em;}
.yui-log .yui-log-ft .yui-log-categoryfilters {}
.yui-log .yui-log-ft .yui-log-sourcefilters {width:100%;border-top:1px solid #575757;margin-top:.75em;padding-top:.75em;}
.yui-log .yui-log-btns {position:relative;float:right;bottom:.25em;}
.yui-log .yui-log-filtergrp {margin-right:.5em;}
.yui-log .info {background-color:#A7CC25;/* A7CC25 green */
.yui-log .warn {background-color:#F58516;/* F58516 orange */
.yui-log .error {background-color:#E32F0B;/* E32F0B red */
.yui-log .time {background-color:#A6C9D7;/* A6C9D7 blue */
.yui-log .window {background-color:#F2E886;/* F2E886 tan */

</style>


<div id="container">
<img class="ylogo" src="img/logo.gif" alt="" />
  <div id="containerTop">
    <div id="header">
      <h1>
      
      </h1>
      <h4>&nbsp;</h4>
    </div>
    <div id="main">

<div id="rightbar">

<div id="rightBarPad">
<h3>Examples</h3>
    <script type="text/javascript">

    YAHOO.example.logApp = function() {
        var divId;
        return {
            init: function(p_divId, p_toggleElId, p_clearElId) {
                divId = p_divId
            },

            onload: function() {
                if (YAHOO.widget.Logger) {
                    new YAHOO.widget.LogReader"logDiv"height: "400px" } );
                }
            }
        };
    } ()

    YAHOO.util.Event.on(window, "load", YAHOO.example.logApp.onload);

    </script>

    <div id="logDiv"></div>

    
</div>

</div>


  <div id="content">
    <form name="mainForm" action="javscript:;">
  <div class="newsItem">
    <h3>Menu TreeView Widget</h3>
    <p>
    The presentation differences between the default treeview widget and this
    one were accomplished by modifying the css styles in tree.css.  The
    functionality is the same, except the menu does not allow multiple siblings
    to be expanded at one time (when you expand a node, all of its expanded 
    siblings are collapsed.
    </p>

    <div id="expandcontractdiv">
    <a href="javascript:tree.expandAll()">Expand all</a>
    <a href="javascript:tree.collapseAll()">Collapse all</a>
    </div>
    <div id="treeDiv1"></div>

  </div>
  </form>
  </div>
  
      <div id="footerContainer">
        <div id="footer">
          <p>&nbsp;</p>
        </div>
      </div>
    </div>
  </div>
</div>


<script type="text/javascript">

  var tree;
  var nodes = new Array();
  var nodeIndex = 0;
  
  function treeInit() {
    buildRandomTextNodeTree();
  }

  function buildRandomTextNodeTree() {
    tree = new YAHOO.widget.TreeView("treeDiv1");
    tree.onExpand = function(node) {
      // alert(node.index + " was expanded"); 
    }

    tree.onCollapse = function(node) {
      // alert(node.index + " was collapsed"); 
    }

    for (var i = 0; i < Math.floor((Math.random()*43); i++) {
      var thisId = nodeIndex++;
      var thisLabel = "menu" + i;
      // nodes[thisId] = new YAHOO.widget.TextNode({ label: thisLabel }, tree.getRoot(), false);
      // nodes[thisId] = new YAHOO.widget.MenuNode({label:thisLabel, href:"http://asdf"}, tree.getRoot(), false);
      nodes[thisIdnew YAHOO.widget.MenuNode(thisLabel, tree.getRoot()false);

      var p1 = nodes[thisId];
      var l1 = thisLabel;

      for (var j = 0; j < Math.floor(Math.random()*61; j++) { 
        thisId = nodeIndex++;
        thisLabel = l1 + "-" + j;
        // nodes[thisId] = new YAHOO.widget.TextNode({ label: thisLabel }, p1, true);
        nodes[thisIdnew YAHOO.widget.MenuNode(thisLabel, p1, false);

        var p2 = nodes[thisId];
        var l2 = thisLabel;

        for (var k =0; k < Math.floor(Math.random()*61; k++) { 
          thisId = nodeIndex++;
          thisLabel = l2 + "-" + k;

                    /*
          var data = {
              id: thisId,
              label: thisLabel, 
              href: "javascript:onLabelClick(" + thisId + ")" 
            }
*/

          var data = {
              label: thisLabel, 
                            href: "javascript:void(window.open('http://www.yahoo.com'))" 
            }
          nodes[thisIdnew YAHOO.widget.TextNode(data, p2, false);
                    nodes[thisId].labelStyle = "emLabel";

          // nodes[thisId] = new YAHOO.widget.MenuNode(thisLabel, p2, false);
        }

      }

    }

    // nodes[0] = new YAHOO.widget.TextNode(tree.getRoot(), false, "label-0");
    tree.draw();
  }

  var selectedId = null;
  function onLabelClick(id) {

    var node = tree.getNodeByProperty("id", id);
    // alert(node.label);

    var el = node.getLabelEl()

        YAHOO.log("pos: " + YAHOO.util.Dom.getXY(el));

        el.style.backgroundColor = "#c5dbfc";
    

    if (selectedId != null) {
      node = tree.getNodeByProperty("id", selectedId);
      node.getLabelEl().style.backgroundColor = "white";
    }

    selectedId = id;
  }

</script>

  </body>
</html>
 

           
       
Download: yui.zip   ( 3,714  K )  
Related examples in the same category
1.  Explorer based on treeHas Download File
2.  Yahoo! UI Library - Tree ControlHas Download File
3.  Yahoo! UI Library - Tree Control 2Has Download File
4.  Tree ControlHas Download File
5.  Dynamic TreeView ExampleHas Download File
6.  Yahoo! UI Library - Tree Control 3Has Download File
7.  Yahoo! UI Library - Tree Control 4Has Download File
8.  Build a tree in JavaScriptHas Download File
9.  Delete, insert items in a treeHas Download File
10.  Tree selection action handlerHas Download File
11.  Expand, Collapse, Close, Open selected Tree item and branch Has Download File
12.  Change Tree Node Color and IconHas Download File
13.  Checkbox tree node: checked, unchecked, get the checked itemsHas Download File
14.  Change tree expand and collapse iconsHas Download File
15.  Drag and Drop between treesHas Download File
16.  Build tree from xmlHas Download File
17.  Tree navigation barHas Download File
18.  Navigation Tree Has Download File
19.  Navigation Tree menu based on XML
20.  XML Tree
21.  Building Collapsible Trees
22.  Nano TreeHas Download File
23.  Tree which accepts drag and drop event in JavaScript (IE)Has Download File
24.  Simple Tree in JavascriptHas Download File
25.  Elegant simple tree
























Home| Contact Us
Copyright 2003 - 04 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.