]>
git.wh0rd.org - tt-rss.git/blob - lib/dojo/fx.js.uncompressed.js
12 "require" // for context sensitive loading of Toggler
13 ], function(lang
, Evented
, dojo
, arrayUtil
, connect
, baseFx
, dom
, domStyle
, geom
, ready
, require
) {
23 // summary: Effects library on top of Base animations
28 // For back-compat, remove in 2.0.
31 var requires
= ["./fx/Toggler"];
32 require(requires
); // use indirection so modules not rolled into a build
36 var coreFx
= dojo
.fx
= {};
39 _fire: function(evt
, args
){
41 this[evt
].apply(this, args
||[]);
47 var _chain = function(animations
){
49 this._animations
= animations
||[];
50 this._current
= this._onAnimateCtx
= this._onEndCtx
= null;
53 arrayUtil
.forEach(this._animations
, function(a
){
54 this.duration
+= a
.duration
;
55 if(a
.delay
){ this.duration
+= a
.delay
; }
58 _chain
.prototype = new Evented();
60 _onAnimate: function(){
61 this._fire("onAnimate", arguments
);
64 connect
.disconnect(this._onAnimateCtx
);
65 connect
.disconnect(this._onEndCtx
);
66 this._onAnimateCtx
= this._onEndCtx
= null;
67 if(this._index
+ 1 == this._animations
.length
){
71 this._current
= this._animations
[++this._index
];
72 this._onAnimateCtx
= connect
.connect(this._current
, "onAnimate", this, "_onAnimate");
73 this._onEndCtx
= connect
.connect(this._current
, "onEnd", this, "_onEnd");
74 this._current
.play(0, true);
77 play: function(/*int?*/ delay
, /*Boolean?*/ gotoStart
){
78 if(!this._current
){ this._current
= this._animations
[this._index
= 0]; }
79 if(!gotoStart
&& this._current
.status() == "playing"){ return this; }
80 var beforeBegin
= connect
.connect(this._current
, "beforeBegin", this, function(){
81 this._fire("beforeBegin");
83 onBegin
= connect
.connect(this._current
, "onBegin", this, function(arg
){
84 this._fire("onBegin", arguments
);
86 onPlay
= connect
.connect(this._current
, "onPlay", this, function(arg
){
87 this._fire("onPlay", arguments
);
88 connect
.disconnect(beforeBegin
);
89 connect
.disconnect(onBegin
);
90 connect
.disconnect(onPlay
);
92 if(this._onAnimateCtx
){
93 connect
.disconnect(this._onAnimateCtx
);
95 this._onAnimateCtx
= connect
.connect(this._current
, "onAnimate", this, "_onAnimate");
97 connect
.disconnect(this._onEndCtx
);
99 this._onEndCtx
= connect
.connect(this._current
, "onEnd", this, "_onEnd");
100 this._current
.play
.apply(this._current
, arguments
);
105 var e
= connect
.connect(this._current
, "onPause", this, function(arg
){
106 this._fire("onPause", arguments
);
107 connect
.disconnect(e
);
109 this._current
.pause();
113 gotoPercent: function(/*Decimal*/percent
, /*Boolean?*/ andPlay
){
115 var offset
= this.duration
* percent
;
116 this._current
= null;
117 arrayUtil
.some(this._animations
, function(a
){
118 if(a
.duration
<= offset
){
122 offset
-= a
.duration
;
126 this._current
.gotoPercent(offset
/ this._current
.duration
, andPlay
);
130 stop: function(/*boolean?*/ gotoEnd
){
133 for(; this._index
+ 1 < this._animations
.length
; ++this._index
){
134 this._animations
[this._index
].stop(true);
136 this._current
= this._animations
[this._index
];
138 var e
= connect
.connect(this._current
, "onStop", this, function(arg
){
139 this._fire("onStop", arguments
);
140 connect
.disconnect(e
);
142 this._current
.stop();
147 return this._current
? this._current
.status() : "stopped";
150 if(this._onAnimateCtx
){ connect
.disconnect(this._onAnimateCtx
); }
151 if(this._onEndCtx
){ connect
.disconnect(this._onEndCtx
); }
154 lang
.extend(_chain
, _baseObj
);
156 coreFx
.chain
= /*===== dojo.fx.chain = =====*/ function(/*dojo.Animation[]*/ animations
){
158 // Chain a list of `dojo.Animation`s to run in sequence
161 // Return a `dojo.Animation` which will play all passed
162 // `dojo.Animation` instances in sequence, firing its own
163 // synthesized events simulating a single animation. (eg:
164 // onEnd of this animation means the end of the chain,
165 // not the individual animations within)
168 // Once `node` is faded out, fade in `otherNode`
170 // | dojo.fadeIn({ node:node }),
171 // | dojo.fadeOut({ node:otherNode })
174 return new _chain(animations
); // dojo.Animation
177 var _combine = function(animations
){
178 this._animations
= animations
||[];
183 arrayUtil
.forEach(animations
, function(a
){
184 var duration
= a
.duration
;
185 if(a
.delay
){ duration
+= a
.delay
; }
186 if(this.duration
< duration
){ this.duration
= duration
; }
187 this._connects
.push(connect
.connect(a
, "onEnd", this, "_onEnd"));
190 this._pseudoAnimation
= new baseFx
.Animation({curve
: [0, 1], duration
: this.duration
});
192 arrayUtil
.forEach(["beforeBegin", "onBegin", "onPlay", "onAnimate", "onPause", "onStop", "onEnd"],
194 self
._connects
.push(connect
.connect(self
._pseudoAnimation
, evt
,
195 function(){ self
._fire(evt
, arguments
); }
200 lang
.extend(_combine
, {
201 _doAction: function(action
, args
){
202 arrayUtil
.forEach(this._animations
, function(a
){
203 a
[action
].apply(a
, args
);
208 if(++this._finished
> this._animations
.length
){
212 _call: function(action
, args
){
213 var t
= this._pseudoAnimation
;
214 t
[action
].apply(t
, args
);
216 play: function(/*int?*/ delay
, /*Boolean?*/ gotoStart
){
218 this._doAction("play", arguments
);
219 this._call("play", arguments
);
223 this._doAction("pause", arguments
);
224 this._call("pause", arguments
);
227 gotoPercent: function(/*Decimal*/percent
, /*Boolean?*/ andPlay
){
228 var ms
= this.duration
* percent
;
229 arrayUtil
.forEach(this._animations
, function(a
){
230 a
.gotoPercent(a
.duration
< ms
? 1 : (ms
/ a
.duration
), andPlay
);
232 this._call("gotoPercent", arguments
);
235 stop: function(/*boolean?*/ gotoEnd
){
236 this._doAction("stop", arguments
);
237 this._call("stop", arguments
);
241 return this._pseudoAnimation
.status();
244 arrayUtil
.forEach(this._connects
, connect
.disconnect
);
247 lang
.extend(_combine
, _baseObj
);
249 coreFx
.combine
= /*===== dojo.fx.combine = =====*/ function(/*dojo.Animation[]*/ animations
){
251 // Combine a list of `dojo.Animation`s to run in parallel
254 // Combine an array of `dojo.Animation`s to run in parallel,
255 // providing a new `dojo.Animation` instance encompasing each
256 // animation, firing standard animation events.
259 // Fade out `node` while fading in `otherNode` simultaneously
260 // | dojo.fx.combine([
261 // | dojo.fadeIn({ node:node }),
262 // | dojo.fadeOut({ node:otherNode })
266 // When the longest animation ends, execute a function:
267 // | var anim = dojo.fx.combine([
268 // | dojo.fadeIn({ node: n, duration:700 }),
269 // | dojo.fadeOut({ node: otherNode, duration: 300 })
271 // | dojo.connect(anim, "onEnd", function(){
272 // | // overall animation is done.
274 // | anim.play(); // play the animation
276 return new _combine(animations
); // dojo.Animation
279 coreFx
.wipeIn
= /*===== dojo.fx.wipeIn = =====*/ function(/*Object*/ args
){
281 // Expand a node to it's natural height.
284 // Returns an animation that will expand the
285 // node defined in 'args' object from it's current height to
286 // it's natural height (with no scrollbar).
287 // Node must have no margin/border/padding.
290 // A hash-map of standard `dojo.Animation` constructor properties
291 // (such as easing: node: duration: and so on)
294 // | dojo.fx.wipeIn({
297 var node
= args
.node
= dom
.byId(args
.node
), s
= node
.style
, o
;
299 var anim
= baseFx
.animateProperty(lang
.mixin({
302 // wrapped in functions so we wait till the last second to query (in case value has changed)
304 // start at current [computed] height, but use 1px rather than 0
305 // because 0 causes IE to display the whole panel
307 s
.overflow
= "hidden";
308 if(s
.visibility
== "hidden" || s
.display
== "none"){
314 var height
= domStyle
.get(node
, "height");
315 return Math
.max(height
, 1);
319 return node
.scrollHeight
;
325 var fini = function(){
329 connect
.connect(anim
, "onStop", fini
);
330 connect
.connect(anim
, "onEnd", fini
);
332 return anim
; // dojo.Animation
335 coreFx
.wipeOut
= /*===== dojo.fx.wipeOut = =====*/ function(/*Object*/ args
){
337 // Shrink a node to nothing and hide it.
340 // Returns an animation that will shrink node defined in "args"
341 // from it's current height to 1px, and then hide it.
344 // A hash-map of standard `dojo.Animation` constructor properties
345 // (such as easing: node: duration: and so on)
348 // | dojo.fx.wipeOut({ node:"someId" }).play()
350 var node
= args
.node
= dom
.byId(args
.node
), s
= node
.style
, o
;
352 var anim
= baseFx
.animateProperty(lang
.mixin({
355 end
: 1 // 0 causes IE to display the whole panel
360 connect
.connect(anim
, "beforeBegin", function(){
362 s
.overflow
= "hidden";
365 var fini = function(){
370 connect
.connect(anim
, "onStop", fini
);
371 connect
.connect(anim
, "onEnd", fini
);
373 return anim
; // dojo.Animation
376 coreFx
.slideTo
= /*===== dojo.fx.slideTo = =====*/ function(/*Object*/ args
){
378 // Slide a node to a new top/left position
381 // Returns an animation that will slide "node"
382 // defined in args Object from its current position to
383 // the position defined by (args.left, args.top).
386 // A hash-map of standard `dojo.Animation` constructor properties
387 // (such as easing: node: duration: and so on). Special args members
388 // are `top` and `left`, which indicate the new position to slide to.
391 // | .slideTo({ node: node, left:"40", top:"50", units:"px" }).play()
393 var node
= args
.node
= dom
.byId(args
.node
),
394 top
= null, left
= null;
396 var init
= (function(n
){
398 var cs
= domStyle
.getComputedStyle(n
);
399 var pos
= cs
.position
;
400 top
= (pos
== 'absolute' ? n
.offsetTop
: parseInt(cs
.top
) || 0);
401 left
= (pos
== 'absolute' ? n
.offsetLeft
: parseInt(cs
.left
) || 0);
402 if(pos
!= 'absolute' && pos
!= 'relative'){
403 var ret
= geom
.position(n
, true);
406 n
.style
.position
="absolute";
407 n
.style
.top
=top
+"px";
408 n
.style
.left
=left
+"px";
414 var anim
= baseFx
.animateProperty(lang
.mixin({
420 connect
.connect(anim
, "beforeBegin", anim
, init
);
422 return anim
; // dojo.Animation