source: Dev/trunk/src/client/dojox/fx/ext-dojo/reverse.js @ 532

Last change on this file since 532 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 2.7 KB
Line 
1define(["dojo/_base/fx",
2                "dojo/fx",
3                "dojo/_base/lang",
4                "dojo/fx/easing",
5                "dojox/fx"],
6        function(baseFx, coreFx, lang, easingUtil, dojoxFx){ //
7
8var reverseApi = {
9        // summary:
10        //              A dojo.Animation extension that enables an easy reversal.
11        // description:
12        //              To use, simply require dojox.fx.ext-dojo.reverse and a reverse()
13        //              method will be added to all dojo.Animations.
14        //              It can be used at any time during the animation. It does not
15        //              need to be called when it ends. It also reverses the easing -
16        //              if dojo.fx.easing.quadIn is used, dojo.fx.easing.quadOut will
17        //              be used when animating backwards.
18
19        _reversed: false,
20        reverse: function(/*Boolean*/keepPaused, /*Function ? */reverseEase){
21                // summary:
22                //              The key method added to an animation to enable reversal.
23                // keepPaused: Boolean
24                //              By default, calling reverse() will play the animation if
25                //              it was paused. Pass in true to keep it paused (will have
26                //              no effect if reverse is called while animation is playing).
27                // reverseEase: Function
28                //              A function to use for the reverse easing. This allows for
29                //              the possibility of custom eases that are not in the dojo.fx
30                //              library.
31
32                var playing = this.status() == "playing";
33                this.pause();
34                this._reversed = !this._reversed;
35                var d = this.duration,
36                        sofar = d * this._percent,
37                        togo = d - sofar,
38                        curr = new Date().valueOf(),
39                        cp = this.curve._properties,
40                        p = this.properties,
41                        nm
42                ;
43                this._endTime = curr + sofar;
44                this._startTime = curr - togo;
45
46                if(playing){
47                        this.gotoPercent(togo / d)
48                }
49                for(nm in p){
50                        var tmp = p[nm].start;
51                        p[nm].start = cp[nm].start = p[nm].end;
52                        p[nm].end = cp[nm].end = tmp;
53                }
54
55                if(this._reversed){
56                        if(!this.rEase){
57                                this.fEase = this.easing;
58                                if(reverseEase){
59                                        this.rEase = reverseEase;
60                                }else{
61                                        // loop through dojo.fx.easing to find the matching ease
62                                        var de = easingUtil, found, eName;
63                                        for(nm in de){
64                                                if(this.easing == de[nm]){
65                                                        // get ease's name
66                                                        found = nm; break;
67                                                }
68                                        }
69
70                                        if(found){
71                                                // find ease's opposite
72                                                if(/InOut/.test(nm) || !/In|Out/i.test(nm)){
73                                                        this.rEase = this.easing;
74                                                }else if(/In/.test(nm)){
75                                                        eName = nm.replace("In", "Out");
76                                                }else{
77                                                        eName = nm.replace("Out", "In");
78                                                }
79                                                if(eName){
80                                                        this.rEase = easingUtil[eName];
81                                                }
82                                        }else{
83                                                // default ease, and other's like linear do not have an opposite
84                                                console.info("ease function to reverse not found");
85                                                this.rEase = this.easing;
86                                        }
87                                }
88
89                        }
90                        this.easing = this.rEase;
91                }else{
92                        this.easing = this.fEase;
93                }
94                if(!keepPaused && this.status() != "playing"){
95                        this.play();
96                }
97
98                return this;
99        }
100};
101lang.extend( baseFx.Animation, reverseApi);
102return baseFx.Animation;
103});
Note: See TracBrowser for help on using the repository browser.