<?xml version="1.0" encoding="iso-8859-1" ?>
<?xml-stylesheet type="text/xsl" href="/lib/xsl/devedge-1.00/article_en.xsl"?>
<nde:article 
  url="/toolbox/examples/2002/xb/xbTreeWidgetStatic/" 
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:nde="http://devedge.netscape.com/2002/de"
  xmlns:ent="http://devedge.netscape.com/2003/ent"
  xml:lang="en"
  >

 <nde:header>

   <nde:title>
      Class xbTreeWidgetStatic
   </nde:title>

   <nde:category>
     Manpage
   </nde:category>

  <nde:pubdate year="2002" month="04" day="21" />
  <nde:moddate year="2002" month="07" day="22" />

  <nde:summary>
      Cross Browser Tree Widget with DHTML Support for Gecko based 
      browsers, Internet Explorer 4+,
      and Static HTML support for Opera 5+, Netscape Navigator 4.x. 
  </nde:summary>

  <nde:abstract>
    <p>
      Cross Browser Tree Widget with DHTML Support for Gecko based 
      browsers, Internet Explorer 4+,
      and Static HTML support for Opera 5+, Netscape Navigator 4.x. 
    </p>
  </nde:abstract>

  <nde:authlist>
    <nde:author>
      <nde:authname>Bob Clary</nde:authname>
      <nde:authaffil>Netscape Communications</nde:authaffil>
    </nde:author>
  </nde:authlist>

  <nde:channels>
    <nde:channel id="examples"/>
    <nde:channel id="xb-2002"/>
  </nde:channels>

