root / trunk / web / dojo / dojox / dtl / dom.js @ 11
History | View | Annotate | Download (18.1 KB)
1 |
/*
|
---|---|
2 |
Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
3 |
Available via Academic Free License >= 2.1 OR the modified BSD license.
|
4 |
see: http://dojotoolkit.org/license for details
|
5 |
*/
|
6 |
|
7 |
|
8 |
if(!dojo._hasResource["dojox.dtl.dom"]){ |
9 |
dojo._hasResource["dojox.dtl.dom"]=true; |
10 |
dojo.provide("dojox.dtl.dom");
|
11 |
dojo.require("dojox.dtl._base");
|
12 |
dojo.require("dojox.dtl.Context");
|
13 |
(function(){
|
14 |
var dd=dojox.dtl;
|
15 |
dd.BOOLS={checked:1,disabled:1,readonly:1}; |
16 |
dd.TOKEN_CHANGE=-11;
|
17 |
dd.TOKEN_ATTR=-12;
|
18 |
dd.TOKEN_CUSTOM=-13;
|
19 |
dd.TOKEN_NODE=1;
|
20 |
var _1=dd.text;
|
21 |
var _2=dd.dom={_attributes:{},_uppers:{},_re4:/^function anonymous\(\)\s*{\s*(.*)\s*}$/,_reTrim:/(?:^[\n\s]*(\{%)?\s*|\s*(%\})?[\n\s]*$)/g,_reSplit:/\s*%\}[\n\s]*\{%\s*/g,getTemplate:function(_3){ |
22 |
if(typeof this._commentable=="undefined"){ |
23 |
this._commentable=false; |
24 |
var _4=document.createElement("div"); |
25 |
_4.innerHTML="<!--Test comment handling, and long comments, using comments whenever possible.-->";
|
26 |
if(_4.childNodes.length&&_4.childNodes[0].nodeType==8&&_4.childNodes[0].data=="comment"){ |
27 |
this._commentable=true; |
28 |
} |
29 |
} |
30 |
if(!this._commentable){ |
31 |
_3=_3.replace(/<!--({({|%).*?(%|})})-->/g,"$1"); |
32 |
} |
33 |
if(dojo.isIE){
|
34 |
_3=_3.replace(/\b(checked|disabled|readonly|style)="/g,"t$1=\""); |
35 |
} |
36 |
_3=_3.replace(/\bstyle="/g,"tstyle=\""); |
37 |
var _5;
|
38 |
var _6=dojo.isWebKit;
|
39 |
var _7=[[true,"select","option"],[_6,"tr","td|th"],[_6,"thead","tr","th"],[_6,"tbody","tr","td"],[_6,"table","tbody|thead|tr","tr","td"]]; |
40 |
var _8=[];
|
41 |
for(var i=0,_9;_9=_7[i];i++){ |
42 |
if(!_9[0]){ |
43 |
continue;
|
44 |
} |
45 |
if(_3.indexOf("<"+_9[1])!=-1){ |
46 |
var _a=new RegExp("<"+_9[1]+"(?:.|\n)*?>((?:.|\n)+?)</"+_9[1]+">","ig"); |
47 |
tagLoop: |
48 |
while(_5=_a.exec(_3)){
|
49 |
var _b=_9[2].split("|"); |
50 |
var _c=[];
|
51 |
for(var j=0,_d;_d=_b[j];j++){ |
52 |
_c.push("<"+_d+"(?:.|\n)*?>(?:.|\n)*?</"+_d+">"); |
53 |
} |
54 |
var _e=[];
|
55 |
var _f=dojox.string.tokenize(_5[1],new RegExp("("+_c.join("|")+")","ig"),function(_10){ |
56 |
var tag=/<(\w+)/.exec(_10)[1]; |
57 |
if(!_e[tag]){
|
58 |
_e[tag]=true;
|
59 |
_e.push(tag); |
60 |
} |
61 |
return {data:_10}; |
62 |
}); |
63 |
if(_e.length){
|
64 |
var tag=(_e.length==1)?_e[0]:_9[2].split("|")[0]; |
65 |
var _11=[];
|
66 |
for(var j=0,jl=_f.length;j<jl;j++){ |
67 |
var _12=_f[j];
|
68 |
if(dojo.isObject(_12)){
|
69 |
_11.push(_12.data); |
70 |
}else{
|
71 |
var _13=_12.replace(this._reTrim,""); |
72 |
if(!_13){
|
73 |
continue;
|
74 |
} |
75 |
_12=_13.split(this._reSplit);
|
76 |
for(var k=0,kl=_12.length;k<kl;k++){ |
77 |
var _14=""; |
78 |
for(var p=2,pl=_9.length;p<pl;p++){ |
79 |
if(p==2){ |
80 |
_14+="<"+tag+" dtlinstruction=\"{% "+_12[k].replace("\"","\\\"")+" %}\">"; |
81 |
}else{
|
82 |
if(tag==_9[p]){
|
83 |
continue;
|
84 |
}else{
|
85 |
_14+="<"+_9[p]+">"; |
86 |
} |
87 |
} |
88 |
} |
89 |
_14+="DTL";
|
90 |
for(var p=_9.length-1;p>1;p--){ |
91 |
if(p==2){ |
92 |
_14+="</"+tag+">"; |
93 |
}else{
|
94 |
if(tag==_9[p]){
|
95 |
continue;
|
96 |
}else{
|
97 |
_14+="</"+_9[p]+">"; |
98 |
} |
99 |
} |
100 |
} |
101 |
_11.push("ÿ"+_8.length);
|
102 |
_8.push(_14); |
103 |
} |
104 |
} |
105 |
} |
106 |
_3=_3.replace(_5[1],_11.join("")); |
107 |
} |
108 |
} |
109 |
} |
110 |
} |
111 |
for(var i=_8.length;i--;){ |
112 |
_3=_3.replace("ÿ"+i,_8[i]);
|
113 |
} |
114 |
var re=/\b([a-zA-Z_:][a-zA-Z0-9_\-\.:]*)=['"]/g; |
115 |
while(_5=re.exec(_3)){
|
116 |
var _15=_5[1].toLowerCase(); |
117 |
if(_15=="dtlinstruction"){ |
118 |
continue;
|
119 |
} |
120 |
if(_15!=_5[1]){ |
121 |
this._uppers[_15]=_5[1]; |
122 |
} |
123 |
this._attributes[_15]=true; |
124 |
} |
125 |
var _4=document.createElement("div"); |
126 |
_4.innerHTML=_3; |
127 |
var _16={nodes:[]}; |
128 |
while(_4.childNodes.length){
|
129 |
_16.nodes.push(_4.removeChild(_4.childNodes[0]));
|
130 |
} |
131 |
return _16;
|
132 |
},tokenize:function(_17){ |
133 |
var _18=[];
|
134 |
for(var i=0,_19;_19=_17[i++];){ |
135 |
if(_19.nodeType!=1){ |
136 |
this.__tokenize(_19,_18);
|
137 |
}else{
|
138 |
this._tokenize(_19,_18);
|
139 |
} |
140 |
} |
141 |
return _18;
|
142 |
},_swallowed:[],_tokenize:function(_1a,_1b){ |
143 |
var _1c=false; |
144 |
var _1d=this._swallowed; |
145 |
var i,j,tag,_1e;
|
146 |
if(!_1b.first){
|
147 |
_1c=_1b.first=true;
|
148 |
var _1f=dd.register.getAttributeTags();
|
149 |
for(i=0;tag=_1f[i];i++){ |
150 |
try{
|
151 |
(tag[2])({swallowNode:function(){ |
152 |
throw 1; |
153 |
}},new dd.Token(dd.TOKEN_ATTR,"")); |
154 |
} |
155 |
catch(e){
|
156 |
_1d.push(tag); |
157 |
} |
158 |
} |
159 |
} |
160 |
for(i=0;tag=_1d[i];i++){ |
161 |
var _20=_1a.getAttribute(tag[0]); |
162 |
if(_20){
|
163 |
var _1d=false; |
164 |
var _21=(tag[2])({swallowNode:function(){ |
165 |
_1d=true;
|
166 |
return _1a;
|
167 |
}},new dd.Token(dd.TOKEN_ATTR,tag[0]+" "+_20)); |
168 |
if(_1d){
|
169 |
if(_1a.parentNode&&_1a.parentNode.removeChild){
|
170 |
_1a.parentNode.removeChild(_1a); |
171 |
} |
172 |
_1b.push([dd.TOKEN_CUSTOM,_21]); |
173 |
return;
|
174 |
} |
175 |
} |
176 |
} |
177 |
var _22=[];
|
178 |
if(dojo.isIE&&_1a.tagName=="SCRIPT"){ |
179 |
_22.push({nodeType:3,data:_1a.text}); |
180 |
_1a.text="";
|
181 |
}else{
|
182 |
for(i=0;_1e=_1a.childNodes[i];i++){ |
183 |
_22.push(_1e); |
184 |
} |
185 |
} |
186 |
_1b.push([dd.TOKEN_NODE,_1a]); |
187 |
var _23=false; |
188 |
if(_22.length){
|
189 |
_1b.push([dd.TOKEN_CHANGE,_1a]); |
190 |
_23=true;
|
191 |
} |
192 |
for(var key in this._attributes){ |
193 |
var _24=false; |
194 |
var _25=""; |
195 |
if(key=="class"){ |
196 |
_25=_1a.className||_25; |
197 |
}else{
|
198 |
if(key=="for"){ |
199 |
_25=_1a.htmlFor||_25; |
200 |
}else{
|
201 |
if(key=="value"&&_1a.value==_1a.innerHTML){ |
202 |
continue;
|
203 |
}else{
|
204 |
if(_1a.getAttribute){
|
205 |
_25=_1a.getAttribute(key,2)||_25;
|
206 |
if(key=="href"||key=="src"){ |
207 |
if(dojo.isIE){
|
208 |
var _26=location.href.lastIndexOf(location.hash);
|
209 |
var _27=location.href.substring(0,_26).split("/"); |
210 |
_27.pop(); |
211 |
_27=_27.join("/")+"/"; |
212 |
if(_25.indexOf(_27)==0){ |
213 |
_25=_25.replace(_27,"");
|
214 |
} |
215 |
_25=decodeURIComponent(_25); |
216 |
} |
217 |
}else{
|
218 |
if(key=="tstyle"){ |
219 |
_24=key; |
220 |
key="style";
|
221 |
}else{
|
222 |
if(dd.BOOLS[key.slice(1)]&&dojo.trim(_25)){ |
223 |
key=key.slice(1);
|
224 |
}else{
|
225 |
if(this._uppers[key]&&dojo.trim(_25)){ |
226 |
_24=this._uppers[key];
|
227 |
} |
228 |
} |
229 |
} |
230 |
} |
231 |
} |
232 |
} |
233 |
} |
234 |
} |
235 |
if(_24){
|
236 |
_1a.setAttribute(_24,"");
|
237 |
_1a.removeAttribute(_24); |
238 |
} |
239 |
if(typeof _25=="function"){ |
240 |
_25=_25.toString().replace(this._re4,"$1"); |
241 |
} |
242 |
if(!_23){
|
243 |
_1b.push([dd.TOKEN_CHANGE,_1a]); |
244 |
_23=true;
|
245 |
} |
246 |
_1b.push([dd.TOKEN_ATTR,_1a,key,_25]); |
247 |
} |
248 |
for(i=0,_1e;_1e=_22[i];i++){ |
249 |
if(_1e.nodeType==1){ |
250 |
var _28=_1e.getAttribute("dtlinstruction"); |
251 |
if(_28){
|
252 |
_1e.parentNode.removeChild(_1e); |
253 |
_1e={nodeType:8,data:_28}; |
254 |
} |
255 |
} |
256 |
this.__tokenize(_1e,_1b);
|
257 |
} |
258 |
if(!_1c&&_1a.parentNode&&_1a.parentNode.tagName){
|
259 |
if(_23){
|
260 |
_1b.push([dd.TOKEN_CHANGE,_1a,true]);
|
261 |
} |
262 |
_1b.push([dd.TOKEN_CHANGE,_1a.parentNode]); |
263 |
_1a.parentNode.removeChild(_1a); |
264 |
}else{
|
265 |
_1b.push([dd.TOKEN_CHANGE,_1a,true,true]); |
266 |
} |
267 |
},__tokenize:function(_29,_2a){ |
268 |
var _2b=_29.data;
|
269 |
switch(_29.nodeType){
|
270 |
case 1: |
271 |
this._tokenize(_29,_2a);
|
272 |
return;
|
273 |
case 3: |
274 |
if(_2b.match(/[^\s\n]/)&&(_2b.indexOf("{{")!=-1||_2b.indexOf("{%")!=-1)){ |
275 |
var _2c=_1.tokenize(_2b);
|
276 |
for(var j=0,_2d;_2d=_2c[j];j++){ |
277 |
if(typeof _2d=="string"){ |
278 |
_2a.push([dd.TOKEN_TEXT,_2d]); |
279 |
}else{
|
280 |
_2a.push(_2d); |
281 |
} |
282 |
} |
283 |
}else{
|
284 |
_2a.push([_29.nodeType,_29]); |
285 |
} |
286 |
if(_29.parentNode){
|
287 |
_29.parentNode.removeChild(_29); |
288 |
} |
289 |
return;
|
290 |
case 8: |
291 |
if(_2b.indexOf("{%")==0){ |
292 |
var _2d=dojo.trim(_2b.slice(2,-2)); |
293 |
if(_2d.substr(0,5)=="load "){ |
294 |
var _2e=dojo.trim(_2d).split(/\s+/g); |
295 |
for(var i=1,_2f;_2f=_2e[i];i++){ |
296 |
dojo["require"](_2f);
|
297 |
} |
298 |
} |
299 |
_2a.push([dd.TOKEN_BLOCK,_2d]); |
300 |
} |
301 |
if(_2b.indexOf("{{")==0){ |
302 |
_2a.push([dd.TOKEN_VAR,dojo.trim(_2b.slice(2,-2))]); |
303 |
} |
304 |
if(_29.parentNode){
|
305 |
_29.parentNode.removeChild(_29); |
306 |
} |
307 |
return;
|
308 |
} |
309 |
}}; |
310 |
dd.DomTemplate=dojo.extend(function(obj){
|
311 |
if(!obj.nodes){
|
312 |
var _30=dojo.byId(obj);
|
313 |
if(_30&&_30.nodeType==1){ |
314 |
dojo.forEach(["class","src","href","name","value"],function(_31){ |
315 |
_2._attributes[_31]=true;
|
316 |
}); |
317 |
obj={nodes:[_30]};
|
318 |
}else{
|
319 |
if(typeof obj=="object"){ |
320 |
obj=_1.getTemplateString(obj); |
321 |
} |
322 |
obj=_2.getTemplate(obj); |
323 |
} |
324 |
} |
325 |
var _32=_2.tokenize(obj.nodes);
|
326 |
if(dd.tests){
|
327 |
this.tokens=_32.slice(0); |
328 |
} |
329 |
var _33=new dd._DomParser(_32); |
330 |
this.nodelist=_33.parse();
|
331 |
},{_count:0,_re:/\bdojo:([a-zA-Z0-9_]+)\b/g,setClass:function(str){ |
332 |
this.getRootNode().className=str;
|
333 |
},getRootNode:function(){ |
334 |
return this.buffer.rootNode; |
335 |
},getBuffer:function(){ |
336 |
return new dd.DomBuffer(); |
337 |
},render:function(_34,_35){ |
338 |
_35=this.buffer=_35||this.getBuffer(); |
339 |
this.rootNode=null; |
340 |
var _36=this.nodelist.render(_34||new dd.Context({}),_35); |
341 |
for(var i=0,_37;_37=_35._cache[i];i++){ |
342 |
if(_37._cache){
|
343 |
_37._cache.length=0;
|
344 |
} |
345 |
} |
346 |
return _36;
|
347 |
},unrender:function(_38,_39){ |
348 |
return this.nodelist.unrender(_38,_39); |
349 |
}}); |
350 |
dd.DomBuffer=dojo.extend(function(_3a){
|
351 |
this._parent=_3a;
|
352 |
this._cache=[];
|
353 |
},{concat:function(_3b){ |
354 |
var _3c=this._parent; |
355 |
if(_3c&&_3b.parentNode&&_3b.parentNode===_3c&&!_3c._dirty){
|
356 |
return this; |
357 |
} |
358 |
if(_3b.nodeType==1&&!this.rootNode){ |
359 |
this.rootNode=_3b||true; |
360 |
return this; |
361 |
} |
362 |
if(!_3c){
|
363 |
if(_3b.nodeType==3&&dojo.trim(_3b.data)){ |
364 |
throw new Error("Text should not exist outside of the root node in template"); |
365 |
} |
366 |
return this; |
367 |
} |
368 |
if(this._closed){ |
369 |
if(_3b.nodeType==3&&!dojo.trim(_3b.data)){ |
370 |
return this; |
371 |
}else{
|
372 |
throw new Error("Content should not exist outside of the root node in template"); |
373 |
} |
374 |
} |
375 |
if(_3c._dirty){
|
376 |
if(_3b._drawn&&_3b.parentNode==_3c){
|
377 |
var _3d=_3c._cache;
|
378 |
if(_3d){
|
379 |
for(var i=0,_3e;_3e=_3d[i];i++){ |
380 |
this.onAddNode&&this.onAddNode(_3e); |
381 |
_3c.insertBefore(_3e,_3b); |
382 |
this.onAddNodeComplete&&this.onAddNodeComplete(_3e); |
383 |
} |
384 |
_3d.length=0;
|
385 |
} |
386 |
} |
387 |
_3c._dirty=false;
|
388 |
} |
389 |
if(!_3c._cache){
|
390 |
_3c._cache=[]; |
391 |
this._cache.push(_3c);
|
392 |
} |
393 |
_3c._dirty=true;
|
394 |
_3c._cache.push(_3b); |
395 |
return this; |
396 |
},remove:function(obj){ |
397 |
if(typeof obj=="string"){ |
398 |
if(this._parent){ |
399 |
this._parent.removeAttribute(obj);
|
400 |
} |
401 |
}else{
|
402 |
if(obj.nodeType==1&&!this.getRootNode()&&!this._removed){ |
403 |
this._removed=true; |
404 |
return this; |
405 |
} |
406 |
if(obj.parentNode){
|
407 |
this.onRemoveNode&&this.onRemoveNode(obj); |
408 |
if(obj.parentNode){
|
409 |
obj.parentNode.removeChild(obj); |
410 |
} |
411 |
} |
412 |
} |
413 |
return this; |
414 |
},setAttribute:function(key,_3f){ |
415 |
var old=dojo.attr(this._parent,key); |
416 |
if(this.onChangeAttribute&&old!=_3f){ |
417 |
this.onChangeAttribute(this._parent,key,old,_3f); |
418 |
} |
419 |
if(key=="style"){ |
420 |
this._parent.style.cssText=_3f;
|
421 |
}else{
|
422 |
dojo.attr(this._parent,key,_3f);
|
423 |
} |
424 |
return this; |
425 |
},addEvent:function(_40,_41,fn,_42){ |
426 |
if(!_40.getThis()){
|
427 |
throw new Error("You must use Context.setObject(instance)"); |
428 |
} |
429 |
this.onAddEvent&&this.onAddEvent(this.getParent(),_41,fn); |
430 |
var _43=fn;
|
431 |
if(dojo.isArray(_42)){
|
432 |
_43=function(e){ |
433 |
this[fn].apply(this,[e].concat(_42)); |
434 |
}; |
435 |
} |
436 |
return dojo.connect(this.getParent(),_41,_40.getThis(),_43); |
437 |
},setParent:function(_44,up,_45){ |
438 |
if(!this._parent){ |
439 |
this._parent=this._first=_44; |
440 |
} |
441 |
if(up&&_45&&_44===this._first){ |
442 |
this._closed=true; |
443 |
} |
444 |
if(up){
|
445 |
var _46=this._parent; |
446 |
var _47=""; |
447 |
var ie=dojo.isIE&&_46.tagName=="SCRIPT"; |
448 |
if(ie){
|
449 |
_46.text="";
|
450 |
} |
451 |
if(_46._dirty){
|
452 |
var _48=_46._cache;
|
453 |
var _49=(_46.tagName=="SELECT"&&!_46.options.length); |
454 |
for(var i=0,_4a;_4a=_48[i];i++){ |
455 |
if(_4a!==_46){
|
456 |
this.onAddNode&&this.onAddNode(_4a); |
457 |
if(ie){
|
458 |
_47+=_4a.data; |
459 |
}else{
|
460 |
_46.appendChild(_4a); |
461 |
if(_49&&_4a.defaultSelected&&i){
|
462 |
_49=i; |
463 |
} |
464 |
} |
465 |
this.onAddNodeComplete&&this.onAddNodeComplete(_4a); |
466 |
} |
467 |
} |
468 |
if(_49){
|
469 |
_46.options.selectedIndex=(typeof _49=="number")?_49:0; |
470 |
} |
471 |
_48.length=0;
|
472 |
_46._dirty=false;
|
473 |
} |
474 |
if(ie){
|
475 |
_46.text=_47; |
476 |
} |
477 |
} |
478 |
this._parent=_44;
|
479 |
this.onSetParent&&this.onSetParent(_44,up,_45); |
480 |
return this; |
481 |
},getParent:function(){ |
482 |
return this._parent; |
483 |
},getRootNode:function(){ |
484 |
return this.rootNode; |
485 |
}}); |
486 |
dd._DomNode=dojo.extend(function(_4b){
|
487 |
this.contents=_4b;
|
488 |
},{render:function(_4c,_4d){ |
489 |
this._rendered=true; |
490 |
return _4d.concat(this.contents); |
491 |
},unrender:function(_4e,_4f){ |
492 |
if(!this._rendered){ |
493 |
return _4f;
|
494 |
} |
495 |
this._rendered=false; |
496 |
return _4f.remove(this.contents); |
497 |
},clone:function(_50){ |
498 |
return new this.constructor(this.contents); |
499 |
}}); |
500 |
dd._DomNodeList=dojo.extend(function(_51){
|
501 |
this.contents=_51||[];
|
502 |
},{push:function(_52){ |
503 |
this.contents.push(_52);
|
504 |
},unshift:function(_53){ |
505 |
this.contents.unshift(_53);
|
506 |
},render:function(_54,_55,_56){ |
507 |
_55=_55||dd.DomTemplate.prototype.getBuffer(); |
508 |
if(_56){
|
509 |
var _57=_55.getParent();
|
510 |
} |
511 |
for(var i=0;i<this.contents.length;i++){ |
512 |
_55=this.contents[i].render(_54,_55);
|
513 |
if(!_55){
|
514 |
throw new Error("Template node render functions must return their buffer"); |
515 |
} |
516 |
} |
517 |
if(_57){
|
518 |
_55.setParent(_57); |
519 |
} |
520 |
return _55;
|
521 |
},dummyRender:function(_58,_59,_5a){ |
522 |
var div=document.createElement("div"); |
523 |
var _5b=_59.getParent();
|
524 |
var old=_5b._clone;
|
525 |
_5b._clone=div; |
526 |
var _5c=this.clone(_59,div); |
527 |
if(old){
|
528 |
_5b._clone=old; |
529 |
}else{
|
530 |
_5b._clone=null;
|
531 |
} |
532 |
_59=dd.DomTemplate.prototype.getBuffer(); |
533 |
_5c.unshift(new dd.ChangeNode(div));
|
534 |
_5c.unshift(new dd._DomNode(div));
|
535 |
_5c.push(new dd.ChangeNode(div,true)); |
536 |
_5c.render(_58,_59); |
537 |
if(_5a){
|
538 |
return _59.getRootNode();
|
539 |
} |
540 |
var _5d=div.innerHTML;
|
541 |
return (dojo.isIE)?_5d.replace(/\s*_(dirty|clone)="[^"]*"/g,""):_5d; |
542 |
},unrender:function(_5e,_5f,_60){ |
543 |
if(_60){
|
544 |
var _61=_5f.getParent();
|
545 |
} |
546 |
for(var i=0;i<this.contents.length;i++){ |
547 |
_5f=this.contents[i].unrender(_5e,_5f);
|
548 |
if(!_5f){
|
549 |
throw new Error("Template node render functions must return their buffer"); |
550 |
} |
551 |
} |
552 |
if(_61){
|
553 |
_5f.setParent(_61); |
554 |
} |
555 |
return _5f;
|
556 |
},clone:function(_62){ |
557 |
var _63=_62.getParent();
|
558 |
var _64=this.contents; |
559 |
var _65=new dd._DomNodeList(); |
560 |
var _66=[];
|
561 |
for(var i=0;i<_64.length;i++){ |
562 |
var _67=_64[i].clone(_62);
|
563 |
if(_67 instanceof dd.ChangeNode||_67 instanceof dd._DomNode){ |
564 |
var _68=_67.contents._clone;
|
565 |
if(_68){
|
566 |
_67.contents=_68; |
567 |
}else{
|
568 |
if(_63!=_67.contents&&_67 instanceof dd._DomNode){ |
569 |
var _69=_67.contents;
|
570 |
_67.contents=_67.contents.cloneNode(false);
|
571 |
_62.onClone&&_62.onClone(_69,_67.contents); |
572 |
_66.push(_69); |
573 |
_69._clone=_67.contents; |
574 |
} |
575 |
} |
576 |
} |
577 |
_65.push(_67); |
578 |
} |
579 |
for(var i=0,_67;_67=_66[i];i++){ |
580 |
_67._clone=null;
|
581 |
} |
582 |
return _65;
|
583 |
},rtrim:function(){ |
584 |
while(1){ |
585 |
var i=this.contents.length-1; |
586 |
if(this.contents[i] instanceof dd._DomTextNode&&this.contents[i].isEmpty()){ |
587 |
this.contents.pop();
|
588 |
}else{
|
589 |
break;
|
590 |
} |
591 |
} |
592 |
return this; |
593 |
}}); |
594 |
dd._DomVarNode=dojo.extend(function(str){
|
595 |
this.contents=new dd._Filter(str); |
596 |
},{render:function(_6a,_6b){ |
597 |
var str=this.contents.resolve(_6a); |
598 |
var _6c="text"; |
599 |
if(str){
|
600 |
if(str.render&&str.getRootNode){
|
601 |
_6c="injection";
|
602 |
}else{
|
603 |
if(str.safe){
|
604 |
if(str.nodeType){
|
605 |
_6c="node";
|
606 |
}else{
|
607 |
if(str.toString){
|
608 |
str=str.toString(); |
609 |
_6c="html";
|
610 |
} |
611 |
} |
612 |
} |
613 |
} |
614 |
} |
615 |
if(this._type&&_6c!=this._type){ |
616 |
this.unrender(_6a,_6b);
|
617 |
} |
618 |
this._type=_6c;
|
619 |
switch(_6c){
|
620 |
case "text": |
621 |
this._rendered=true; |
622 |
this._txt=this._txt||document.createTextNode(str); |
623 |
if(this._txt.data!=str){ |
624 |
var old=this._txt.data; |
625 |
this._txt.data=str;
|
626 |
_6b.onChangeData&&_6b.onChangeData(this._txt,old,this._txt.data); |
627 |
} |
628 |
return _6b.concat(this._txt); |
629 |
case "injection": |
630 |
var _6d=str.getRootNode();
|
631 |
if(this._rendered&&_6d!=this._root){ |
632 |
_6b=this.unrender(_6a,_6b);
|
633 |
} |
634 |
this._root=_6d;
|
635 |
var _6e=this._injected=new dd._DomNodeList(); |
636 |
_6e.push(new dd.ChangeNode(_6b.getParent()));
|
637 |
_6e.push(new dd._DomNode(_6d));
|
638 |
_6e.push(str); |
639 |
_6e.push(new dd.ChangeNode(_6b.getParent()));
|
640 |
this._rendered=true; |
641 |
return _6e.render(_6a,_6b);
|
642 |
case "node": |
643 |
this._rendered=true; |
644 |
if(this._node&&this._node!=str&&this._node.parentNode&&this._node.parentNode===_6b.getParent()){ |
645 |
this._node.parentNode.removeChild(this._node); |
646 |
} |
647 |
this._node=str;
|
648 |
return _6b.concat(str);
|
649 |
case "html": |
650 |
if(this._rendered&&this._src!=str){ |
651 |
_6b=this.unrender(_6a,_6b);
|
652 |
} |
653 |
this._src=str;
|
654 |
if(!this._rendered){ |
655 |
this._rendered=true; |
656 |
this._html=this._html||[]; |
657 |
var div=(this._div=this._div||document.createElement("div")); |
658 |
div.innerHTML=str; |
659 |
var _6f=div.childNodes;
|
660 |
while(_6f.length){
|
661 |
var _70=div.removeChild(_6f[0]); |
662 |
this._html.push(_70);
|
663 |
_6b=_6b.concat(_70); |
664 |
} |
665 |
} |
666 |
return _6b;
|
667 |
default:
|
668 |
return _6b;
|
669 |
} |
670 |
},unrender:function(_71,_72){ |
671 |
if(!this._rendered){ |
672 |
return _72;
|
673 |
} |
674 |
this._rendered=false; |
675 |
switch(this._type){ |
676 |
case "text": |
677 |
return _72.remove(this._txt); |
678 |
case "injection": |
679 |
return this._injection.unrender(_71,_72); |
680 |
case "node": |
681 |
if(this._node.parentNode===_72.getParent()){ |
682 |
return _72.remove(this._node); |
683 |
} |
684 |
return _72;
|
685 |
case "html": |
686 |
for(var i=0,l=this._html.length;i<l;i++){ |
687 |
_72=_72.remove(this._html[i]);
|
688 |
} |
689 |
return _72;
|
690 |
default:
|
691 |
return _72;
|
692 |
} |
693 |
},clone:function(){ |
694 |
return new this.constructor(this.contents.getExpression()); |
695 |
}}); |
696 |
dd.ChangeNode=dojo.extend(function(_73,up,_74){
|
697 |
this.contents=_73;
|
698 |
this.up=up;
|
699 |
this.root=_74;
|
700 |
},{render:function(_75,_76){ |
701 |
return _76.setParent(this.contents,this.up,this.root); |
702 |
},unrender:function(_77,_78){ |
703 |
if(!_78.getParent()){
|
704 |
return _78;
|
705 |
} |
706 |
return _78.setParent(this.contents); |
707 |
},clone:function(){ |
708 |
return new this.constructor(this.contents,this.up,this.root); |
709 |
}}); |
710 |
dd.AttributeNode=dojo.extend(function(key,_79){
|
711 |
this.key=key;
|
712 |
this.value=_79;
|
713 |
this.contents=_79;
|
714 |
if(this._pool[_79]){ |
715 |
this.nodelist=this._pool[_79]; |
716 |
}else{
|
717 |
if(!(this.nodelist=dd.quickFilter(_79))){ |
718 |
this.nodelist=(new dd.Template(_79,true)).nodelist; |
719 |
} |
720 |
this._pool[_79]=this.nodelist; |
721 |
} |
722 |
this.contents=""; |
723 |
},{_pool:{},render:function(_7a,_7b){ |
724 |
var key=this.key; |
725 |
var _7c=this.nodelist.dummyRender(_7a); |
726 |
if(dd.BOOLS[key]){
|
727 |
_7c=!(_7c=="false"||_7c=="undefined"||!_7c); |
728 |
} |
729 |
if(_7c!==this.contents){ |
730 |
this.contents=_7c;
|
731 |
return _7b.setAttribute(key,_7c);
|
732 |
} |
733 |
return _7b;
|
734 |
},unrender:function(_7d,_7e){ |
735 |
this.contents=""; |
736 |
return _7e.remove(this.key); |
737 |
},clone:function(_7f){ |
738 |
return new this.constructor(this.key,this.value); |
739 |
}}); |
740 |
dd._DomTextNode=dojo.extend(function(str){
|
741 |
this.contents=document.createTextNode(str);
|
742 |
this.upcoming=str;
|
743 |
},{set:function(_80){ |
744 |
this.upcoming=_80;
|
745 |
return this; |
746 |
},render:function(_81,_82){ |
747 |
if(this.contents.data!=this.upcoming){ |
748 |
var old=this.contents.data; |
749 |
this.contents.data=this.upcoming; |
750 |
_82.onChangeData&&_82.onChangeData(this.contents,old,this.upcoming); |
751 |
} |
752 |
return _82.concat(this.contents); |
753 |
},unrender:function(_83,_84){ |
754 |
return _84.remove(this.contents); |
755 |
},isEmpty:function(){ |
756 |
return !dojo.trim(this.contents.data); |
757 |
},clone:function(){ |
758 |
return new this.constructor(this.contents.data); |
759 |
}}); |
760 |
dd._DomParser=dojo.extend(function(_85){
|
761 |
this.contents=_85;
|
762 |
},{i:0,parse:function(_86){ |
763 |
var _87={};
|
764 |
var _88=this.contents; |
765 |
if(!_86){
|
766 |
_86=[]; |
767 |
} |
768 |
for(var i=0;i<_86.length;i++){ |
769 |
_87[_86[i]]=true;
|
770 |
} |
771 |
var _89=new dd._DomNodeList(); |
772 |
while(this.i<_88.length){ |
773 |
var _8a=_88[this.i++]; |
774 |
var _8b=_8a[0]; |
775 |
var _8c=_8a[1]; |
776 |
if(_8b==dd.TOKEN_CUSTOM){
|
777 |
_89.push(_8c); |
778 |
}else{
|
779 |
if(_8b==dd.TOKEN_CHANGE){
|
780 |
var _8d=new dd.ChangeNode(_8c,_8a[2],_8a[3]); |
781 |
_8c[_8d.attr]=_8d; |
782 |
_89.push(_8d); |
783 |
}else{
|
784 |
if(_8b==dd.TOKEN_ATTR){
|
785 |
var fn=_1.getTag("attr:"+_8a[2],true); |
786 |
if(fn&&_8a[3]){ |
787 |
if(_8a[3].indexOf("{%")!=-1||_8a[3].indexOf("{{")!=-1){ |
788 |
_8c.setAttribute(_8a[2],""); |
789 |
} |
790 |
_89.push(fn(null,new dd.Token(_8b,_8a[2]+" "+_8a[3]))); |
791 |
}else{
|
792 |
if(dojo.isString(_8a[3])){ |
793 |
if(_8a[2]=="style"||_8a[3].indexOf("{%")!=-1||_8a[3].indexOf("{{")!=-1){ |
794 |
_89.push(new dd.AttributeNode(_8a[2],_8a[3])); |
795 |
}else{
|
796 |
if(dojo.trim(_8a[3])){ |
797 |
try{
|
798 |
dojo.attr(_8c,_8a[2],_8a[3]); |
799 |
} |
800 |
catch(e){
|
801 |
} |
802 |
} |
803 |
} |
804 |
} |
805 |
} |
806 |
}else{
|
807 |
if(_8b==dd.TOKEN_NODE){
|
808 |
var fn=_1.getTag("node:"+_8c.tagName.toLowerCase(),true); |
809 |
if(fn){
|
810 |
_89.push(fn(null,new dd.Token(_8b,_8c),_8c.tagName.toLowerCase())); |
811 |
} |
812 |
_89.push(new dd._DomNode(_8c));
|
813 |
}else{
|
814 |
if(_8b==dd.TOKEN_VAR){
|
815 |
_89.push(new dd._DomVarNode(_8c));
|
816 |
}else{
|
817 |
if(_8b==dd.TOKEN_TEXT){
|
818 |
_89.push(new dd._DomTextNode(_8c.data||_8c));
|
819 |
}else{
|
820 |
if(_8b==dd.TOKEN_BLOCK){
|
821 |
if(_87[_8c]){
|
822 |
--this.i;
|
823 |
return _89;
|
824 |
} |
825 |
var cmd=_8c.split(/\s+/g); |
826 |
if(cmd.length){
|
827 |
cmd=cmd[0];
|
828 |
var fn=_1.getTag(cmd);
|
829 |
if(typeof fn!="function"){ |
830 |
throw new Error("Function not found for "+cmd); |
831 |
} |
832 |
var tpl=fn(this,new dd.Token(_8b,_8c)); |
833 |
if(tpl){
|
834 |
_89.push(tpl); |
835 |
} |
836 |
} |
837 |
} |
838 |
} |
839 |
} |
840 |
} |
841 |
} |
842 |
} |
843 |
} |
844 |
} |
845 |
if(_86.length){
|
846 |
throw new Error("Could not find closing tag(s): "+_86.toString()); |
847 |
} |
848 |
return _89;
|
849 |
},next_token:function(){ |
850 |
var _8e=this.contents[this.i++]; |
851 |
return new dd.Token(_8e[0],_8e[1]); |
852 |
},delete_first_token:function(){ |
853 |
this.i++;
|
854 |
},skip_past:function(_8f){ |
855 |
return dd._Parser.prototype.skip_past.call(this,_8f); |
856 |
},create_variable_node:function(_90){ |
857 |
return new dd._DomVarNode(_90); |
858 |
},create_text_node:function(_91){ |
859 |
return new dd._DomTextNode(_91||""); |
860 |
},getTemplate:function(loc){ |
861 |
return new dd.DomTemplate(_2.getTemplate(loc)); |
862 |
}}); |
863 |
})(); |
864 |
} |