root / trunk / web / dojo / dojox / dtl / contrib / dom.js @ 12
History | View | Annotate | Download (3.49 KB)
1 | 9 | andrej.cim | /*
|
---|---|---|---|
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.contrib.dom"]){ |
||
9 | dojo._hasResource["dojox.dtl.contrib.dom"]=true; |
||
10 | dojo.provide("dojox.dtl.contrib.dom");
|
||
11 | dojo.require("dojox.dtl.dom");
|
||
12 | (function(){
|
||
13 | var dd=dojox.dtl;
|
||
14 | var _1=dd.contrib.dom;
|
||
15 | var _2={render:function(){ |
||
16 | return this.contents; |
||
17 | }}; |
||
18 | _1.StyleNode=dojo.extend(function(_3){
|
||
19 | this.contents={};
|
||
20 | this._current={};
|
||
21 | this._styles=_3;
|
||
22 | for(var _4 in _3){ |
||
23 | if(_3[_4].indexOf("{{")!=-1){ |
||
24 | var _5=new dd.Template(_3[_4]); |
||
25 | }else{
|
||
26 | var _5=dojo.delegate(_2);
|
||
27 | _5.contents=_3[_4]; |
||
28 | } |
||
29 | this.contents[_4]=_5;
|
||
30 | } |
||
31 | },{render:function(_6,_7){ |
||
32 | for(var _8 in this.contents){ |
||
33 | var _9=this.contents[_8].render(_6); |
||
34 | if(this._current[_8]!=_9){ |
||
35 | dojo.style(_7.getParent(),_8,this._current[_8]=_9);
|
||
36 | } |
||
37 | } |
||
38 | return _7;
|
||
39 | },unrender:function(_a,_b){ |
||
40 | this._current={};
|
||
41 | return _b;
|
||
42 | },clone:function(_c){ |
||
43 | return new this.constructor(this._styles); |
||
44 | }}); |
||
45 | _1.BufferNode=dojo.extend(function(_d,_e){
|
||
46 | this.nodelist=_d;
|
||
47 | this.options=_e;
|
||
48 | },{_swap:function(_f,_10){ |
||
49 | if(!this.swapped&&this.parent.parentNode){ |
||
50 | if(_f=="node"){ |
||
51 | if((_10.nodeType==3&&!this.options.text)||(_10.nodeType==1&&!this.options.node)){ |
||
52 | return;
|
||
53 | } |
||
54 | }else{
|
||
55 | if(_f=="class"){ |
||
56 | if(_f!="class"){ |
||
57 | return;
|
||
58 | } |
||
59 | } |
||
60 | } |
||
61 | this.onAddNode&&dojo.disconnect(this.onAddNode); |
||
62 | this.onRemoveNode&&dojo.disconnect(this.onRemoveNode); |
||
63 | this.onChangeAttribute&&dojo.disconnect(this.onChangeAttribute); |
||
64 | this.onChangeData&&dojo.disconnect(this.onChangeData); |
||
65 | this.swapped=this.parent.cloneNode(true); |
||
66 | this.parent.parentNode.replaceChild(this.swapped,this.parent); |
||
67 | } |
||
68 | },render:function(_11,_12){ |
||
69 | this.parent=_12.getParent();
|
||
70 | if(this.options.node){ |
||
71 | this.onAddNode=dojo.connect(_12,"onAddNode",dojo.hitch(this,"_swap","node")); |
||
72 | this.onRemoveNode=dojo.connect(_12,"onRemoveNode",dojo.hitch(this,"_swap","node")); |
||
73 | } |
||
74 | if(this.options.text){ |
||
75 | this.onChangeData=dojo.connect(_12,"onChangeData",dojo.hitch(this,"_swap","node")); |
||
76 | } |
||
77 | if(this.options["class"]){ |
||
78 | this.onChangeAttribute=dojo.connect(_12,"onChangeAttribute",dojo.hitch(this,"_swap","class")); |
||
79 | } |
||
80 | _12=this.nodelist.render(_11,_12);
|
||
81 | if(this.swapped){ |
||
82 | this.swapped.parentNode.replaceChild(this.parent,this.swapped); |
||
83 | dojo.destroy(this.swapped);
|
||
84 | }else{
|
||
85 | this.onAddNode&&dojo.disconnect(this.onAddNode); |
||
86 | this.onRemoveNode&&dojo.disconnect(this.onRemoveNode); |
||
87 | this.onChangeAttribute&&dojo.disconnect(this.onChangeAttribute); |
||
88 | this.onChangeData&&dojo.disconnect(this.onChangeData); |
||
89 | } |
||
90 | delete this.parent; |
||
91 | delete this.swapped; |
||
92 | return _12;
|
||
93 | },unrender:function(_13,_14){ |
||
94 | return this.nodelist.unrender(_13,_14); |
||
95 | },clone:function(_15){ |
||
96 | return new this.constructor(this.nodelist.clone(_15),this.options); |
||
97 | }}); |
||
98 | dojo.mixin(_1,{buffer:function(_16,_17){ |
||
99 | var _18=_17.contents.split().slice(1); |
||
100 | var _19={};
|
||
101 | var _1a=false; |
||
102 | for(var i=_18.length;i--;){ |
||
103 | _1a=true;
|
||
104 | _19[_18[i]]=true;
|
||
105 | } |
||
106 | if(!_1a){
|
||
107 | _19.node=true;
|
||
108 | } |
||
109 | var _1b=_16.parse(["endbuffer"]); |
||
110 | _16.next_token(); |
||
111 | return new _1.BufferNode(_1b,_19); |
||
112 | },html:function(_1c,_1d){ |
||
113 | dojo.deprecated("{% html someVariable %}","Use {{ someVariable|safe }} instead"); |
||
114 | return _1c.create_variable_node(_1d.contents.slice(5)+"|safe"); |
||
115 | },style_:function(_1e,_1f){ |
||
116 | var _20={};
|
||
117 | _1f=_1f.contents.replace(/^style\s+/,""); |
||
118 | var _21=_1f.split(/\s*;\s*/g); |
||
119 | for(var i=0,_22;_22=_21[i];i++){ |
||
120 | var _23=_22.split(/\s*:\s*/g); |
||
121 | var key=_23[0]; |
||
122 | var _24=dojo.trim(_23[1]); |
||
123 | if(_24){
|
||
124 | _20[key]=_24; |
||
125 | } |
||
126 | } |
||
127 | return new _1.StyleNode(_20); |
||
128 | }}); |
||
129 | dd.register.tags("dojox.dtl.contrib",{"dom":["html","attr:style","buffer"]}); |
||
130 | })(); |
||
131 | } |