</nde:header>


 <nde:head>
 </nde:head>

 <nde:content>
   <h2>Synopis</h2>
   <pre><![CDATA[
class xbTreeWidgetStatic
{
public:
xbTreeWidgetStatic(Object handles, Object labels, String classprefix);

  // properties
  Number id;
  Object handles;
  Object labels;
  String classprefix;
  Array  children;

  // methods
  xbTreeWidgetStatic appendChild(xbTreeWidgetStatic child);
  String toHTML();

}

// static Class properties
Number  xbStaticTreeWidget._id;
Object  xbStaticTreeWidget._hash;
Boolean xbStaticTreeWidget._dynamic;

// global functions
Node xbGetNextElement(Node node);

Boolean xbTreeWidgetStaticToggleHandle(HTMLElement handlediv);

xbTreeWidgetStatic xbCreateTreeWidgetStaticFromObject(
  Function getChildren, 
  Function getHandles, 
  Function getLabels, 
  Object obj, 
  String classprefix);
]]></pre>

    <h2>Source</h2>
    <p>
      <a href="xbTreeWidgetStatic.js">xbTreeWidgetStatic.js</a>
    </p>

    <h2>Uses</h2>
    <ul>
      <li>
        Nothing
      </li>
    </ul>

    <h2>See Also</h2>
    
    <ul>
      <li>
      </li>
    </ul>

    <h2>Description</h2>
      <p>
        xbTreeWidgetStatic is a JavaScript object which allows the flexible construction of
        HTML Tree Widgets using a simple API along with HTML. DHTML manipulation of the tree
        is possible in browsers which support the Internet Explorer proprietary HTMLElement.innerHTML
        property. For browsers which do not support this property, xbTreeWidgetStatic will 
        generate a simple hierarchal layout.
      </p>

      <p>
        xbTreeWidgetStatic is designed to be used before a page load event fires by writing
        the HTML into the document.
        xbTreeWidgetStatic is Static because it can not modify the contents of the Tree
        widget after it has been written to the document.
      </p>

      <p>
        xbTreeWidgetStatic requires the use of JavaScript 1.2 in it's implementation
        of it's data structures.
      </p>

      <h3>Notes</h3>

        <h4>Script Location/Invocation</h4>
        <p>
          xbTreeWidgetStatic must be used inside the BODY Tag to document.write the 
          HTML representation of the tree into the document. The xbTreeWidgetStatic 
          itself must be constructed in full either in the HEAD of the document or 
          prior to the document.write in the BODY.
        </p>

        <h4>Netscape Navigator 4</h4>
        <p>
          Netscape Navigator 4 is supported for a simple Non-DHTML version of the 
          Tree Widget.
        </p>

        <h4>Opera 5+</h4>
        <p>
          Opera 5 and above are supported for a simple Non-DHTML version of the 
          Tree Widget.
        </p>


    <h2>Examples</h2>

      <h3>Download</h3>
      <p>
        <a href="examples/xbTreeWidgetStatic-examples.zip">xbTreeWidgetStatic-examples.zip</a>
      </p>

    <h3>Basic Example</h3>
      
    <p>
      This example illustrates the basic steps for creating a simple
      tree widget using xbTreeWidgetStatic
    </p>

        <pre><![CDATA[
<html>
  <head>
    <title>xbTreeWidgetStatic Example</title>

    <!-- 
    Define CSS classes which govern how the tree widget is displayed.
    -->

    <style type="text/css">

      div.treewidgetcontainer
      { 
      }

      /* make the cursor a pointer when over the item in a tree widget */

      div.treewidgethandle
      { 
        cursor: pointer; cursor: hand;
      }

      /* indent each level in the tree by two character positions */

      div.treewidgetchildren 
      { 
        position: relative; 
        left: 2em; 
        display:none;
      }
    </style>    

    <!-- include the scripts needed for xbTreeWidgetStatic -->
    <script language="javascript" src="/xbProjects-srce/xbDebug.js"></script>
    <script language="javascript" src="/xbProjects-srce/xbTreeWidgetStatic.js"></script>

    <script language="javascript">

      // define a variable to hold the reference to your
      // tree widget.

      var xbtreewidgetroot;
      var xbtreewidget;

      // create the root of the tree
      xbtreewidgetroot = new xbTreeWidgetStatic(
       { open: 'insert open handle html here', closed: 'insert closed handle html here'},
       { open: 'insert open label html here',  closed: 'insert closed label html here'}
      );

      // add children to the tree 
      xbtreewidget = xbtreewidgetroot.appendChild( new xbTreeWidgetStatic( ... ) );
      xbtreewidget.appendChild( new xbTreeWidgetStatic( ... ) );
      xbtreewidget.appendChild( new xbTreeWidgetStatic( ... ) );

    </script>
  </head>
  <body>
    <script language="javascript">
      // output the HTML which represents the tree
      document.write(xbtreewidgetroot.toHTML());
    </script>
  </body>
</html>
]]>
        </pre>

        <h3><a href="examples/example-simple-01.html">Simple Example 01</a></h3>

        <p>
          This example illustrates the basics of a working xbTreeWidgetStatic widget
          using simple text handles and labels.
        </p>

        <h3><a href="examples/example-simple-02.html">Simple Example 02</a></h3>

        <p>
          This example expands on the Simple Example 01 by using images and styled labels.
        </p>

        <h3><a href="examples/example-object-01.html">Object Example 01</a></h3>

        <p>
          This example illustrates the basics of a working xbTreeWidgetStatic widget
          created from a JavaScript object using simple text handles and labels. Note this 
          example will not work in Navigator 4 since it uses a DOM object not available in 
          Navigator 4.
        </p>

        <h3><a href="examples/example-object-02.html">Object Example 02</a></h3>

        <p>
          This example expands on the Object Example 01 by using images and styled labels.
        </p>

        <h3><a href="examples/example-combined-01.html">Combined Example 01</a></h3>

        <p>
          This example illustrates using more than one xbTreeWidgetStatic on a page by combining the Simple and 
          Object examples.
        </p>


    <h3>CSS Classes</h3>

    <p>
      The display of xbTreeWidgetStatic trees are controlled via the use of three 
      CSS classes. These class names can be customized by specifying the 
      classprefix when creating the xbTreeWidgetStatic. If not
      otherwise specified, classprefix defaults to 'treewidget'.
    </p>

    <dl>

        <dt>
          classprefixcontainer
        </dt>
        <dd>
          <p>
            Name of CSS class for the container of the Tree Widget. Use this to position 
            the tree widget or to style the widget as a whole.
          </p>
        </dd>

        <dt>
          classprefixhandle
        </dt>
        <dd>
          <p>
            Name of CSS class for the handles in a Tree Widget. Use this to 
            style the widget's handles.
          </p>
        </dd>

        <dt>
          classprefixchildren
        </dt>
        <dd>
          <p>
            Name of CSS class for the child nodes in a Tree Widget. Use this to 
            style the widget's children. For example, you can have an indented
            list by specifying position: relative; left:2em; or have a vertical
            collapsing list by specifying position: relative; left: 0em;
          </p>
        </dd>
    </dl>

    <h2>Properties</h2>
    <dl>

        <dt>
          id
        </dt>
        <dd>
          <p>readonly Number - unique number for a particular instance
            of an xbTreeWidgetStatic which is managed via the constructor and the static class
            property xbTreeWidgetStatic._id. This property is used to generate unique ID's for
            the HTML Elements used to represent the tree data.
          </p>
        </dd>

        <dt>
          handles
        </dt>
        <dd>
          <p>readonly Object - with two properties, open
            and closed each containing a string of HTML to be 
            used to represent the handle of an xbTreeWidgetStatic node in the open or closed
            state respectively.
          </p>
        </dd>

        <dt>
          labels
        </dt>
        <dd>
          <p>readonly Object - with two properties, open
            and closed each containing a string of HTML to be 
            used to represent the label of an xbTreeWidgetStatic node in the open or closed
            state respectively.
          </p>
        </dd>

        <dt>
          classprefix
        </dt>
        <dd>
          <p>readonly String - containing the prefix of CSS classnames
            to be used when displaying the DHTML version of the Tree Widget. If not 
            specified elsewhere the default value is 'treewidget'.
          </p>
        </dd>

        <dt>
          children
        </dt>
        <dd>
          <p>readonly Array - containing the children of the 
            xbTreeWidgetStatic node.
          </p>
        </dd>

    </dl>

    <h2>Methods</h2>
    <dl>

        <dt>xbTreeWidgetStatic(Object handles, Object labels, String classprefix)</dt>
        <dd>
          <p>Constructs an instance of the xbTreeWidgetStatic class.</p>
            <h3>Arguments:</h3>
            <p>
              <ul>
                <li>
                  <p>
              Object handles - contains two properties open and
              closed which contain the HTML strings used to represent the 
              Tree Widget's handle in the open and closed state respectively.
            </p>
            </li>
            <li>
              <p>
              Object labels - contains two properties open and
              closed which contain the HTML strings used to represent the 
              Tree Widget's handle in the open and closed state respectively.
            </p>
            </li>
            <li>
              <p>
              String classprefix - prefix of CSS classes used to style 
              the Tree Widget. By specifying different classprefixes for different Tree Widgets on the 
              same page you can customize the appearance of each Tree independently of the others.
            </p>
            </li>
          </ul>
            </p>
            <h3>Returns:</h3>
            <p>nothing</p>
            <h3>Support</h3>
            <p>Gecko/Netscape 6.x, Netscape Navigator 4+, Internet Explorer 4+, Opera</p>
        </dd>

        <dt>appendChild(xbTreeWidgetStatic child)</dt>
        <dd>
          <p>
            append a xbTreeWidgetStatic to the list of child nodes for this node
          </p>
            <h3>Arguments:</h3>
            <p>
              xbTreeWidgetStatic to be added as a child of this xbTreeWidgetStatic node.
            </p>
            <h3>Returns:</h3>
            <p>
              xbTreeWidgetStatic node that was appended.
            </p>

        </dd>

        <dt>toHTML()</dt>
        <dd>
          <p>returns the HTML representation of the xbTreeWidgetStatic node and 
            it's children.</p>
            <h3>Arguments:</h3>
            <p>
              None
            </p>
            <h3>Returns:</h3>
            <p>
              String containing the HTML of the Tree Widget.
            </p>
        </dd>

    </dl>

    <h2>Global Functions</h2>
    <dl>

        <dt>xbGetNextElement(HTMLElement element)</dt>
        <dd>
          <p>Used internally by the Tree Widget DHTML routines to locate the 
            next sibling element.</p>
            <h3>Arguments:</h3>
            <p>
              HTMLElement element - starting point in the 
              search.
            </p>
            <h3>Returns:</h3>
            <p>
              HTMLElement that is the next sibling of the specified element.
            </p>
            <h3>Support</h3>
            <p>Gecko/Netscape 6.x, Internet Explorer 5+, DOM HTML Compliant browsers</p>
        </dd>

        <dt>xbCreateTreeWidgetStaticFromObject(Function getChildren, Function getHandles, Function getLabels, Object obj, String classprefix)</dt>
        <dd>
          <p>
            Create a TreeWidget from a hierarchal JavaScript object.
          </p>
            <h3>Arguments:</h3>
            <p>
              <ul>
                <li>
                  <p>
                    Function getChildren - reference to function which takes a JavaScript
                    object as input and returns an array containing the list of objects/properties 
                    that are to be displayed as child nodes. Note that xbTreeWidgetStatic does not
                    support recursive JavaScript data structures since all nods of the Tree Widget
                    are added at construction. If you return a recursive reference in the list of
                    child nodes you will cause infinite recursion... So DON'T DO THAT!
                  </p>
                </li>
                <li>
                  <p>
                    Function getHandles - reference to function which takes a JavaScript 
                      object and a classprefix as input and returns an object which contains
                      open and closed properties containing the HTML representing the Tree Widget's handle
                      in open and closed states respectively.
                  </p>
                </li>
                <li>
                  <p>
                    Function getLabels - reference to function which takes a JavaScript 
                      object and a classprefix as input and returns an object which contains
                      open and closed properties containing the HTML representing the Tree Widget's label
                      in open and closed states respectively.
                  </p>
                </li>
                <li>
                  <p>
                    Object obj - reference to the JavaScript object to be displayed as 
                    a Tree Widget.
                  </p>
                </li>
                <li>
                  <p>
                    String classprefix - prefix of CSS classnames to be used when displaying
                    the Tree Widget.
                  </p>
                </li>

              </ul>
            </p>
            <h3>Returns:</h3>
            <p>
              xbTreeWidgetStatic tree that was created.
            </p>

        </dd>

    </dl>
 </nde:content>

<nde:related area="nde">
  <nde:item url="/toolbox/examples/2002/xb/">More xbAPI Examples</nde:item>
</nde:related>

</nde:article>
