| 1 |
define([ |
| 2 |
"dojo/dom-construct", |
| 3 |
".", |
| 4 |
"./contrib/dijit", |
| 5 |
"./render/dom", |
| 6 |
"dojo/cache", |
| 7 |
"dijit/_TemplatedMixin" |
| 8 |
], function(domConstruct,dtl,ddcd,ddrd,cache,TemplatedMixin){ |
| 9 |
|
| 10 |
dtl._DomTemplated = function(){ |
| 11 |
|
| 12 |
|
| 13 |
}; |
| 14 |
dtl._DomTemplated.prototype = { |
| 15 |
_dijitTemplateCompat: false, |
| 16 |
buildRendering: function(){ |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
this.domNode = this.srcNodeRef || dojo.create('div'); |
| 22 |
|
| 23 |
if(!this._render){ |
| 24 |
var old = ddcd.widgetsInTemplate; |
| 25 |
ddcd.widgetsInTemplate = this.widgetsInTemplate; |
| 26 |
this.template = this.template && this.template !== true ? this.template : this._getCachedTemplate(this.templatePath, this.templateString); |
| 27 |
this._render = new ddrd.Render(this.domNode, this.template); |
| 28 |
ddcd.widgetsInTemplate = old; |
| 29 |
} |
| 30 |
|
| 31 |
var context = this._getContext(); |
| 32 |
if(!this._created){ |
| 33 |
delete context._getter; |
| 34 |
} |
| 35 |
this.render(context); |
| 36 |
|
| 37 |
this.domNode = this.template.getRootNode(); |
| 38 |
if(this.srcNodeRef && this.srcNodeRef.parentNode){ |
| 39 |
domConstruct.destroy(this.srcNodeRef); |
| 40 |
delete this.srcNodeRef; |
| 41 |
} |
| 42 |
}, |
| 43 |
setTemplate: function( template, context){ |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
if(dojox.dtl.text._isTemplate(template)){ |
| 51 |
this.template = this._getCachedTemplate(null, template); |
| 52 |
}else{ |
| 53 |
this.template = this._getCachedTemplate(template); |
| 54 |
} |
| 55 |
this.render(context); |
| 56 |
}, |
| 57 |
render: function( context, tpl){ |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
if(tpl){ |
| 65 |
this.template = tpl; |
| 66 |
} |
| 67 |
this._render.render(this._getContext(context), this.template); |
| 68 |
}, |
| 69 |
_getContext: function(context){ |
| 70 |
if(!(context instanceof dojox.dtl.Context)){ |
| 71 |
context = false; |
| 72 |
} |
| 73 |
context = context || new dojox.dtl.Context(this); |
| 74 |
context.setThis(this); |
| 75 |
return context; |
| 76 |
}, |
| 77 |
_getCachedTemplate: function(templatePath, templateString){ |
| 78 |
if(!this._templates){ |
| 79 |
this._templates = {}; |
| 80 |
} |
| 81 |
if(!templateString){ |
| 82 |
templateString = cache(templatePath, {sanitize: true}); |
| 83 |
} |
| 84 |
var key = templateString; |
| 85 |
var tmplts = this._templates; |
| 86 |
if(tmplts[key]){ |
| 87 |
return tmplts[key]; |
| 88 |
} |
| 89 |
return (tmplts[key] = new dojox.dtl.DomTemplate( |
| 90 |
TemplatedMixin.getCachedTemplate( |
| 91 |
templateString, |
| 92 |
true |
| 93 |
) |
| 94 |
)); |
| 95 |
} |
| 96 |
}; |
| 97 |
return dtl._DomTemplated; |
| 98 |
}); |
| 99 |
|