-
Notifications
You must be signed in to change notification settings - Fork 1
/
navigation.js
91 lines (81 loc) · 1.96 KB
/
navigation.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
var currentPage = 0;
var totalPages = {{ total_pages }} + 1;
var slideTimer = null;
var timerRunning = false;
function showPage(page) {
document.querySelectorAll('.page').forEach(function(div, index) {
div.classList.remove('actives');
if (index === page) {
div.classList.add('active');
}
});
}
function prevPage() {
if (currentPage > 0) {
currentPage--;
showPage(currentPage);
}
}
function nextPage() {
if (currentPage < totalPages - 1) {
currentPage++;
showPage(currentPage);
}
}
function goToFirstPage() {
currentPage = 0;
showPage(currentPage);
}
function goToLastPage() {
currentPage = totalPages - 1;
showPage(currentPage);
}
function showFlashMessage(message) {
var flashMessage = document.getElementById("flash-message");
flashMessage.textContent = message;
flashMessage.classList.add("show");
setTimeout(function () {
flashMessage.classList.remove("show");
}, 2000); // hide message after 2 seconds
}
function startTimer() {
if (!timerRunning) {
slideTimer = setInterval(() => {
if (currentPage < totalPages - 1) {
nextPage();
} else {
clearInterval(slideTimer);
timerRunning = false;
}
}, 10000);
timerRunning = true;
console.log("Timer Started!");
showFlashMessage("Timer Running...");
}
}
function stopTimer() {
if (timerRunning) {
clearInterval(slideTimer);
timerRunning = false;
console.log("Timer Stopped!");
showFlashMessage("Timer Stopped!");
}
}
document.addEventListener("keydown", function (event) {
if (event.key === "ArrowLeft") {
prevPage();
} else if (event.key === "ArrowRight") {
nextPage();
} else if (event.key === "Home") {
goToFirstPage();
} else if (event.key === "End") {
goToLastPage();
} else if (event.key === " ") {
if (timerRunning) {
stopTimer();
} else {
startTimer();
}
}
});
showPage(currentPage);