Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2150 mathias 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
 
5
dojox.dtl.render.html.sensitivity = {
6
	// summary:
7
	//		Set conditions under which to buffer changes
8
	// description:
9
	//		Necessary if you make a lot of changes to your template.
10
	//		What happens is that the entire node, from the attached DOM Node
11
	//		down gets swapped with a clone, and until the entire rendering
12
	//		is complete, we don't replace the clone again. In this way, renders are
13
	//		"batched".
14
	//
15
	//		But, if we're only changing a small number of nodes, we might no want to buffer at all.
16
	//		The higher numbers mean that even small changes will result in buffering.
17
	//		Each higher level includes the lower levels.
18
	NODE: 1, // If a node changes, implement buffering
19
	ATTRIBUTE: 2, // If an attribute or node changes, implement buffering
20
	TEXT: 3 // If any text at all changes, implement buffering
21
}
22
dojox.dtl.render.html.Render = function(/*DOMNode?*/ attachPoint, /*dojox.dtl.HtmlTemplate?*/ tpl){
23
	this._tpl = tpl;
24
	this._node = attachPoint;
25
	this._swap = dojo.hitch(this, function(){
26
		// summary: Swaps the node out the first time the DOM is changed
27
		// description: Gets swapped back it at end of render
28
		if(this._node === this._tpl.getRootNode()){
29
			var frag = this._node;
30
			this._node = this._node.cloneNode(true);
31
			frag.parentNode.replaceChild(this._node, frag);
32
		}
33
	});
34
}
35
dojo.extend(dojox.dtl.render.html.Render, {
36
	sensitivity: dojox.dtl.render.html.sensitivity,
37
	setAttachPoint: function(/*Node*/ node){
38
		this._node = node;
39
	},
40
	render: function(/*dojox.dtl.HtmlTemplate*/ tpl, /*Object*/ context, /*dojox.dtl.HtmlBuffer?*/ buffer){
41
		if(!this._node){
42
			throw new Error("You cannot use the Render object without specifying where you want to render it");
43
		}
44
 
45
		buffer = buffer || tpl.getBuffer();
46
 
47
		if(context.getThis() && context.getThis().buffer == this.sensitivity.NODE){
48
			var onAddNode = dojo.connect(buffer, "onAddNode", this, "_swap");
49
			var onRemoveNode = dojo.connect(buffer, "onRemoveNode", this, "_swap");
50
		}
51
 
52
		if(this._tpl && this._tpl !== tpl){
53
			this._tpl.unrender(context, buffer);
54
		}
55
		this._tpl = tpl;
56
 
57
		var frag = tpl.render(context, buffer).getParent();
58
 
59
		dojo.disconnect(onAddNode);
60
		dojo.disconnect(onRemoveNode);
61
 
62
		if(this._node !== frag){
63
			this._node.parentNode.replaceChild(frag, this._node);
64
			dojo._destroyElement(this._node);
65
			this._node = frag;
66
		}
67
	}
68
});
69
 
70
}