/*
	Copyright (c) 2004-2009, The Dojo Foundation All Rights Reserved.
	Available via Academic Free License >= 2.1 OR the modified BSD license.
	see: http://dojotoolkit.org/license for details
*/


if(!dojo._hasResource["dojox.dtl._Templated"]){
dojo._hasResource["dojox.dtl._Templated"]=true;
dojo.provide("dojox.dtl._Templated");
dojo.require("dijit._Templated");
dojo.require("dojox.dtl._base");
dojo.declare("dojox.dtl._Templated",dijit._Templated,{_dijitTemplateCompat:false,buildRendering:function(){
var _1;
if(this.domNode&&!this._template){
return;
}
if(!this._template){
var t=this.getCachedTemplate(this.templatePath,this.templateString,this._skipNodeCache);
if(t instanceof dojox.dtl.Template){
this._template=t;
}else{
_1=t;
}
}
if(!_1){
var _3=dojo._toDom(this._template.render(new dojox.dtl._Context(this)));
if(_3.nodeType!==1&&_3.nodeType!==3){
for(var i=0,l=_3.childNodes.length;i<l;++i){
_1=_3.childNodes[i];
if(_1.nodeType==1){
break;
}
}
}else{
_1=_3;
}
}
this._attachTemplateNodes(_1);
var _6=this.srcNodeRef;
if(_6&&_6.parentNode){
_6.parentNode.replaceChild(_1,_6);
}
if(this.widgetsInTemplate){
var _7=dojo.parser.parse(_1);
this._attachTemplateNodes(_7,function(n,p){
return n[p];
});
}
if(this.domNode){
dojo.place(_1,this.domNode,"before");
this.destroyDescendants();
dojo.destroy(this.domNode);
}
this.domNode=_1;
this._fillContent(_6);
},_templateCache:{},getCachedTemplate:function(_a,_b,_c){
var _d=this._templateCache;
var _e=_b||_a;
if(_d[_e]){
return _d[_e];
}
_b=dojo.string.trim(_b||dijit._Templated._sanitizeTemplateString(dojo._getText(_a)));
if(this._dijitTemplateCompat&&(_c||_b.match(/\$\{([^\}]+)\}/g))){
_b=this._stringRepl(_b);
}
if(_c||!_b.match(/\{[{%]([^\}]+)[%}]\}/g)){
return _d[_e]=dojo._toDom(_b);
}else{
return _d[_e]=new dojox.dtl.Template(_b);
}
},render:function(){
this.buildRendering();
}});
}
