This repository has been archived by the owner on Sep 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
modern-fade.js
76 lines (66 loc) · 2.31 KB
/
modern-fade.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
67
68
69
70
71
72
73
74
75
76
// Generated by CoffeeScript 1.6.3
(function() {
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
this.ModernFade = (function() {
function ModernFade(wrapper, _options) {
this.wrapper = wrapper;
if (_options == null) {
_options = {};
}
this.log = __bind(this.log, this);
this.mergeAttributes = __bind(this.mergeAttributes, this);
this.refresh = __bind(this.refresh, this);
this.startTimeout = __bind(this.startTimeout, this);
this.afterTransition = __bind(this.afterTransition, this);
this.transition = __bind(this.transition, this);
this.elements = document.querySelectorAll("" + this.wrapper + " > *");
this.index = this.elements.length - 1;
this.elements[this.index].className += 'in';
this.options = this.mergeAttributes(_options, {
delay: 2000,
time: 1600
});
this.startTimeout();
}
ModernFade.prototype.transition = function() {
this.t_out = this.elements[this.index];
this.next = this.index - 1 >= 0 ? this.index - 1 : this.elements.length - 1;
this.t_in = this.elements[this.next];
this.t_out.className = this.t_out.className.replace('in', '');
this.t_out.className += "out";
this.t_in.className += "in";
return setTimeout(this.afterTransition, this.options.time);
};
ModernFade.prototype.afterTransition = function() {
this.t_out.className = this.t_out.className.replace("out", "");
this.index = this.next;
return this.startTimeout();
};
ModernFade.prototype.startTimeout = function() {
return setTimeout(this.transition, this.options.delay);
};
ModernFade.prototype.refresh = function(_index) {
this.elements = document.querySelectorAll("" + this.wrapper + " > *");
if (_index) {
return this.index = _index;
}
};
ModernFade.prototype.mergeAttributes = function(obj1, obj2) {
var key, obj3, val;
obj3 = {};
for (key in obj2) {
val = obj2[key];
obj3[key] = val;
}
for (key in obj1) {
val = obj1[key];
obj3[key] = val;
}
return obj3;
};
ModernFade.prototype.log = function(msg) {
return console.log('ModernFade', msg);
};
return ModernFade;
})();
}).call(this);