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 = dojox.dtl; |
---|
11 | cache = dojo.cache; |
---|
12 | TemplatedMixin = dijit._TemplatedMixin |
---|
13 | =====*/ |
---|
14 | dtl._DomTemplated = function(){}; |
---|
15 | dtl._DomTemplated.prototype = { |
---|
16 | _dijitTemplateCompat: false, |
---|
17 | buildRendering: function(){ |
---|
18 | // summary: |
---|
19 | // Construct the UI for this widget, setting this.domNode. |
---|
20 | |
---|
21 | //render needs a domNode to work with |
---|
22 | this.domNode = this.srcNodeRef; |
---|
23 | |
---|
24 | if(!this._render){ |
---|
25 | var old = ddcd.widgetsInTemplate; |
---|
26 | ddcd.widgetsInTemplate = this.widgetsInTemplate; |
---|
27 | this.template = this.template || this._getCachedTemplate(this.templatePath, this.templateString); |
---|
28 | this._render = new ddrd.Render(this.domNode, this.template); |
---|
29 | ddcd.widgetsInTemplate = old; |
---|
30 | } |
---|
31 | |
---|
32 | var context = this._getContext(); |
---|
33 | if(!this._created){ |
---|
34 | delete context._getter; |
---|
35 | } |
---|
36 | this.render(context); |
---|
37 | |
---|
38 | this.domNode = this.template.getRootNode(); |
---|
39 | if(this.srcNodeRef && this.srcNodeRef.parentNode){ |
---|
40 | domConstruct.destroy(this.srcNodeRef); |
---|
41 | delete this.srcNodeRef; |
---|
42 | } |
---|
43 | }, |
---|
44 | setTemplate: function(/*String|dojo._Url*/ template, /*dojox.dtl.Context?*/ context){ |
---|
45 | // summary: |
---|
46 | // Quickly switch between templated by location |
---|
47 | // template: The new template. |
---|
48 | // context: |
---|
49 | // The runtime context. |
---|
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(/*dojox.dtl.Context?*/ context, /*dojox.dtl.DomTemplate?*/ tpl){ |
---|
58 | // summary: |
---|
59 | // Renders this template. |
---|
60 | // context: |
---|
61 | // The runtime context. |
---|
62 | // tpl: |
---|
63 | // The template to render. Optional. |
---|
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 dojox.dtl._DomTemplated; |
---|
98 | }); |
---|
99 | |
---|