2150 |
mathias |
1 |
if(!dojo._hasResource["dojox.dtl.tag.html"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
|
|
|
2 |
dojo._hasResource["dojox.dtl.tag.html"] = true;
|
|
|
3 |
dojo.provide("dojox.dtl.tag.html");
|
|
|
4 |
|
|
|
5 |
dojo.require("dojox.dtl._base");
|
|
|
6 |
|
|
|
7 |
dojox.dtl.tag.html.HtmlNode = function(name){
|
|
|
8 |
this.contents = new dojox.dtl.Filter(name);
|
|
|
9 |
this._div = document.createElement("div");
|
|
|
10 |
this._lasts = [];
|
|
|
11 |
}
|
|
|
12 |
dojo.extend(dojox.dtl.tag.html.HtmlNode, {
|
|
|
13 |
render: function(context, buffer){
|
|
|
14 |
var text = this.contents.resolve(context);
|
|
|
15 |
text = text.replace(/<(\/?script)/ig, '<$1').replace(/\bon[a-z]+\s*=/ig, '');
|
|
|
16 |
if(this._rendered && this._last != text){
|
|
|
17 |
buffer = this.unrender(context, buffer);
|
|
|
18 |
}
|
|
|
19 |
this._last = text;
|
|
|
20 |
|
|
|
21 |
// This can get reset in the above tag
|
|
|
22 |
if(!this._rendered){
|
|
|
23 |
this._rendered = true;
|
|
|
24 |
var div = this._div;
|
|
|
25 |
div.innerHTML = text;
|
|
|
26 |
var children = div.childNodes;
|
|
|
27 |
while(children.length){
|
|
|
28 |
var removed = div.removeChild(children[0]);
|
|
|
29 |
this._lasts.push(removed);
|
|
|
30 |
buffer = buffer.concat(removed);
|
|
|
31 |
}
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
return buffer;
|
|
|
35 |
},
|
|
|
36 |
unrender: function(context, buffer){
|
|
|
37 |
if(this._rendered){
|
|
|
38 |
this._rendered = false;
|
|
|
39 |
this._last = "";
|
|
|
40 |
for(var i = 0, node; node = this._lasts[i++];){
|
|
|
41 |
buffer = buffer.remove(node);
|
|
|
42 |
dojo._destroyElement(node);
|
|
|
43 |
}
|
|
|
44 |
this._lasts = [];
|
|
|
45 |
}
|
|
|
46 |
return buffer;
|
|
|
47 |
},
|
|
|
48 |
clone: function(buffer){
|
|
|
49 |
return new dojox.dtl.tag.html.HtmlNode(this.contents.contents);
|
|
|
50 |
},
|
|
|
51 |
toString: function(){ return "dojox.dtl.tag.html.HtmlNode"; }
|
|
|
52 |
});
|
|
|
53 |
|
|
|
54 |
dojox.dtl.tag.html.StyleNode = function(styles){
|
|
|
55 |
this.contents = {};
|
|
|
56 |
this._styles = styles;
|
|
|
57 |
for(var key in styles){
|
|
|
58 |
this.contents[key] = new dojox.dtl.Template(styles[key]);
|
|
|
59 |
}
|
|
|
60 |
}
|
|
|
61 |
dojo.extend(dojox.dtl.tag.html.StyleNode, {
|
|
|
62 |
render: function(context, buffer){
|
|
|
63 |
for(var key in this.contents){
|
|
|
64 |
dojo.style(buffer.getParent(), key, this.contents[key].render(context));
|
|
|
65 |
}
|
|
|
66 |
return buffer;
|
|
|
67 |
},
|
|
|
68 |
unrender: function(context, buffer){
|
|
|
69 |
return buffer;
|
|
|
70 |
},
|
|
|
71 |
clone: function(buffer){
|
|
|
72 |
return new dojox.dtl.tag.html.HtmlNode(this._styles);
|
|
|
73 |
},
|
|
|
74 |
toString: function(){ return "dojox.dtl.tag.html.StyleNode"; }
|
|
|
75 |
});
|
|
|
76 |
|
|
|
77 |
dojox.dtl.tag.html.AttachNode = function(key){
|
|
|
78 |
this.contents = key;
|
|
|
79 |
}
|
|
|
80 |
dojo.extend(dojox.dtl.tag.html.AttachNode, {
|
|
|
81 |
render: function(context, buffer){
|
|
|
82 |
if(!this._rendered){
|
|
|
83 |
this._rendered = true;
|
|
|
84 |
context.getThis()[this.contents] = buffer.getParent();
|
|
|
85 |
}
|
|
|
86 |
return buffer;
|
|
|
87 |
},
|
|
|
88 |
unrender: function(context, buffer){
|
|
|
89 |
if(this._rendered){
|
|
|
90 |
this._rendered = false;
|
|
|
91 |
if(context.getThis()[this.contents] === buffer.getParent()){
|
|
|
92 |
delete context.getThis()[this.contents];
|
|
|
93 |
}
|
|
|
94 |
}
|
|
|
95 |
return buffer;
|
|
|
96 |
},
|
|
|
97 |
clone: function(buffer){
|
|
|
98 |
return new dojox.dtl.tag.html.HtmlNode(this._styles);
|
|
|
99 |
},
|
|
|
100 |
toString: function(){ return "dojox.dtl.tag.html.AttachNode"; }
|
|
|
101 |
});
|
|
|
102 |
|
|
|
103 |
dojox.dtl.tag.html.html = function(parser, text){
|
|
|
104 |
var parts = text.split(" ", 2);
|
|
|
105 |
return new dojox.dtl.tag.html.HtmlNode(parts[1]);
|
|
|
106 |
}
|
|
|
107 |
|
|
|
108 |
dojox.dtl.tag.html.tstyle = function(parser, text){
|
|
|
109 |
var styles = {};
|
|
|
110 |
text = text.replace(dojox.dtl.tag.html.tstyle._re, "");
|
|
|
111 |
var rules = text.split(dojox.dtl.tag.html.tstyle._re1);
|
|
|
112 |
for(var i = 0, rule; rule = rules[i]; i++){
|
|
|
113 |
var parts = rule.split(dojox.dtl.tag.html.tstyle._re2);
|
|
|
114 |
var key = parts[0];
|
|
|
115 |
var value = parts[1];
|
|
|
116 |
if(value.indexOf("{{") == 0){
|
|
|
117 |
styles[key] = value;
|
|
|
118 |
}
|
|
|
119 |
}
|
|
|
120 |
return new dojox.dtl.tag.html.StyleNode(styles);
|
|
|
121 |
}
|
|
|
122 |
dojo.mixin(dojox.dtl.tag.html.tstyle, {
|
|
|
123 |
_re: /^tstyle\s+/,
|
|
|
124 |
_re1: /\s*;\s*/g,
|
|
|
125 |
_re2: /\s*:\s*/g
|
|
|
126 |
});
|
|
|
127 |
|
|
|
128 |
dojox.dtl.tag.html.attach = function(parser, text){
|
|
|
129 |
var parts = text.split(dojox.dtl.tag.html.attach._re);
|
|
|
130 |
return new dojox.dtl.tag.html.AttachNode(parts[1]);
|
|
|
131 |
}
|
|
|
132 |
dojo.mixin(dojox.dtl.tag.html.attach, {
|
|
|
133 |
_re: /\s+/g
|
|
|
134 |
})
|
|
|
135 |
|
|
|
136 |
}
|