home *** CD-ROM | disk | FTP | other *** search
- /* treeview.js
-
- Copyright (c) 1997 Microsoft Corporation. All rights reserved.
-
- nodes must be spans
-
- Do not put onClick handlers on nodes: they'll be overwritten. Instead, make
- another span inside of the node and put your click handler there.
-
- */
-
- /****************
- RegisterTreeViewPage()
-
- This is the basic initialization call for pages that
- use the tree view. It dynamically binds to open and close
- node links so that they open and close when clicked.
-
- Call this function in the body onLoad:
-
- <body onLoad="top.RegisterTreeViewPage(this.document);">
-
- ****************/
- function RegisterTreeViewPage(document){
- BindToNodes(document);
- CloseAllNodes(document);
- BindToItemText(document);
- }
-
- function BindToItemText(document){
-
- // walk all of the spans in the document and bind to the text items,
- // so that they change class when hovered over or selected
-
- var spansToBind = new Array;
- var spansToBindIndex = 0;
-
- var collectionsArray = new Array;
- allSpans = document.all.tags("span");
-
- // loop through all the spans in the doc
- for (var i=0; i < allSpans.length; i++) {
-
- // if this is one of our text item spans add it to our list of spans to bind to
- if (allSpans[i].className == "treeText") {
- spansToBind[spansToBindIndex] = allSpans[i];
- spansToBindIndex++;
- }
- }
-
- for (i=0;i<spansToBind.length; i++) {
- // bind to each of our text spans
-
- // BUGBUG: if there's a way to detect whether or not a
- // treeText-selected rule exists we should check here and do nothing
- // if it doesn't exist
- spansToBind[i].onmouseover = function(){
- if (this.className == "treeText-selected"){
- this.className = "treeText-hover-selected";
- }else {
- this.className="treeText-hover";
- }
- };
- spansToBind[i].onmouseout = function(){
- if (this.className == "treeText-hover-selected"){
- this.className = "treeText-selected";
- }else {
- this.className="treeText";
- }
- };
- spansToBind[i].onclick = function(){
- DeselectAllTreeItems(document);
- this.className="treeText-hover-selected";
- };
- }
- }
-
- function BindToNodes(document) {
- // walk all of the spans in the document and bind to the nodes,
- // so that closed nodes open up and open nodes close up when clicked
-
- var spansToBind = new Array;
- var spansToBindIndex = 0;
-
- allSpans = document.all.tags("span");
-
- // loop through all the spans in the doc
- for (var i=0; i < allSpans.length; i++) {
- // if this is one of our tree view node spans add it to our list of spans to bind to
- if ( (allSpans[i].className == "treeviewNode-closed") ||
- (allSpans[i].className == "treeviewNode-open") ){
- spansToBind[spansToBindIndex] = allSpans[i];
- spansToBindIndex++;
- }
- }
-
- for (i=0;i<spansToBind.length; i++) {
- // bind to each of our treeview nodes
- spansToBind[i].onclick = function(){
- DoNodeClick(document,this);
- };
- }
- }
-
- function DoNodeClick(document,node){
- // I'm thinking that we should figure out
- // what our node text is and if the event
- // originated in or is contained in that we
- // want to process it
-
- var nodeHead;
- var nodePart; // is this an open or close node span?
-
- var srcElem = document.parentWindow.event.srcElement;
-
- var dashPos = node.id.indexOf("-");
- if (dashPos != -1) { // the dash was found
- nodePart = node.id.substring(dashPos+1, node.id.length);
- var baseName = node.id.substring(0,dashPos);
- nodeHead = document.all[baseName + "-head"];
-
- if (nodePart == "closed" || nodeHead.contains(srcElem) ) {
- ToggleTreeview(document,baseName);
- }
-
- }
- }
-
- function ToggleTreeview(document, nodeBaseName){
-
- var baseName;
- var closedNode;
- var openNode;
- var closedNodeCaption;
- var openNodeCaption;
- var nodeList;
-
- // find the the open and closed node ids for this node
-
- // the nodes have ids of the form
- // FOO-closed and FOO-open
-
- closedNode = document.all[nodeBaseName + "-closed"];
- openNode = document.all[nodeBaseName + "-open"];
- closedNodeCaption = document.all[nodeBaseName + "-caption-closed"];
- openNodeCaption = document.all[nodeBaseName + "-caption-open"];
- nodeList = document.all[nodeBaseName + "-list"];
-
- if (closedNode!=null){
- if (closedNode.style.display!="none"){
- // node is closed, open it up
-
- // first close all nodes
- CloseAllNonParentNodes(document, closedNode);
- //CloseAllNodes(document);
-
- // now open the clicked node
- OpenNode(closedNode, openNode, nodeList);
- if (openNodeCaption)
- openNodeCaption.className = "treeText-selected";
- }
- else{
- // node is open, close it up
- CloseNode(closedNode, openNode, nodeList);
- if (closedNodeCaption)
- closedNodeCaption.className = "treeText-selected";
- }
- }
- }
-
- function CloseNode(closedNode, openNode, nodeList){
- if (closedNode!=null && openNode != null){
- closedNode.style.display="inline";
- openNode.style.display="none";
- }
- if (nodeList!=null){
- nodeList.style.display="none";
- }
- }
-
- function OpenNode(closedNode, openNode,nodeList){
- if (closedNode!=null && openNode != null){
- closedNode.style.display="none";
- openNode.style.display="inline";
- }
- if (nodeList!=null){
- nodeList.style.display="inline";
- }
- }
-
- function CloseAllNonParentNodes(document, child){
-
- CloseAllNodes(document);
-
- // walk up the tree to find what, if any, treeViewNode-open
- // element contains the child
- var openNode = null;
- var currentElem = child;
-
- while (currentElem.parentElement != null) {
-
- if (currentElem.parentElement.className == "treeviewNode-open") {
- openNode = currentElem.parentElement;
- break;
- }
-
- currentElem = currentElem.parentElement;
-
- }
-
- if (openNode != null){
-
- var dashPos = openNode.id.indexOf("-");
- if (dashPos != -1) { // the dash was found
- var baseName = openNode.id.substring(0,dashPos);
- closedNode = document.all[baseName + "-closed"];
-
- if (closedNode)
- closedNode.style.display = "none";
-
- openNode.style.display = "inline";
- }
- }
- }
-
- function CloseAllNodes(document) {
-
- // makes sure that all the treeviewNode-open elements in a document
- // are hidden and that all the treeviewNode-closed elements in a
- // document are shown.
-
- var allSpans = document.all.tags("span");
-
- for (var i=0; i < allSpans.length; i++) {
- if (allSpans[i].className == "treeviewNode-closed"){
- var closedNode = document.all[allSpans[i].id];
- if (closedNode != null) {
- if (closedNode.style.display != "inline") {
- closedNode.style.display = "inline";
- }
- }
- } else if (allSpans[i].className == "treeviewNode-open"){
- var openNode = document.all[allSpans[i].id];
- if (openNode != null) {
- if (openNode.style.display != "none") {
- openNode.style.display = "none";
- }
- }
- } else if (allSpans[i].className == "treeviewNode-list"){
- var list = document.all[allSpans[i].id];
- if (list != null) {
- if (list.style.display != "none") {
- list.style.display = "none";
- }
- }
- }
- }
- }
-
- function DeselectAllTreeItems(document){
- var allSpans = document.all.tags("span");
-
- for (var i=0; i < allSpans.length; i++) {
- if ( (allSpans[i].className == "treeText-selected")||
- (allSpans[i].className == "treeText-hover-selected") ){
-
- allSpans[i].className = "treeText";
- }
- }
- }
-