source: Dev/branches/rest-dojo-ui/client/dojox/css3/fx.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 5.0 KB
Line 
1define([
2        "dojo/_base/kernel",
3        "dojo/_base/connect",   // dojo.connect
4        "dojo/dom-style",       // dojo.style
5        "dojo/_base/fx",
6        "dojo/fx",
7        "dojo/_base/html",
8        "dojox/html/ext-dojo/style",
9        "dojox/fx/ext-dojo/complex"],
10function(lang,connectUtil,domStyle,baseFx,coreFx,htmlUtil,htmlStyleExt,complexFx){
11        var css3fx = lang.getObject("dojox.css3.fx", true);
12        /*===== css3fx = dojox.css3.fx =====*/
13       
14        return lang.mixin(css3fx, {
15                puff: function(args){
16                        // summary:
17                        //              Returns an animation that will do a "puff" effect on the given node
18                        //
19                        // description:
20                        //              Fades out an element and scales it to args.endScale
21                        //
22                        return coreFx.combine([baseFx.fadeOut(args),
23                                this.expand({
24                                        node: args.node,
25                                        endScale: args.endScale || 2
26                                })
27                        ]);
28                },
29
30                expand: function(args){
31                        // summary:
32                        //              Returns an animation that expands args.node
33                        //
34                        // description:
35                        //              Scales an element to args.endScale
36                        //
37                        return baseFx.animateProperty({
38                                node: args.node,
39                                properties: {
40                                        transform: { start: "scale(1)", end: "scale(" + [args.endScale || 3] + ")" }
41                                }
42                        });
43                },
44
45                shrink: function(args){
46                        // summary:
47                        //              Returns an animation that shrinks args.node
48                        //
49                        // description:
50                        //              Shrinks an element, same as expand({ node: node, endScale: .01 });
51                        //
52                        return this.expand({
53                                node: args.node,
54                                endScale: .01
55                        });
56                },
57
58                rotate: function(args){
59                        // summary:
60                        //              Returns an animation that rotates an element
61                        //
62                        // description:
63                        //              Rotates an element from args.startAngle to args.endAngle
64                        //
65                        return baseFx.animateProperty({
66                                node: args.node,
67                                duration: args.duration || 1000,
68                                properties: {
69                                        transform: { start: "rotate(" + (args.startAngle || "0deg") + ")", end: "rotate(" + (args.endAngle || "360deg") + ")" }
70                                }
71                        });
72                },
73
74                flip: function(args){
75                        // summary:
76                        //              Returns an animation that flips an element around his y axis
77                        //
78                        // description:
79                        //              Flips an element around his y axis. The default is a 360deg flip
80                        //              but it's possible to run a partial flip using args.whichAnims
81                        //
82                        // example:
83                        //      |       // half flip
84                        //      |       dojox.css3.fx.flip({
85                        //      |               node: domNode,
86                        //      |               whichAnim: [0, 1]
87                        //      |       }).play();
88                        //
89                        var anims = [],
90                                whichAnims = args.whichAnims || [0, 1, 2, 3],
91                                        direction = args.direction || 1,
92                                transforms = [
93                                        { start: "scale(1, 1) skew(0deg,0deg)", end: "scale(0, 1) skew(0," + (direction * 30) + "deg)" },
94                                        { start: "scale(0, 1) skew(0deg," + (direction * 30) + "deg)", end: "scale(-1, 1) skew(0deg,0deg)" },
95                                        { start: "scale(-1, 1) skew(0deg,0deg)", end: "scale(0, 1) skew(0deg," + (-direction * 30) + "deg)" },
96                                        { start: "scale(0, 1) skew(0deg," + (-direction * 30) + "deg)", end: "scale(1, 1) skew(0deg,0deg)" }
97                        ];
98                        for(var i = 0; i < whichAnims.length; i++){
99                                anims.push(baseFx.animateProperty(
100                                        lang.mixin({
101                                        node: args.node,
102                                        duration: args.duration || 600,
103                                        properties: {
104                                                transform: transforms[whichAnims[i]]
105                                        }}, args)
106                                ));
107                        }
108                        return coreFx.chain(anims);
109                },
110
111                bounce: function(args){
112                        // summary:
113                        //              Returns an animation that do a "bounce" effect on args.node
114                        //
115                        // description:
116                        //              Vertical bounce animation, the scaleX, scaleY deformation and the
117                        //              jump height (args.jumpHeight) can be specified
118                        //
119                        var anims = [],
120                                n = args.node,
121                                duration = args.duration || 1000,
122                                scaleX = args.scaleX || 1.2,
123                                scaleY = args.scaleY || .6,
124                                ds = htmlUtil.style,
125                                oldPos = ds(n, "position"),
126                                newPos = "absolute",
127                                oldTop = ds(n, "top"),
128                                combinedAnims = [],
129                                bTime = 0,
130                                round = Math.round,
131                                jumpHeight = args.jumpHeight || 70
132                        ;
133                        if(oldPos !== "absolute"){
134                                newPos = "relative";
135                        }
136                        var a1 = baseFx.animateProperty({
137                                node: n,
138                                duration: duration / 6,
139                                properties: {
140                                        transform: { start: "scale(1, 1)", end: "scale(" + scaleX + ", " + scaleY + ")" }
141                                }
142                        });
143                        connectUtil.connect(a1, "onBegin", function(){
144                                ds(n, {
145                                        transformOrigin: "50% 100%",
146                                        position: newPos
147                                });
148                        });
149                        anims.push(a1);
150                        var a2 = baseFx.animateProperty({
151                                node: n,
152                                duration: duration / 6,
153                                properties: {
154                                        transform: { end: "scale(1, 1)", start: "scale(" + scaleX + ", " + scaleY + ")" }
155                                }
156                        });
157                        combinedAnims.push(a2);
158                        combinedAnims.push(new baseFx.Animation(lang.mixin({
159                                curve: [],
160                                duration: duration / 3,
161                                delay: duration / 12,
162                                onBegin: function(){
163                                        bTime = (new Date).getTime();
164                                },
165                                onAnimate: function(){
166                                        var cTime = (new Date).getTime();
167                                        ds(n, {
168                                                top: parseInt(ds(n, "top")) - round(jumpHeight*((cTime-bTime)/this.duration)) + "px"
169                                        });
170                                        bTime = cTime;
171                                }
172                        }, args)));
173                        anims.push(coreFx.combine(combinedAnims));
174                        anims.push(baseFx.animateProperty(lang.mixin({
175                                duration: duration / 3,
176                                onEnd: function(){
177                                        ds(n, {
178                                                position: oldPos
179                                        });
180                                },
181                                properties:{
182                                        top: oldTop
183                                }
184                        }, args)));
185                        anims.push(a1);
186                        anims.push(a2);
187
188                        return coreFx.chain(anims);
189                }
190        });
191});
Note: See TracBrowser for help on using the repository browser.