-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathomr_speakers.js
309 lines (243 loc) · 10.1 KB
/
omr_speakers.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
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
let speakersData = [];
// Function to fetch speakers' data from API
async function fetchSpeakersData() {
try {
let response = await fetch('http://localhost:3000/speaker');
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
let data = await response.json();
console.log('Fetched speakers data:', data); // Log entire fetched data array
speakersData = data; // Store the fetched speakers data globally
initializeSpeakers(); // Initialize speakers after fetching data
} catch (error) {
console.error('Error fetching speakers data:', error);
}
}
// Function to create a speaker card element
function createSpeakerCard(speaker) {
// Create the main speaker card element
const speakerCard = document.createElement('div');
speakerCard.classList.add('speaker-card');
// Create the link element
const speakerLink = document.createElement('a');
speakerLink.href = `omr_speakers_detail.html?id=${speaker.id}`;
// Create and append the image element
const speakerImage = document.createElement('img');
speakerImage.src = speaker.image;
speakerImage.alt = speaker.name;
speakerCard.appendChild(speakerImage);
// Create and append the name element
const speakerName = document.createElement('h3');
speakerName.textContent = speaker.name;
speakerCard.appendChild(speakerName);
// Create and append the title element
const speakerTitle = document.createElement('span');
speakerTitle.textContent = speaker.title;
speakerCard.appendChild(speakerTitle);
// Add click event to the speaker card
speakerCard.addEventListener('click', () => {
console.log(`Navigating to: ${speakerLink.href}`); // Debugging: log the navigation URL
window.location.href = speakerLink.href;
});
return speakerCard;
}
// Function to initialize and display the first set of speakers
function initializeSpeakers() {
const speakersGrid = document.querySelector('.speakers-grid');
speakersGrid.innerHTML = ''; // Clear previous content
const initialCount = 12; // Display the first 12 speakers initially
for (let i = 0; i < initialCount && i < speakersData.length; i++) {
const speakerCard = createSpeakerCard(speakersData[i]);
speakersGrid.appendChild(speakerCard);
}
if (speakersData.length > initialCount) {
document.querySelector('.loadbtn').style.display = 'block'; // Show load more button if more speakers available
}
}
// Function to render more speakers
function renderMoreSpeakers() {
const speakersGrid = document.querySelector('.speakers-grid');
const startIndex = speakersGrid.children.length; // Number of currently displayed speakers
const endIndex = startIndex + 12; // Display next 12 speakers
for (let i = startIndex; i < endIndex && i < speakersData.length; i++) {
const speakerCard = createSpeakerCard(speakersData[i]);
speakersGrid.appendChild(speakerCard);
}
if (endIndex >= speakersData.length) {
document.querySelector('.loadbtn').style.display = 'none'; // Hide load more button if no more speakers
}
}
// Function to validate speaker's topics
function validateSpeakerTopics(speakerTopics, selectedTopics) {
let topics = speakerTopics.toLowerCase().split(" | ").map(topic => topic.trim());
let filteredTopics = topics.filter(topic => selectedTopics.includes(topic));
return filteredTopics.length > 0;
}
// Function to validate speaker's day
function validateSpeakerDay(speakerDay, selectedDays) {
let day = speakerDay.toLowerCase();
return selectedDays.includes(day);
}
// Function to filter speakers based on selected topics and days
function filterSpeakers(selectedTopics, selectedDays) {
return speakersData.filter(speaker => {
const speakerTopics = speaker.topics || "";
const speakerDay = speaker.day || "";
if (selectedTopics.length > 0 && selectedDays.length > 0) {
let isTopicValid = validateSpeakerTopics(speakerTopics, selectedTopics);
let isDayValid = validateSpeakerDay(speakerDay, selectedDays);
return isTopicValid && isDayValid;
} else {
if (selectedTopics.length > 0) {
let isTopicValid = validateSpeakerTopics(speakerTopics, selectedTopics);
return isTopicValid;
} else {
let isDayValid = validateSpeakerDay(speakerDay, selectedDays);
return isDayValid;
}
}
});
}
// Function to update displayed speakers
function updateDisplayedSpeakers() {
const selectedTopics = Array.from(document.querySelectorAll('#topics-dropdown input[type="checkbox"]:checked')).map(option => option.value.toLowerCase());
const selectedDays = Array.from(document.querySelectorAll('#days-dropdown input[type="checkbox"]:checked')).map(option => option.value.toLowerCase());
let filteredSpeakers = filterSpeakers(selectedTopics, selectedDays);
console.log('Filtered speakers:', filteredSpeakers); // Debugging: log filtered speakers
const speakersGrid = document.querySelector('.speakers-grid');
speakersGrid.innerHTML = ''; // Clear previous results
if (filteredSpeakers.length === 0) {
const noResultsMessage = document.createElement('p');
noResultsMessage.textContent = 'No speakers found.';
speakersGrid.appendChild(noResultsMessage);
} else {
filteredSpeakers.forEach(speaker => {
const speakerCard = createSpeakerCard(speaker);
speakersGrid.appendChild(speakerCard);
});
}
}
// Event listener for language selector
const selectedLanguageButton = document.getElementById('selected-language');
const currentFlagImage = document.getElementById('current-flag');
const languageOptions = document.getElementById('language-options');
languageOptions.addEventListener('click', function(event) {
if (event.target.closest('button')) {
const selectedButton = event.target.closest('button');
const newFlag = selectedButton.getAttribute('data-flag');
currentFlagImage.src = newFlag;
}
});
// Event listener for burger menu
const menuBars = document.querySelector('#menu3 .fa-bars');
const menuDropdown = document.getElementById('menu3-dropdown');
menuBars.addEventListener('mouseover', function () {
menuDropdown.style.display = 'flex';
});
menuDropdown.addEventListener('mouseleave', function () {
menuDropdown.style.display = 'none';
});
// Event listener setup for topics and days dropdowns
const topicsDropdownInputs = document.querySelectorAll('#topics-dropdown input[type="checkbox"]');
topicsDropdownInputs.forEach(input => {
input.addEventListener('change', updateDisplayedSpeakers);
});
const daysDropdownInputs = document.querySelectorAll('#days-dropdown input[type="checkbox"]');
daysDropdownInputs.forEach(input => {
input.addEventListener('change', updateDisplayedSpeakers);
});
// Event listener for search input
const searchInput = document.querySelector('.input-container input');
searchInput.addEventListener('input', function () {
const searchTerm = this.value.trim();
console.log(`Search term: ${searchTerm}`); // Debugging: log search term
if (searchTerm.length > 0) {
filterSpeakersBySearch(searchTerm);
} else {
showSpeakers(speakersData); // Show all speakers if search field is empty
}
});
// Event listeners for dropdown toggles
const dropdownToggleButtons = document.querySelectorAll('.dropbtn');
dropdownToggleButtons.forEach(button => {
button.addEventListener('click', function () {
const dropdownContent = this.nextElementSibling;
dropdownContent.classList.toggle('show');
});
});
// Event listener to close dropdowns if clicking outside
window.addEventListener('click', function (event) {
if (!event.target.matches('.dropbtn')) {
dropdownToggleButtons.forEach(button => {
const dropdownContent = button.nextElementSibling;
if (dropdownContent.classList.contains('show')) {
dropdownContent.classList.remove('show');
}
});
}
});
// Event listener for load more button
const loadMoreButton = document.querySelector('.loadbtn');
loadMoreButton.addEventListener('click', renderMoreSpeakers);
// Captcha verification
document.getElementById('captchaButton').addEventListener('click', function() {
document.getElementById('captchaIcon').className = 'fa-solid fa-circle-notch loading';
document.getElementById('captchaText').textContent = 'Verification in progress...';
document.getElementById('captchaButton').style.display = 'none';
setTimeout(function() {
document.getElementById('captchaIcon').className = 'fa-solid fa-shield-heart';
document.getElementById('captchaText').textContent = 'Verification successful!';
}, 2000);
});
// Chat popup
const openPopupButton = document.getElementById('openPopup');
const popupForm = document.getElementById('popupForm');
const closePopupButton = document.getElementById('closePopup');
const form = document.getElementById('contactForm');
const popupContent = document.querySelector('.popup-content');
openPopupButton.addEventListener('click', () => {
popupForm.style.display = 'block';
});
closePopupButton.addEventListener('click', () => {
popupForm.style.display = 'none';
});
// // Handle form submission
popupContent.addEventListener('submit', (e) => {
e.preventDefault();
popupForm.innerHTML = `
<div class="submitted-message">
<h2>Thank you!</h2>
<p>Our unicorns are now working their magic and will get back to you soon.</p>
</div>
`;
popupForm.style.backgroundColor = '#ffc107';
popupContent.style.color = 'white';
window.addEventListener('click', function (event) {
if (!event.target.matches('.popupForm')) {
popupForm.style.display = 'none';
}
});
});
// Prevent footer links to work
const footerLinks = document.querySelectorAll('.footer a');
const socialIcons = document.querySelectorAll('.social-icons a');
// Prevent default action for footer links
footerLinks.forEach(link => {
link.addEventListener('click', (e) => {
e.preventDefault();
});
});
// Prevent default action for social icons
socialIcons.forEach(icon => {
icon.addEventListener('click', (e) => {
e.preventDefault();
});
});
// Initial call to display speakers based on default selections
updateDisplayedSpeakers();
// Initialize the application
async function initializeApp() {
await fetchSpeakersData();
}
initializeApp();