[Zope-CVS] CVS: ZopeProducts/RotterdamSprint - xmltree.js:1.1

Paul Everitt paul@zope.com
Wed, 4 Dec 2002 05:23:14 -0500


Update of /cvs-repository/ZopeProducts/RotterdamSprint
In directory cvs.zope.org:/tmp/cvs-serv17902

Added Files:
	xmltree.js 
Log Message:
first checkin, ready to integrate with joachim's dynamically generated xml


=== Added File ZopeProducts/RotterdamSprint/xmltree.js ===


var ELEMENT_NODE = 1;
var TEXT_NODE = 3;
var folderdata_url = 'children.xml';

function togglenode (n) {

  if (typeof(n.style) == 'undefined') {
    alert('no style on node');
 }

  if (n.style.display == 'none')
    n.style.display = 'block';
  else 
    n.style.display = 'none';
}

function togglecursor (e) {
  if(e.target)
    elem=e.target;
  else
    elem=e.srcElement;
  if(elem.nodeType == TEXT_NODE)
  {elem.parentNode.style.cursor='pointer';
  /* elem.parentNode.style.textDecoration='underline';*/}
  else
  {elem.style.cursor='auto';
  /* elem.style.textDecoration='none';*/}
}

function togglenodes (e) {
  if(e.target) {
    // Mozilla uses this
    elem=e.target.parentNode;
  }
  else {
    // IE uses this
    elem=e.srcElement;
  }
//  alert(elem.tagName);
  zid=elem.id;
  if(zid == 'navtree')
  {return}
//  if(elem.nodeType != TEXT_NODE)
//  {return}
  collections = elem.getElementsByTagName('collection');
  num = collections.length;
  for (var i = num - 1; i >=0; i--) {
    togglenode(collections[i]);
  }
  items = elem.getElementsByTagName('item');
  num = items.length;
  for (var i = num - 1; i >=0; i--) {
    togglenode(items[i]);
 
}
}

function getControlPrefix() {
   if (getControlPrefix.prefix)
      return getControlPrefix.prefix;
   
   var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];
   var o, o2;
   for (var i = 0; i < prefixes.length; i++) {
      try {
         // try to create the objects
         o = new ActiveXObject(prefixes[i] + ".XmlHttp");
         o2 = new ActiveXObject(prefixes[i] + ".XmlDom");
         return getControlPrefix.prefix = prefixes[i];
      }
      catch (ex) {};
   }
   
   throw new Error("Could not find an installed XML parser");
}


// XmlHttp factory
function XmlHttp() {}

XmlHttp.create = function () {
      if (window.XMLHttpRequest) {
         var req = new XMLHttpRequest();
         
         // some older versions of Moz did not support the readyState property
         // and the onreadystate event so we patch it!
         if (req.readyState == null) {
            req.readyState = 1;
            req.addEventListener("load", function () {
               req.readyState = 4;
               if (typeof req.onreadystatechange == "function")
                  req.onreadystatechange();
            }, false);
         }
         
         return req;
      }
      if (window.ActiveXObject) {
         s = getControlPrefix() + '.XmlHttp';
         return new ActiveXObject(getControlPrefix() + ".XmlHttp");
      }
};

function loadtree () {
  var xmlHttp = XmlHttp.create(); 
  xmlHttp.open('GET',folderdata_url,false); 
  xmlHttp.send(null);
  var data = xmlHttp.responseXML.documentElement;
  var navtree = document.getElementById('navtreecontents');
  
  var items = data.childNodes;
  var numitems = items.length;
  for (var i=0; i< numitems; i++) {
    curritem = items[i];

    if (curritem.nodeType != ELEMENT_NODE) {
      continue;
    }

    currtext = curritem.getAttribute('title');
//    alert(currtext);
    newtextnode = document.createTextNode(currtext);
    newelem = document.createElement(curritem.tagName);
    newelem.appendChild(newtextnode);

  children= curritem.childNodes;
  numchildren = children.length;
  for (var j = 0; j < numchildren; j++) {
    currchild = children[j];

    if (currchild.nodeType != ELEMENT_NODE) {
      continue;
    }

    currtext = currchild.getAttribute('title');
    newtextnode = document.createTextNode(currtext);
    newchild = document.createElement(currchild.tagName);
    newchild.appendChild(newtextnode);

    newelem.appendChild(newchild);
    }

    navtree.appendChild(newelem);
  }

//  alert(document.getElementsByTagName('collection').length);

}