blob: c35f983ca3167f5dbfb66d6620d718dc99d811f8 (
plain)
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
|
class Slideshow {
constructor(node) {
let prev, next, time;
this.autostop = false;
this.timeout = false;
this.current = 0;
this.list = node.getElementsByTagName("ul")[0].getElementsByTagName("li");
if(prev = node.getElementsByClassName("prev")[0]) {
prev.onclick = () => {
this.initializeTimeout();
this.changeDirection("prev")
};
}
if(next = node.getElementsByClassName("next")[0]) {
next.onclick = () => {
this.initializeTimeout();
this.changeDirection("next");
};
}
if(time = node.getAttribute("data-time")) {
setInterval(() => {
!this.autostop && this.changeDirection("next");
}, time);
}
}
initializeTimeout() {
if(this.timeout) {
clearTimeout(this.timeout);
}
this.autostop = true;
this.timeout = setTimeout(() => {
this.autostop = false;
}, 15000);
}
changeDirection(direction) {
(direction === "prev" && --this.current);
(direction === "next" && ++this.current);
if(this.list[this.current] === undefined) {
switch(direction) {
case "prev": this.current = this.list.length - 1; break;
case "next": this.current = 0;
}
}
for(let i = 0; i < this.list.length; ++i) {
if(this.current === i) {
this.list[i].getAttribute("class") !== "show" && this.list[i].setAttribute("class", "show " + direction);
} else {
this.list[i].getAttribute("class") !== "hide" && this.list[i].setAttribute("class", "hide");
}
}
}
}
|