Index: openacs-4/packages/ajaxhelper/www/resources/dojo-ajax/src/xml/Parse.js =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ajaxhelper/www/resources/dojo-ajax/src/xml/Attic/Parse.js,v diff -u -r1.1 -r1.2 --- openacs-4/packages/ajaxhelper/www/resources/dojo-ajax/src/xml/Parse.js 7 Nov 2006 02:38:06 -0000 1.1 +++ openacs-4/packages/ajaxhelper/www/resources/dojo-ajax/src/xml/Parse.js 25 Dec 2006 16:39:59 -0000 1.2 @@ -14,28 +14,35 @@ //TODO: determine dependencies // currently has dependency on dojo.xml.DomUtil nodeTypes constants... -/* - generic class for taking a node and parsing it into an object -*/ - // using documentFragment nomenclature to generalize in case we don't want to require passing a collection of nodes with a single parent dojo.xml.Parse = function(){ - - // supported dojoTagName's: + // summary: + // generic class for taking a DOM node and parsing it into an object + // based on the "dojo tag name" of that node. // - // => prefix:tag - // => dojo:tag - // => dojo:tag - // => dojo:type - // => prefix:type - // => dojo:type - // => dojo:type + // supported dojoTagName's: + // => prefix:tag + // => dojo:tag + // => dojo:tag + // => dojo:type + // => prefix:type + // => dojo:type + // => dojo:type + var isIE = ((dojo.render.html.capable)&&(dojo.render.html.ie)); + // get normalized (lowercase) tagName // some browsers report tagNames in lowercase no matter what function getTagName(node){ - return ((node)&&(node.tagName) ? node.tagName.toLowerCase() : ''); + /* + return ((node)&&(node["tagName"]) ? node.tagName.toLowerCase() : ''); + */ + try{ + return node.tagName.toLowerCase(); + }catch(e){ + return ""; + } } // locate dojo qualified tag name @@ -88,16 +95,16 @@ } if(djt){ return "dojo:"+djt.toLowerCase(); } // => dojo:type - if((!dj_global["djConfig"])|| (djConfig["ignoreClassNames"])){ + if((dj_global["djConfig"])&&(!djConfig["ignoreClassNames"])){ // FIXME: should we make this optionally enabled via djConfig? var classes = node.className||node.getAttribute("class"); // FIXME: following line, without check for existence of classes.indexOf // breaks firefox 1.5's svg widgets if((classes )&&(classes.indexOf)&&(classes.indexOf("dojo-")!=-1)){ - var aclasses = classes.split(" "); - for(var x=0, c=aclasses.length; x as nodes that should be parsed. Ignore these - if((tagName)&&(tagName.indexOf("/")==0)){ - return null; - } + if(isIE && tagName.indexOf("/")==0){ return null; } + + try{ + var attr = node.getAttribute("parseWidgets"); + if(attr && attr.toLowerCase() == "false"){ + return {}; + } + }catch(e){/*continue*/} + // look for a dojoml qualified name // process dojoml only when optimizeForDojoML is true @@ -124,11 +155,8 @@ tagName = dojoTagName || tagName; process = Boolean(dojoTagName); } - - if(node && node.getAttribute && node.getAttribute("parseWidgets") && node.getAttribute("parseWidgets") == "false") { - return {}; - } + var parsedNodeSet = {}; parsedNodeSet[tagName] = []; var pos = tagName.indexOf(":"); if(pos>0){ @@ -159,7 +187,6 @@ var tcn = node.childNodes.item(i); switch(tcn.nodeType){ case dojo.dom.ELEMENT_NODE: // element nodes, call this function recursively - count++; var ctn = getDojoTagName(tcn) || getTagName(tcn); if(!parsedNodeSet[ctn]){ parsedNodeSet[ctn] = []; @@ -169,6 +196,7 @@ (tcn.childNodes.item(0).nodeType == dojo.dom.TEXT_NODE)){ parsedNodeSet[ctn][parsedNodeSet[ctn].length-1].value = tcn.childNodes.item(0).nodeValue; } + count++; break; case dojo.dom.TEXT_NODE: // if a single text node is the child, treat it as an attribute if(node.childNodes.length == 1){ @@ -205,15 +233,34 @@ return parsedNodeSet; }; + /* parses a set of attributes on a node into an object tree */ - this.parseAttributes = function(node){ + this.parseAttributes = function(/*DomNode*/node){ + // summary: + // creates an attribute object that maps attribute values for the + // passed node. Note that this is similar to creating a JSON + // representation of a DOM node. + // usage: + // a node with the following serialization: + //
...
+ // would yeild the following return structure when passed into this + // function: + // { + // "foo": { + // "value": "bar" + // }, + // "baz": { + // "value": "thud" + // } + // } + // var parsedAttributeSet = {}; var atts = node.attributes; // TODO: should we allow for duplicate attributes at this point... // would any of the relevant dom implementations even allow this? var attnode, i=0; while((attnode=atts[i++])){ - if((dojo.render.html.capable)&&(dojo.render.html.ie)){ + if(isIE){ if(!attnode){ continue; } if((typeof attnode == "object")&& (typeof attnode.nodeValue == 'undefined')||