root / trunk / web / dojo / dojox / fx / Timeline.js
History | View | Annotate | Download (2.78 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.fx.Timeline"]){ |
||
9 | dojo._hasResource["dojox.fx.Timeline"]=true; |
||
10 | dojo.provide("dojox.fx.Timeline");
|
||
11 | dojo.require("dojo.fx.easing");
|
||
12 | dojox.fx.animateTimeline=function(_1,_2){ |
||
13 | var _3=new dojox.fx._Timeline(_1.keys); |
||
14 | var _4=dojo.animateProperty({node:dojo.byId(_2||_1.node),duration:_1.duration||1000,properties:_3._properties,easing:dojo.fx.easing.linear,onAnimate:function(v){ |
||
15 | }}); |
||
16 | dojo.connect(_4,"onEnd",function(_5){ |
||
17 | var _6=_4.curve.getValue(_4.reversed?0:1); |
||
18 | dojo.style(_5,_6); |
||
19 | }); |
||
20 | dojo.connect(_4,"beforeBegin",function(){ |
||
21 | if(_4.curve){
|
||
22 | delete _4.curve;
|
||
23 | } |
||
24 | _4.curve=_3; |
||
25 | _3.ani=_4; |
||
26 | }); |
||
27 | return _4;
|
||
28 | }; |
||
29 | dojox.fx._Timeline=function(_7){ |
||
30 | this.keys=dojo.isArray(_7)?this.flatten(_7):_7; |
||
31 | }; |
||
32 | dojox.fx._Timeline.prototype.flatten=function(_8){ |
||
33 | var _9=function(_a,_b){ |
||
34 | if(_a=="from"){ |
||
35 | return 0; |
||
36 | } |
||
37 | if(_a=="to"){ |
||
38 | return 1; |
||
39 | } |
||
40 | if(_a===undefined){ |
||
41 | return _b==0?0:_b/(_8.length-1); |
||
42 | } |
||
43 | return parseInt(_a,10)*0.01; |
||
44 | }; |
||
45 | var p={},o={};
|
||
46 | dojo.forEach(_8,function(k,i){
|
||
47 | var _c=_9(k.step,i);
|
||
48 | var _d=dojo.fx.easing[k.ease]||dojo.fx.easing.linear;
|
||
49 | for(var nm in k){ |
||
50 | if(nm=="step"||nm=="ease"||nm=="from"||nm=="to"){ |
||
51 | continue;
|
||
52 | } |
||
53 | if(!o[nm]){
|
||
54 | o[nm]={steps:[],values:[],eases:[],ease:_d}; |
||
55 | p[nm]={}; |
||
56 | if(!/#/.test(k[nm])){ |
||
57 | p[nm].units=o[nm].units=/\D{1,}/.exec(k[nm]).join(""); |
||
58 | }else{
|
||
59 | p[nm].units=o[nm].units="isColor";
|
||
60 | } |
||
61 | } |
||
62 | o[nm].eases.push(dojo.fx.easing[k.ease||"linear"]);
|
||
63 | o[nm].steps.push(_c); |
||
64 | if(p[nm].units=="isColor"){ |
||
65 | o[nm].values.push(new dojo.Color(k[nm]));
|
||
66 | }else{
|
||
67 | o[nm].values.push(parseInt(/\d{1,}/.exec(k[nm]).join(""))); |
||
68 | } |
||
69 | if(p[nm].start===undefined){ |
||
70 | p[nm].start=o[nm].values[o[nm].values.length-1];
|
||
71 | }else{
|
||
72 | p[nm].end=o[nm].values[o[nm].values.length-1];
|
||
73 | } |
||
74 | } |
||
75 | }); |
||
76 | this._properties=p;
|
||
77 | return o;
|
||
78 | }; |
||
79 | dojox.fx._Timeline.prototype.getValue=function(p){ |
||
80 | p=this.ani._reversed?1-p:p; |
||
81 | var o={},_e=this; |
||
82 | var _f=function(nm,i){ |
||
83 | return _e._properties[nm].units!="isColor"?_e.keys[nm].values[i]+_e._properties[nm].units:_e.keys[nm].values[i].toCss(); |
||
84 | }; |
||
85 | for(var nm in this.keys){ |
||
86 | var k=this.keys[nm]; |
||
87 | for(var i=0;i<k.steps.length;i++){ |
||
88 | var _10=k.steps[i];
|
||
89 | var ns=k.steps[i+1]; |
||
90 | var _11=i<k.steps.length?true:false; |
||
91 | var _12=k.eases[i]||function(n){ |
||
92 | return n;
|
||
93 | }; |
||
94 | if(p==_10){
|
||
95 | o[nm]=_f(nm,i); |
||
96 | if(!_11||(_11&&this.ani._reversed)){ |
||
97 | break;
|
||
98 | } |
||
99 | }else{
|
||
100 | if(p>_10){
|
||
101 | if(_11&&p<k.steps[i+1]){ |
||
102 | var end=k.values[i+1]; |
||
103 | var beg=k.values[i];
|
||
104 | var seg=(1/(ns-_10))*(p-_10); |
||
105 | seg=_12(seg); |
||
106 | if(beg instanceof dojo.Color){ |
||
107 | o[nm]=dojo.blendColors(beg,end,seg).toCss(false);
|
||
108 | }else{
|
||
109 | var df=end-beg;
|
||
110 | o[nm]=beg+seg*df+this._properties[nm].units;
|
||
111 | } |
||
112 | break;
|
||
113 | }else{
|
||
114 | o[nm]=_f(nm,i); |
||
115 | } |
||
116 | }else{
|
||
117 | if((_11&&!this.ani._reversed)||(!_11&&this.ani._reversed)){ |
||
118 | o[nm]=_f(nm,i); |
||
119 | } |
||
120 | } |
||
121 | } |
||
122 | } |
||
123 | } |
||
124 | return o;
|
||
125 | }; |
||
126 | } |