-
Notifications
You must be signed in to change notification settings - Fork 1
/
cb.transition.js
66 lines (59 loc) · 1.74 KB
/
cb.transition.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
var cb = cb || {};
(function (transition) {
var sIndex = 0,
direction = 1, // 1 = forward; -1 = backward
sequence,
sequencer,
reset = function() {
sIndex = 0;
direction = 1;
sequence = null;
};
/*
* fn:
* function you want to sequence (Don't forget $.fn)
*
* args (optional):
* array of arguments you would normally pass to fn
* e.g. [{left: '100px'}, 'fast']
*
* callback (optional):
* function to call after entire sequence is animated
*/
sequencer = function (fn, args, callback) {
var oargs,
el = (direction == 1) ? sequence.eq(sIndex++) : sequence.eq(--sIndex);
// sequencer(fn, callback) - 2-argument overload
if (args && typeof args === "function") {
callback = args;
args = [];
}
if (el.length) {
args = args || [];
// set a copy of args by value
oargs = args.slice();
// add a recursive callback to the sequencer in args
args.push(
function () {
sequencer(fn, oargs, callback);
}
);
fn.apply(el, args);
} else {
if (callback) {
callback.call();
}
}
};
transition.tile = function (els, callback) {
reset();
sequence = els;
if (els.is(':visible')) {
sIndex = els.length;
direction = -1;
sequencer($.fn.fadeOut, [180], callback);
} else {
sequencer($.fn.fadeIn, [180], callback);
}
};
})(cb.transition = cb.transition || {});