root / trunk / web / dojo / dojox / fx / text.js @ 12
History | View | Annotate | Download (7.22 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.fx.text"]){ |
9 |
dojo._hasResource["dojox.fx.text"]=true; |
10 |
dojo.provide("dojox.fx.text");
|
11 |
dojo.require("dojo.fx");
|
12 |
dojo.require("dojo.fx.easing");
|
13 |
dojox.fx.text._split=function(_1){ |
14 |
var _2=_1.node=dojo.byId(_1.node),s=_2.style,cs=dojo.getComputedStyle(_2),_3=dojo.coords(_2,true); |
15 |
_1.duration=_1.duration||1000;
|
16 |
_1.words=_1.words||false;
|
17 |
var _4=(_1.text&&typeof (_1.text)=="string")?_1.text:_2.innerHTML,_5=s.height,_6=s.width,_7=[]; |
18 |
dojo.style(_2,{height:cs.height,width:cs.width}); |
19 |
var _8=/(<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>)/g; |
20 |
var _9=(_1.words?/(<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>)\s*|([^\s<]+\s*)/g:/(<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>)\s*|([^\s<]\s*)/g); |
21 |
var _a=(typeof _1.text=="string")?_1.text.match(_9):_2.innerHTML.match(_9); |
22 |
var _b=""; |
23 |
var _c=0; |
24 |
var _d=0; |
25 |
for(var i=0;i<_a.length;i++){ |
26 |
var _e=_a[i];
|
27 |
if(!_e.match(_8)){
|
28 |
_b+="<span>"+_e+"</span>"; |
29 |
_c++; |
30 |
}else{
|
31 |
_b+=_e; |
32 |
} |
33 |
} |
34 |
_2.innerHTML=_b; |
35 |
function _f(_10){ |
36 |
var _11=_10.nextSibling;
|
37 |
if(_10.tagName=="SPAN"&&_10.childNodes.length==1&&_10.firstChild.nodeType==3){ |
38 |
var _12=dojo.coords(_10,true); |
39 |
_d++; |
40 |
dojo.style(_10,{padding:0,margin:0,top:(_1.crop?"0px":_12.t+"px"),left:(_1.crop?"0px":_12.l+"px"),display:"inline"}); |
41 |
var _13=_1.pieceAnimation(_10,_12,_3,_d,_c);
|
42 |
if(dojo.isArray(_13)){
|
43 |
_7=_7.concat(_13); |
44 |
}else{
|
45 |
_7[_7.length]=_13; |
46 |
} |
47 |
}else{
|
48 |
if(_10.firstChild){
|
49 |
_f(_10.firstChild); |
50 |
} |
51 |
} |
52 |
if(_11){
|
53 |
_f(_11); |
54 |
} |
55 |
}; |
56 |
_f(_2.firstChild); |
57 |
var _14=dojo.fx.combine(_7);
|
58 |
dojo.connect(_14,"onEnd",_14,function(){ |
59 |
_2.innerHTML=_4; |
60 |
dojo.style(_2,{height:_5,width:_6}); |
61 |
}); |
62 |
if(_1.onPlay){
|
63 |
dojo.connect(_14,"onPlay",_14,_1.onPlay);
|
64 |
} |
65 |
if(_1.onEnd){
|
66 |
dojo.connect(_14,"onEnd",_14,_1.onEnd);
|
67 |
} |
68 |
return _14;
|
69 |
}; |
70 |
dojox.fx.text.explode=function(_15){ |
71 |
var _16=_15.node=dojo.byId(_15.node);
|
72 |
var s=_16.style;
|
73 |
_15.distance=_15.distance||1;
|
74 |
_15.duration=_15.duration||1000;
|
75 |
_15.random=_15.random||0;
|
76 |
if(typeof (_15.fade)=="undefined"){ |
77 |
_15.fade=true;
|
78 |
} |
79 |
if(typeof (_15.sync)=="undefined"){ |
80 |
_15.sync=true;
|
81 |
} |
82 |
_15.random=Math.abs(_15.random); |
83 |
_15.pieceAnimation=function(_17,_18,_19,_1a,_1b){ |
84 |
var _1c=_18.h;
|
85 |
var _1d=_18.w;
|
86 |
var _1e=_15.distance*2; |
87 |
var _1f=_15.duration;
|
88 |
var _20=parseFloat(_17.style.top);
|
89 |
var _21=parseFloat(_17.style.left);
|
90 |
var _22=0; |
91 |
var _23=0; |
92 |
var _24=0; |
93 |
if(_15.random){
|
94 |
var _25=(Math.random()*_15.random)+Math.max(1-_15.random,0); |
95 |
_1e*=_25; |
96 |
_1f*=_25; |
97 |
_22=((_15.unhide&&_15.sync)||(!_15.unhide&&!_15.sync))?(_15.duration-_1f):0;
|
98 |
_23=Math.random()-0.5;
|
99 |
_24=Math.random()-0.5;
|
100 |
} |
101 |
var _26=((_19.h-_1c)/2-(_18.y-_19.y)); |
102 |
var _27=((_19.w-_1d)/2-(_18.x-_19.x)); |
103 |
var _28=Math.sqrt(Math.pow(_27,2)+Math.pow(_26,2)); |
104 |
var _29=_20-_26*_1e+_28*_24;
|
105 |
var _2a=_21-_27*_1e+_28*_23;
|
106 |
var _2b=dojo.animateProperty({node:_17,duration:_1f,delay:_22,easing:(_15.easing||(_15.unhide?dojo.fx.easing.sinOut:dojo.fx.easing.circOut)),beforeBegin:(_15.unhide?function(){ |
107 |
if(_15.fade){
|
108 |
dojo.style(_17,"opacity",0); |
109 |
} |
110 |
_17.style.position=_15.crop?"relative":"absolute"; |
111 |
_17.style.top=_29+"px";
|
112 |
_17.style.left=_2a+"px";
|
113 |
}:function(){
|
114 |
_17.style.position=_15.crop?"relative":"absolute"; |
115 |
}),properties:{top:(_15.unhide?{start:_29,end:_20}:{start:_20,end:_29}),left:(_15.unhide?{start:_2a,end:_21}:{start:_21,end:_2a})}}); |
116 |
if(_15.fade){
|
117 |
var _2c=dojo.animateProperty({node:_17,duration:_1f,delay:_22,easing:(_15.fadeEasing||dojo.fx.easing.quadOut),properties:{opacity:(_15.unhide?{start:0,end:1}:{end:0})}}); |
118 |
return (_15.unhide?[_2c,_2b]:[_2b,_2c]);
|
119 |
}else{
|
120 |
return _2b;
|
121 |
} |
122 |
}; |
123 |
var _2d=dojox.fx.text._split(_15);
|
124 |
return _2d;
|
125 |
}; |
126 |
dojox.fx.text.converge=function(_2e){ |
127 |
_2e.unhide=true;
|
128 |
return dojox.fx.text.explode(_2e);
|
129 |
}; |
130 |
dojox.fx.text.disintegrate=function(_2f){ |
131 |
var _30=_2f.node=dojo.byId(_2f.node);
|
132 |
var s=_30.style;
|
133 |
_2f.duration=_2f.duration||1500;
|
134 |
_2f.distance=_2f.distance||1.5;
|
135 |
_2f.random=_2f.random||0;
|
136 |
if(!_2f.fade){
|
137 |
_2f.fade=true;
|
138 |
} |
139 |
var _31=Math.abs(_2f.random);
|
140 |
_2f.pieceAnimation=function(_32,_33,_34,_35,_36){ |
141 |
var _37=_33.h;
|
142 |
var _38=_33.w;
|
143 |
var _39=_2f.interval||(_2f.duration/(1.5*_36)); |
144 |
var _3a=(_2f.duration-_36*_39);
|
145 |
var _3b=Math.random()*_36*_39;
|
146 |
var _3c=(_2f.reverseOrder||_2f.distance<0)?(_35*_39):((_36-_35)*_39); |
147 |
var _3d=_3b*_31+Math.max(1-_31,0)*_3c; |
148 |
var _3e={};
|
149 |
if(_2f.unhide){
|
150 |
_3e.top={start:(parseFloat(_32.style.top)-_34.h*_2f.distance),end:parseFloat(_32.style.top)}; |
151 |
if(_2f.fade){
|
152 |
_3e.opacity={start:0,end:1}; |
153 |
} |
154 |
}else{
|
155 |
_3e.top={end:(parseFloat(_32.style.top)+_34.h*_2f.distance)};
|
156 |
if(_2f.fade){
|
157 |
_3e.opacity={end:0}; |
158 |
} |
159 |
} |
160 |
var _3f=dojo.animateProperty({node:_32,duration:_3a,delay:_3d,easing:(_2f.easing||(_2f.unhide?dojo.fx.easing.sinIn:dojo.fx.easing.circIn)),properties:_3e,beforeBegin:(_2f.unhide?function(){ |
161 |
if(_2f.fade){
|
162 |
dojo.style(_32,"opacity",0); |
163 |
} |
164 |
_32.style.position=_2f.crop?"relative":"absolute"; |
165 |
_32.style.top=_3e.top.start+"px";
|
166 |
}:function(){
|
167 |
_32.style.position=_2f.crop?"relative":"absolute"; |
168 |
})}); |
169 |
return _3f;
|
170 |
}; |
171 |
var _40=dojox.fx.text._split(_2f);
|
172 |
return _40;
|
173 |
}; |
174 |
dojox.fx.text.build=function(_41){ |
175 |
_41.unhide=true;
|
176 |
return dojox.fx.text.disintegrate(_41);
|
177 |
}; |
178 |
dojox.fx.text.blockFadeOut=function(_42){ |
179 |
var _43=_42.node=dojo.byId(_42.node);
|
180 |
var s=_43.style;
|
181 |
_42.duration=_42.duration||1000;
|
182 |
_42.random=_42.random||0;
|
183 |
var _44=Math.abs(_42.random);
|
184 |
_42.pieceAnimation=function(_45,_46,_47,_48,_49){ |
185 |
var _4a=_42.interval||(_42.duration/(1.5*_49)); |
186 |
var _4b=(_42.duration-_49*_4a);
|
187 |
var _4c=Math.random()*_49*_4a;
|
188 |
var _4d=(_42.reverseOrder)?((_49-_48)*_4a):(_48*_4a);
|
189 |
var _4e=_4c*_44+Math.max(1-_44,0)*_4d; |
190 |
var _4f=dojo.animateProperty({node:_45,duration:_4b,delay:_4e,easing:(_42.easing||dojo.fx.easing.sinInOut),properties:{opacity:(_42.unhide?{start:0,end:1}:{end:0})},beforeBegin:(_42.unhide?function(){ |
191 |
dojo.style(_45,"opacity",0); |
192 |
}:undefined)});
|
193 |
return _4f;
|
194 |
}; |
195 |
var _50=dojox.fx.text._split(_42);
|
196 |
return _50;
|
197 |
}; |
198 |
dojox.fx.text.blockFadeIn=function(_51){ |
199 |
_51.unhide=true;
|
200 |
return dojox.fx.text.blockFadeOut(_51);
|
201 |
}; |
202 |
dojox.fx.text.backspace=function(_52){ |
203 |
var _53=_52.node=dojo.byId(_52.node);
|
204 |
var s=_53.style;
|
205 |
_52.words=false;
|
206 |
_52.duration=_52.duration||2000;
|
207 |
_52.random=_52.random||0;
|
208 |
var _54=Math.abs(_52.random);
|
209 |
var _55=10; |
210 |
_52.pieceAnimation=function(_56,_57,_58,_59,_5a){ |
211 |
var _5b=_52.interval||(_52.duration/(1.5*_5a)),_5c=("textContent" in _56)?_56.textContent:_56.innerText,_5d=_5c.match(/\s/g); |
212 |
if(typeof (_52.wordDelay)=="undefined"){ |
213 |
_52.wordDelay=_5b*2;
|
214 |
} |
215 |
if(!_52.unhide){
|
216 |
_55=(_5a-_59-1)*_5b;
|
217 |
} |
218 |
var _5e,_5f;
|
219 |
if(_52.fixed){
|
220 |
if(_52.unhide){
|
221 |
var _5e=function(){ |
222 |
dojo.style(_56,"opacity",0); |
223 |
}; |
224 |
} |
225 |
}else{
|
226 |
if(_52.unhide){
|
227 |
var _5e=function(){ |
228 |
_56.style.display="none";
|
229 |
}; |
230 |
var _5f=function(){ |
231 |
_56.style.display="inline";
|
232 |
}; |
233 |
}else{
|
234 |
var _5f=function(){ |
235 |
_56.style.display="none";
|
236 |
}; |
237 |
} |
238 |
} |
239 |
var _60=dojo.animateProperty({node:_56,duration:1,delay:_55,easing:(_52.easing||dojo.fx.easing.sinInOut),properties:{opacity:(_52.unhide?{start:0,end:1}:{end:0})},beforeBegin:_5e,onEnd:_5f}); |
240 |
if(_52.unhide){
|
241 |
var _61=Math.random()*_5c.length*_5b;
|
242 |
var _62=_61*_54/2+Math.max(1-_54/2,0)*_52.wordDelay; |
243 |
_55+=_61*_54+Math.max(1-_54,0)*_5b*_5c.length+(_62*(_5d&&_5c.lastIndexOf(_5d[_5d.length-1])==_5c.length-1)); |
244 |
} |
245 |
return _60;
|
246 |
}; |
247 |
var _63=dojox.fx.text._split(_52);
|
248 |
return _63;
|
249 |
}; |
250 |
dojox.fx.text.type=function(_64){ |
251 |
_64.unhide=true;
|
252 |
return dojox.fx.text.backspace(_64);
|
253 |
}; |
254 |
} |