forked from Ctoic/Lisbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
80 lines (67 loc) · 2.87 KB
/
app.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
document.addEventListener("DOMContentLoaded", function () {
const audioPlayer = document.getElementById("audio-player");
const playlistItems = document.querySelectorAll("#playlist li");
const playPauseBtn = document.getElementById('playPauseBtn'); // Play/Pause button
// Playlist functionality: Play the clicked audio
playlistItems.forEach((item) => {
item.addEventListener("click", function () {
const audioSource = this.getAttribute("data-src");
audioPlayer.src = audioSource;
audioPlayer.play();
playPauseBtn.classList.remove('play'); // Update the button to pause when playing
playPauseBtn.classList.add('pause');
});
});
// Play/Pause button functionality
playPauseBtn.addEventListener('click', () => {
if (audioPlayer.paused) {
audioPlayer.play();
playPauseBtn.classList.remove('play');
playPauseBtn.classList.add('pause');
} else {
audioPlayer.pause();
playPauseBtn.classList.remove('pause');
playPauseBtn.classList.add('play');
}
});
// Comment submission functionality
const commentForm = document.getElementById("comment-form");
const commentsList = document.getElementById("comments-list");
commentForm.addEventListener("submit", function (e) {
e.preventDefault();
const username = document.getElementById("username").value;
const commentText = document.getElementById("comment").value;
if (username && commentText) {
const commentElement = document.createElement("div");
commentElement.classList.add("comment");
commentElement.innerHTML = `<strong>${username}:</strong><p>${commentText}</p>`;
commentsList.appendChild(commentElement);
// Clear the form
commentForm.reset();
}
});
// Page navigation buttons functionality
const prevBtn = document.getElementById("prev-btn");
const nextBtn = document.getElementById("next-btn");
// Define the pages for navigation
const pages = ['index.html', 'genres.html', 'about.html'];
let currentPageIndex = pages.indexOf(window.location.pathname);
// Function to navigate to the next page
function nextPage() {
if (currentPageIndex < pages.length - 1) {
currentPageIndex++;
window.location.href = pages[currentPageIndex];
}
}
// Function to navigate to the previous page
function prevPage() {
if (currentPageIndex > 0) {
currentPageIndex--;
window.location.href = pages[currentPageIndex];
}
}
// Event listener for "Next" button
if (nextBtn) nextBtn.addEventListener("click", nextPage);
// Event listener for "Previous" button
if (prevBtn) prevBtn.addEventListener("click", prevPage);
});