]>
git.wh0rd.org - tt-rss.git/blob - lib/dojo/fx.js
2 Copyright (c) 2004-2011, 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
8 if(!dojo
._hasResource
["dojo.fx"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
9 dojo
._hasResource
["dojo.fx"] = true;
10 dojo
.provide("dojo.fx");
11 dojo
.require("dojo.fx.Toggler");
16 // summary: Effects library on top of Base animations
23 _fire: function(evt
, args
){
25 this[evt
].apply(this, args
||[]);
31 var _chain = function(animations
){
33 this._animations
= animations
||[];
34 this._current
= this._onAnimateCtx
= this._onEndCtx
= null;
37 d
.forEach(this._animations
, function(a
){
38 this.duration
+= a
.duration
;
39 if(a
.delay
){ this.duration
+= a
.delay
; }
43 _onAnimate: function(){
44 this._fire("onAnimate", arguments
);
47 d
.disconnect(this._onAnimateCtx
);
48 d
.disconnect(this._onEndCtx
);
49 this._onAnimateCtx
= this._onEndCtx
= null;
50 if(this._index
+ 1 == this._animations
.length
){
54 this._current
= this._animations
[++this._index
];
55 this._onAnimateCtx
= d
.connect(this._current
, "onAnimate", this, "_onAnimate");
56 this._onEndCtx
= d
.connect(this._current
, "onEnd", this, "_onEnd");
57 this._current
.play(0, true);
60 play: function(/*int?*/ delay
, /*Boolean?*/ gotoStart
){
61 if(!this._current
){ this._current
= this._animations
[this._index
= 0]; }
62 if(!gotoStart
&& this._current
.status() == "playing"){ return this; }
63 var beforeBegin
= d
.connect(this._current
, "beforeBegin", this, function(){
64 this._fire("beforeBegin");
66 onBegin
= d
.connect(this._current
, "onBegin", this, function(arg
){
67 this._fire("onBegin", arguments
);
69 onPlay
= d
.connect(this._current
, "onPlay", this, function(arg
){
70 this._fire("onPlay", arguments
);
71 d
.disconnect(beforeBegin
);
72 d
.disconnect(onBegin
);
75 if(this._onAnimateCtx
){
76 d
.disconnect(this._onAnimateCtx
);
78 this._onAnimateCtx
= d
.connect(this._current
, "onAnimate", this, "_onAnimate");
80 d
.disconnect(this._onEndCtx
);
82 this._onEndCtx
= d
.connect(this._current
, "onEnd", this, "_onEnd");
83 this._current
.play
.apply(this._current
, arguments
);
88 var e
= d
.connect(this._current
, "onPause", this, function(arg
){
89 this._fire("onPause", arguments
);
92 this._current
.pause();
96 gotoPercent: function(/*Decimal*/percent
, /*Boolean?*/ andPlay
){
98 var offset
= this.duration
* percent
;
100 d
.some(this._animations
, function(a
){
101 if(a
.duration
<= offset
){
105 offset
-= a
.duration
;
109 this._current
.gotoPercent(offset
/ this._current
.duration
, andPlay
);
113 stop: function(/*boolean?*/ gotoEnd
){
116 for(; this._index
+ 1 < this._animations
.length
; ++this._index
){
117 this._animations
[this._index
].stop(true);
119 this._current
= this._animations
[this._index
];
121 var e
= d
.connect(this._current
, "onStop", this, function(arg
){
122 this._fire("onStop", arguments
);
125 this._current
.stop();
130 return this._current
? this._current
.status() : "stopped";
133 if(this._onAnimateCtx
){ d
.disconnect(this._onAnimateCtx
); }
134 if(this._onEndCtx
){ d
.disconnect(this._onEndCtx
); }
137 d
.extend(_chain
, _baseObj
);
139 dojo
.fx
.chain = function(/*dojo.Animation[]*/ animations
){
141 // Chain a list of `dojo.Animation`s to run in sequence
144 // Return a `dojo.Animation` which will play all passed
145 // `dojo.Animation` instances in sequence, firing its own
146 // synthesized events simulating a single animation. (eg:
147 // onEnd of this animation means the end of the chain,
148 // not the individual animations within)
151 // Once `node` is faded out, fade in `otherNode`
153 // | dojo.fadeIn({ node:node }),
154 // | dojo.fadeOut({ node:otherNode })
157 return new _chain(animations
) // dojo.Animation
160 var _combine = function(animations
){
161 this._animations
= animations
||[];
166 d
.forEach(animations
, function(a
){
167 var duration
= a
.duration
;
168 if(a
.delay
){ duration
+= a
.delay
; }
169 if(this.duration
< duration
){ this.duration
= duration
; }
170 this._connects
.push(d
.connect(a
, "onEnd", this, "_onEnd"));
173 this._pseudoAnimation
= new d
.Animation({curve
: [0, 1], duration
: this.duration
});
175 d
.forEach(["beforeBegin", "onBegin", "onPlay", "onAnimate", "onPause", "onStop", "onEnd"],
177 self
._connects
.push(d
.connect(self
._pseudoAnimation
, evt
,
178 function(){ self
._fire(evt
, arguments
); }
184 _doAction: function(action
, args
){
185 d
.forEach(this._animations
, function(a
){
186 a
[action
].apply(a
, args
);
191 if(++this._finished
> this._animations
.length
){
195 _call: function(action
, args
){
196 var t
= this._pseudoAnimation
;
197 t
[action
].apply(t
, args
);
199 play: function(/*int?*/ delay
, /*Boolean?*/ gotoStart
){
201 this._doAction("play", arguments
);
202 this._call("play", arguments
);
206 this._doAction("pause", arguments
);
207 this._call("pause", arguments
);
210 gotoPercent: function(/*Decimal*/percent
, /*Boolean?*/ andPlay
){
211 var ms
= this.duration
* percent
;
212 d
.forEach(this._animations
, function(a
){
213 a
.gotoPercent(a
.duration
< ms
? 1 : (ms
/ a
.duration
), andPlay
);
215 this._call("gotoPercent", arguments
);
218 stop: function(/*boolean?*/ gotoEnd
){
219 this._doAction("stop", arguments
);
220 this._call("stop", arguments
);
224 return this._pseudoAnimation
.status();
227 d
.forEach(this._connects
, dojo
.disconnect
);
230 d
.extend(_combine
, _baseObj
);
232 dojo
.fx
.combine = function(/*dojo.Animation[]*/ animations
){
234 // Combine a list of `dojo.Animation`s to run in parallel
237 // Combine an array of `dojo.Animation`s to run in parallel,
238 // providing a new `dojo.Animation` instance encompasing each
239 // animation, firing standard animation events.
242 // Fade out `node` while fading in `otherNode` simultaneously
243 // | dojo.fx.combine([
244 // | dojo.fadeIn({ node:node }),
245 // | dojo.fadeOut({ node:otherNode })
249 // When the longest animation ends, execute a function:
250 // | var anim = dojo.fx.combine([
251 // | dojo.fadeIn({ node: n, duration:700 }),
252 // | dojo.fadeOut({ node: otherNode, duration: 300 })
254 // | dojo.connect(anim, "onEnd", function(){
255 // | // overall animation is done.
257 // | anim.play(); // play the animation
259 return new _combine(animations
); // dojo.Animation
262 dojo
.fx
.wipeIn = function(/*Object*/ args
){
264 // Expand a node to it's natural height.
267 // Returns an animation that will expand the
268 // node defined in 'args' object from it's current height to
269 // it's natural height (with no scrollbar).
270 // Node must have no margin/border/padding.
273 // A hash-map of standard `dojo.Animation` constructor properties
274 // (such as easing: node: duration: and so on)
277 // | dojo.fx.wipeIn({
280 var node
= args
.node
= d
.byId(args
.node
), s
= node
.style
, o
;
282 var anim
= d
.animateProperty(d
.mixin({
285 // wrapped in functions so we wait till the last second to query (in case value has changed)
287 // start at current [computed] height, but use 1px rather than 0
288 // because 0 causes IE to display the whole panel
290 s
.overflow
= "hidden";
291 if(s
.visibility
== "hidden" || s
.display
== "none"){
297 var height
= d
.style(node
, "height");
298 return Math
.max(height
, 1);
302 return node
.scrollHeight
;
308 d
.connect(anim
, "onEnd", function(){
313 return anim
; // dojo.Animation
316 dojo
.fx
.wipeOut = function(/*Object*/ args
){
318 // Shrink a node to nothing and hide it.
321 // Returns an animation that will shrink node defined in "args"
322 // from it's current height to 1px, and then hide it.
325 // A hash-map of standard `dojo.Animation` constructor properties
326 // (such as easing: node: duration: and so on)
329 // | dojo.fx.wipeOut({ node:"someId" }).play()
331 var node
= args
.node
= d
.byId(args
.node
), s
= node
.style
, o
;
333 var anim
= d
.animateProperty(d
.mixin({
336 end
: 1 // 0 causes IE to display the whole panel
341 d
.connect(anim
, "beforeBegin", function(){
343 s
.overflow
= "hidden";
346 d
.connect(anim
, "onEnd", function(){
352 return anim
; // dojo.Animation
355 dojo
.fx
.slideTo = function(/*Object*/ args
){
357 // Slide a node to a new top/left position
360 // Returns an animation that will slide "node"
361 // defined in args Object from its current position to
362 // the position defined by (args.left, args.top).
365 // A hash-map of standard `dojo.Animation` constructor properties
366 // (such as easing: node: duration: and so on). Special args members
367 // are `top` and `left`, which indicate the new position to slide to.
370 // | dojo.fx.slideTo({ node: node, left:"40", top:"50", units:"px" }).play()
372 var node
= args
.node
= d
.byId(args
.node
),
373 top
= null, left
= null;
375 var init
= (function(n
){
377 var cs
= d
.getComputedStyle(n
);
378 var pos
= cs
.position
;
379 top
= (pos
== 'absolute' ? n
.offsetTop
: parseInt(cs
.top
) || 0);
380 left
= (pos
== 'absolute' ? n
.offsetLeft
: parseInt(cs
.left
) || 0);
381 if(pos
!= 'absolute' && pos
!= 'relative'){
382 var ret
= d
.position(n
, true);
385 n
.style
.position
="absolute";
386 n
.style
.top
=top
+"px";
387 n
.style
.left
=left
+"px";
393 var anim
= d
.animateProperty(d
.mixin({
399 d
.connect(anim
, "beforeBegin", anim
, init
);
401 return anim
; // dojo.Animation