root / trunk / web / dojo / dojox / xml / widgetParser.js @ 13
History | View | Annotate | Download (1.73 KB)
| 1 |
/*
|
|---|---|
| 2 |
Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
| 3 |
Available via Academic Free License >= 2.1 OR the modified BSD license.
|
| 4 |
see: http://dojotoolkit.org/license for details
|
| 5 |
*/
|
| 6 |
|
| 7 |
|
| 8 |
if(!dojo._hasResource["dojox.xml.widgetParser"]){ |
| 9 |
dojo._hasResource["dojox.xml.widgetParser"]=true; |
| 10 |
dojo.provide("dojox.xml.widgetParser");
|
| 11 |
dojo.require("dojox.xml.parser");
|
| 12 |
dojo.require("dojo.parser");
|
| 13 |
dojox.xml.widgetParser=new function(){ |
| 14 |
var d=dojo;
|
| 15 |
this.parseNode=function(_1){ |
| 16 |
var _2=[];
|
| 17 |
d.query("script[type='text/xml']",_1).forEach(function(_3){ |
| 18 |
_2.push.apply(_2,this._processScript(_3));
|
| 19 |
},this).orphan();
|
| 20 |
return d.parser.instantiate(_2);
|
| 21 |
}; |
| 22 |
this._processScript=function(_4){ |
| 23 |
var _5=_4.src?d._getText(_4.src):_4.innerHTML||_4.firstChild.nodeValue;
|
| 24 |
var _6=this.toHTML(dojox.xml.parser.parse(_5).firstChild); |
| 25 |
var _7=d.query("[dojoType]",_6); |
| 26 |
dojo.query(">",_6).place(_4,"before"); |
| 27 |
_4.parentNode.removeChild(_4); |
| 28 |
return _7;
|
| 29 |
}; |
| 30 |
this.toHTML=function(_8){ |
| 31 |
var _9;
|
| 32 |
var _a=_8.nodeName;
|
| 33 |
var dd=dojo.doc;
|
| 34 |
var _b=_8.nodeType;
|
| 35 |
if(_b>=3){ |
| 36 |
return dd.createTextNode((_b==3||_b==4)?_8.nodeValue:""); |
| 37 |
} |
| 38 |
var _c=_8.localName||_a.split(":").pop(); |
| 39 |
var _d=_8.namespaceURI||(_8.getNamespaceUri?_8.getNamespaceUri():""); |
| 40 |
if(_d=="html"){ |
| 41 |
_9=dd.createElement(_c); |
| 42 |
}else{
|
| 43 |
var _e=_d+"."+_c; |
| 44 |
_9=_9||dd.createElement((_e=="dijit.form.ComboBox")?"select":"div"); |
| 45 |
_9.setAttribute("dojoType",_e);
|
| 46 |
} |
| 47 |
d.forEach(_8.attributes,function(_f){
|
| 48 |
var _10=_f.name||_f.nodeName;
|
| 49 |
var _11=_f.value||_f.nodeValue;
|
| 50 |
if(_10.indexOf("xmlns")!=0){ |
| 51 |
if(dojo.isIE&&_10=="style"){ |
| 52 |
_9.style.setAttribute("cssText",_11);
|
| 53 |
}else{
|
| 54 |
_9.setAttribute(_10,_11); |
| 55 |
} |
| 56 |
} |
| 57 |
}); |
| 58 |
d.forEach(_8.childNodes,function(cn){
|
| 59 |
var _12=this.toHTML(cn); |
| 60 |
if(_c=="script"){ |
| 61 |
_9.text+=_12.nodeValue; |
| 62 |
}else{
|
| 63 |
_9.appendChild(_12); |
| 64 |
} |
| 65 |
},this);
|
| 66 |
return _9;
|
| 67 |
}; |
| 68 |
}(); |
| 69 |
} |