-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
195 lines (162 loc) · 6.17 KB
/
script.js
File metadata and controls
195 lines (162 loc) · 6.17 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
// DOM elements
const songModal = document.getElementById('songModal');
const modalClose = document.getElementById('modalClose');
const modalTitle = document.getElementById('modalTitle');
const modalArtist = document.getElementById('modalArtist');
const modalChords = document.getElementById('modalChords');
// Modal functionality
function openModal(song) {
modalTitle.textContent = song.title;
modalArtist.textContent = song.artist;
modalChords.textContent = song.chords;
// Set Ultimate Guitar link
const ultimateGuitarLink = document.getElementById('ultimateGuitarLink');
if (ultimateGuitarLink) {
if (song.ultimateGuitarLink) {
// Use manual link if provided
ultimateGuitarLink.href = song.ultimateGuitarLink;
ultimateGuitarLink.style.display = 'block';
console.log('Setting Ultimate Guitar link to:', song.ultimateGuitarLink);
} else {
// Hide link if no manual link provided
ultimateGuitarLink.style.display = 'none';
console.log('No Ultimate Guitar link provided for this song');
}
} else {
console.log('Ultimate Guitar link element not found');
}
songModal.classList.add('active');
document.body.style.overflow = 'hidden';
}
function closeModal() {
songModal.classList.remove('active');
document.body.style.overflow = 'auto';
}
modalClose.addEventListener('click', closeModal);
songModal.addEventListener('click', (e) => {
// Don't close modal if clicking on the Ultimate Guitar link
if (e.target.closest('#ultimateGuitarLink')) {
return;
}
if (e.target === songModal) {
closeModal();
}
});
// Close modal with Escape key
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape' && songModal.classList.contains('active')) {
closeModal();
}
});
// Create song card
function createSongCard(song) {
const card = document.createElement('div');
card.className = 'song-card';
// Check if we're on the kids page
const currentPage = window.location.pathname.split('/').pop() || 'index.html';
if (currentPage === 'kids.html') {
// For kids page, only show title
card.innerHTML = `
<div class="song-title">${song.title}</div>
`;
} else {
// For other pages, show title and artist
card.innerHTML = `
<div class="song-title">${song.title}</div>
<div class="song-artist">${song.artist}</div>
`;
}
card.addEventListener('click', () => openModal(song));
return card;
}
// Global variable to store kids songs for search functionality
let kidsSongsList = [];
// Load songs for each section
function loadSongs() {
// Check which page we're on and load appropriate songs
const currentPage = window.location.pathname.split('/').pop() || 'index.html';
if (currentPage === 'songs.html') {
// All adult songs
const allSongsContainer = document.getElementById('allSongs');
if (allSongsContainer) {
// Sort songs alphabetically by title
allSongs.sort((a, b) => a.title.localeCompare(b.title));
allSongs.forEach(song => {
allSongsContainer.appendChild(createSongCard(song));
});
// Initialize search functionality
initializeSearch();
}
} else if (currentPage === 'kids.html') {
// Kids songs
const kidsContainer = document.getElementById('kidsSongs');
if (kidsContainer) {
kidsSongsList = [...kidsSongs];
// Sort kids songs alphabetically by title
kidsSongsList.sort((a, b) => a.title.localeCompare(b.title));
kidsSongsList.forEach(song => {
kidsContainer.appendChild(createSongCard(song));
});
// Initialize search functionality for kids page
initializeKidsSearch();
}
}
}
// Search functionality
function initializeSearch() {
const searchInput = document.getElementById('searchInput');
if (searchInput) {
searchInput.addEventListener('input', filterSongs);
}
}
function filterSongs() {
const searchTerm = document.getElementById('searchInput').value.toLowerCase();
const allSongsContainer = document.getElementById('allSongs');
if (!allSongsContainer) return;
// Clear current songs
allSongsContainer.innerHTML = '';
// Filter songs based on search term
const filteredSongs = allSongs.filter(song =>
song.title.toLowerCase().includes(searchTerm) ||
song.artist.toLowerCase().includes(searchTerm)
);
// Display filtered songs
filteredSongs.forEach(song => {
allSongsContainer.appendChild(createSongCard(song));
});
}
// Kids search functionality
function initializeKidsSearch() {
const searchInput = document.getElementById('searchInput');
if (searchInput) {
searchInput.addEventListener('input', filterKidsSongs);
}
}
function filterKidsSongs() {
const searchTerm = document.getElementById('searchInput').value.toLowerCase();
const kidsSongsContainer = document.getElementById('kidsSongs');
if (!kidsSongsContainer) return;
// Clear current songs
kidsSongsContainer.innerHTML = '';
// Filter songs based on search term
const filteredSongs = kidsSongsList.filter(song =>
song.title.toLowerCase().includes(searchTerm) ||
song.artist.toLowerCase().includes(searchTerm)
);
// Display filtered songs
filteredSongs.forEach(song => {
kidsSongsContainer.appendChild(createSongCard(song));
});
}
// Initialize the app
document.addEventListener('DOMContentLoaded', () => {
loadSongs();
// Ensure Ultimate Guitar link works properly
const ultimateGuitarLink = document.getElementById('ultimateGuitarLink');
if (ultimateGuitarLink) {
ultimateGuitarLink.addEventListener('click', (e) => {
e.stopPropagation(); // Prevent modal from closing
console.log('Ultimate Guitar link clicked, href:', ultimateGuitarLink.href);
});
}
});