1 if(!dojo._hasResource["dojox.dtl.render.html"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojox.dtl.render.html"] = true;
3 dojo.provide("dojox.dtl.render.html");
4 dojo.require("dojox.dtl.Context");
6 dojox.dtl.render.html.sensitivity = {
8 // Set conditions under which to buffer changes
10 // Necessary if you make a lot of changes to your template.
11 // What happens is that the entire node, from the attached DOM Node
12 // down gets swapped with a clone, and until the entire rendering
13 // is complete, we don't replace the clone again. In this way, renders are
16 // But, if we're only changing a small number of nodes, we might no want to buffer at all.
17 // The higher numbers mean that even small changes will result in buffering.
18 // Each higher level includes the lower levels.
19 NODE: 1, // If a node changes, implement buffering
20 ATTRIBUTE: 2, // If an attribute or node changes, implement buffering
21 TEXT: 3 // If any text at all changes, implement buffering
23 dojox.dtl.render.html.Render = function(/*DOMNode?*/ attachPoint, /*dojox.dtl.HtmlTemplate?*/ tpl){
25 this.domNode = attachPoint;
26 this._swap = dojo.hitch(this, function(){
27 // summary: Swaps the node out the first time the DOM is changed
28 // description: Gets swapped back it at end of render
29 if(this.domNode === this._tpl.getRootNode()){
30 var frag = this.domNode;
31 this.domNode = this.domNode.cloneNode(true);
32 frag.parentNode.replaceChild(this.domNode, frag);
36 dojo.extend(dojox.dtl.render.html.Render, {
37 sensitivity: dojox.dtl.render.html.sensitivity,
38 setAttachPoint: function(/*Node*/ node){
41 render: function(/*Object*/ context, /*dojox.dtl.HtmlTemplate?*/ tpl, /*dojox.dtl.HtmlBuffer?*/ buffer){
43 throw new Error("You cannot use the Render object without specifying where you want to render it");
46 tpl = tpl || this._tpl;
47 buffer = buffer || tpl.getBuffer();
48 context = context || new dojox.dtl.Context();
50 if(context.getThis() && context.getThis().buffer == this.sensitivity.NODE){
51 var onAddNode = dojo.connect(buffer, "onAddNode", this, "_swap");
52 var onRemoveNode = dojo.connect(buffer, "onRemoveNode", this, "_swap");
55 if(this._tpl && this._tpl !== tpl){
56 this._tpl.unrender(context, buffer);
60 var frag = tpl.render(context, buffer).getParent();
62 throw new Error("Rendered template does not have a root node");
65 dojo.disconnect(onAddNode);
66 dojo.disconnect(onRemoveNode);
68 if(this.domNode !== frag){
69 this.domNode.parentNode.replaceChild(frag, this.domNode);
70 dojo._destroyElement(this.domNode);