root / trunk / web / dojo / dijit / _Templated.js
History | View | Annotate | Download (4.06 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["dijit._Templated"]){ |
| 9 |
dojo._hasResource["dijit._Templated"]=true; |
| 10 |
dojo.provide("dijit._Templated");
|
| 11 |
dojo.require("dijit._Widget");
|
| 12 |
dojo.require("dojo.string");
|
| 13 |
dojo.require("dojo.parser");
|
| 14 |
dojo.require("dojo.cache");
|
| 15 |
dojo.declare("dijit._Templated",null,{templateString:null,templatePath:null,widgetsInTemplate:false,_skipNodeCache:false,_earlyTemplatedStartup:false,constructor:function(){ |
| 16 |
this._attachPoints=[];
|
| 17 |
},_stringRepl:function(_1){ |
| 18 |
var _2=this.declaredClass,_3=this; |
| 19 |
return dojo.string.substitute(_1,this,function(_4,_5){ |
| 20 |
if(_5.charAt(0)=="!"){ |
| 21 |
_4=dojo.getObject(_5.substr(1),false,_3); |
| 22 |
} |
| 23 |
if(typeof _4=="undefined"){ |
| 24 |
throw new Error(_2+" template:"+_5); |
| 25 |
} |
| 26 |
if(_4==null){ |
| 27 |
return ""; |
| 28 |
} |
| 29 |
return _5.charAt(0)=="!"?_4:_4.toString().replace(/"/g,"""); |
| 30 |
},this);
|
| 31 |
},buildRendering:function(){ |
| 32 |
var _6=dijit._Templated.getCachedTemplate(this.templatePath,this.templateString,this._skipNodeCache); |
| 33 |
var _7;
|
| 34 |
if(dojo.isString(_6)){
|
| 35 |
_7=dojo._toDom(this._stringRepl(_6));
|
| 36 |
if(_7.nodeType!=1){ |
| 37 |
throw new Error("Invalid template: "+_6); |
| 38 |
} |
| 39 |
}else{
|
| 40 |
_7=_6.cloneNode(true);
|
| 41 |
} |
| 42 |
this.domNode=_7;
|
| 43 |
this._attachTemplateNodes(_7);
|
| 44 |
if(this.widgetsInTemplate){ |
| 45 |
var _8=dojo.parser,_9,_a;
|
| 46 |
if(_8._query!="[dojoType]"){ |
| 47 |
_9=_8._query; |
| 48 |
_a=_8._attrName; |
| 49 |
_8._query="[dojoType]";
|
| 50 |
_8._attrName="dojoType";
|
| 51 |
} |
| 52 |
var cw=(this._startupWidgets=dojo.parser.parse(_7,{noStart:!this._earlyTemplatedStartup,inherited:{dir:this.dir,lang:this.lang}})); |
| 53 |
if(_9){
|
| 54 |
_8._query=_9; |
| 55 |
_8._attrName=_a; |
| 56 |
} |
| 57 |
this._supportingWidgets=dijit.findWidgets(_7);
|
| 58 |
this._attachTemplateNodes(cw,function(n,p){ |
| 59 |
return n[p];
|
| 60 |
}); |
| 61 |
} |
| 62 |
this._fillContent(this.srcNodeRef); |
| 63 |
},_fillContent:function(_b){ |
| 64 |
var _c=this.containerNode; |
| 65 |
if(_b&&_c){
|
| 66 |
while(_b.hasChildNodes()){
|
| 67 |
_c.appendChild(_b.firstChild); |
| 68 |
} |
| 69 |
} |
| 70 |
},_attachTemplateNodes:function(_d,_e){ |
| 71 |
_e=_e||function(n,p){
|
| 72 |
return n.getAttribute(p);
|
| 73 |
}; |
| 74 |
var _f=dojo.isArray(_d)?_d:(_d.all||_d.getElementsByTagName("*")); |
| 75 |
var x=dojo.isArray(_d)?0:-1; |
| 76 |
for(;x<_f.length;x++){
|
| 77 |
var _10=(x==-1)?_d:_f[x]; |
| 78 |
if(this.widgetsInTemplate&&_e(_10,"dojoType")){ |
| 79 |
continue;
|
| 80 |
} |
| 81 |
var _11=_e(_10,"dojoAttachPoint"); |
| 82 |
if(_11){
|
| 83 |
var _12,_13=_11.split(/\s*,\s*/); |
| 84 |
while((_12=_13.shift())){
|
| 85 |
if(dojo.isArray(this[_12])){ |
| 86 |
this[_12].push(_10);
|
| 87 |
}else{
|
| 88 |
this[_12]=_10;
|
| 89 |
} |
| 90 |
this._attachPoints.push(_12);
|
| 91 |
} |
| 92 |
} |
| 93 |
var _14=_e(_10,"dojoAttachEvent"); |
| 94 |
if(_14){
|
| 95 |
var _15,_16=_14.split(/\s*,\s*/); |
| 96 |
var _17=dojo.trim;
|
| 97 |
while((_15=_16.shift())){
|
| 98 |
if(_15){
|
| 99 |
var _18=null; |
| 100 |
if(_15.indexOf(":")!=-1){ |
| 101 |
var _19=_15.split(":"); |
| 102 |
_15=_17(_19[0]);
|
| 103 |
_18=_17(_19[1]);
|
| 104 |
}else{
|
| 105 |
_15=_17(_15); |
| 106 |
} |
| 107 |
if(!_18){
|
| 108 |
_18=_15; |
| 109 |
} |
| 110 |
this.connect(_10,_15,_18);
|
| 111 |
} |
| 112 |
} |
| 113 |
} |
| 114 |
var _1a=_e(_10,"waiRole"); |
| 115 |
if(_1a){
|
| 116 |
dijit.setWaiRole(_10,_1a); |
| 117 |
} |
| 118 |
var _1b=_e(_10,"waiState"); |
| 119 |
if(_1b){
|
| 120 |
dojo.forEach(_1b.split(/\s*,\s*/),function(_1c){ |
| 121 |
if(_1c.indexOf("-")!=-1){ |
| 122 |
var _1d=_1c.split("-"); |
| 123 |
dijit.setWaiState(_10,_1d[0],_1d[1]); |
| 124 |
} |
| 125 |
}); |
| 126 |
} |
| 127 |
} |
| 128 |
},startup:function(){ |
| 129 |
dojo.forEach(this._startupWidgets,function(w){ |
| 130 |
if(w&&!w._started&&w.startup){
|
| 131 |
w.startup(); |
| 132 |
} |
| 133 |
}); |
| 134 |
this.inherited(arguments); |
| 135 |
},destroyRendering:function(){ |
| 136 |
dojo.forEach(this._attachPoints,function(_1e){ |
| 137 |
delete this[_1e]; |
| 138 |
},this);
|
| 139 |
this._attachPoints=[];
|
| 140 |
this.inherited(arguments); |
| 141 |
}}); |
| 142 |
dijit._Templated._templateCache={};
|
| 143 |
dijit._Templated.getCachedTemplate=function(_1f,_20,_21){ |
| 144 |
var _22=dijit._Templated._templateCache;
|
| 145 |
var key=_20||_1f;
|
| 146 |
var _23=_22[key];
|
| 147 |
if(_23){
|
| 148 |
try{
|
| 149 |
if(!_23.ownerDocument||_23.ownerDocument==dojo.doc){
|
| 150 |
return _23;
|
| 151 |
} |
| 152 |
} |
| 153 |
catch(e){
|
| 154 |
} |
| 155 |
dojo.destroy(_23); |
| 156 |
} |
| 157 |
if(!_20){
|
| 158 |
_20=dojo.cache(_1f,{sanitize:true});
|
| 159 |
} |
| 160 |
_20=dojo.string.trim(_20); |
| 161 |
if(_21||_20.match(/\$\{([^\}]+)\}/g)){ |
| 162 |
return (_22[key]=_20);
|
| 163 |
}else{
|
| 164 |
var _24=dojo._toDom(_20);
|
| 165 |
if(_24.nodeType!=1){ |
| 166 |
throw new Error("Invalid template: "+_20); |
| 167 |
} |
| 168 |
return (_22[key]=_24);
|
| 169 |
} |
| 170 |
}; |
| 171 |
if(dojo.isIE){
|
| 172 |
dojo.addOnWindowUnload(function(){
|
| 173 |
var _25=dijit._Templated._templateCache;
|
| 174 |
for(var key in _25){ |
| 175 |
var _26=_25[key];
|
| 176 |
if(typeof _26=="object"){ |
| 177 |
dojo.destroy(_26); |
| 178 |
} |
| 179 |
delete _25[key];
|
| 180 |
} |
| 181 |
}); |
| 182 |
} |
| 183 |
dojo.extend(dijit._Widget,{dojoAttachEvent:"",dojoAttachPoint:"",waiRole:"",waiState:""});
|
| 184 |
} |