Spaces:
Running
Running
Update js/carousel.js
Browse files- js/carousel.js +110 -0
js/carousel.js
CHANGED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
let currentSlideIndex = 0;
|
| 2 |
+
let slides = [];
|
| 3 |
+
|
| 4 |
+
function openCarouselModal(images, title = '') {
|
| 5 |
+
const modal = document.getElementById('carouselModal');
|
| 6 |
+
const slidesContainer = modal.querySelector('.carousel-slides');
|
| 7 |
+
const modalTitle = modal.querySelector('.carousel-title');
|
| 8 |
+
|
| 9 |
+
// Set the title
|
| 10 |
+
if (modalTitle) {
|
| 11 |
+
modalTitle.textContent = title;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
// Clear previous slides
|
| 15 |
+
slidesContainer.innerHTML = '';
|
| 16 |
+
slides = images;
|
| 17 |
+
|
| 18 |
+
// Create slides
|
| 19 |
+
images.forEach((imageUrl, index) => {
|
| 20 |
+
const slide = document.createElement('div');
|
| 21 |
+
slide.className = `carousel-slide ${index === 0 ? 'active' : ''}`;
|
| 22 |
+
|
| 23 |
+
const img = document.createElement('img');
|
| 24 |
+
img.src = imageUrl;
|
| 25 |
+
img.alt = `Slide ${index + 1}`;
|
| 26 |
+
|
| 27 |
+
slide.appendChild(img);
|
| 28 |
+
slidesContainer.appendChild(slide);
|
| 29 |
+
});
|
| 30 |
+
|
| 31 |
+
currentSlideIndex = 0;
|
| 32 |
+
modal.classList.add('active');
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
function closeCarouselModal() {
|
| 36 |
+
const modal = document.getElementById('carouselModal');
|
| 37 |
+
modal.classList.remove('active');
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
function showSlide(index) {
|
| 41 |
+
const slidesContainer = document.querySelector('.carousel-slides');
|
| 42 |
+
const slideElements = slidesContainer.querySelectorAll('.carousel-slide');
|
| 43 |
+
|
| 44 |
+
// Handle circular navigation
|
| 45 |
+
if (index >= slides.length) index = 0;
|
| 46 |
+
if (index < 0) index = slides.length - 1;
|
| 47 |
+
|
| 48 |
+
// Update active slide
|
| 49 |
+
slideElements.forEach(slide => slide.classList.remove('active'));
|
| 50 |
+
slideElements[index].classList.add('active');
|
| 51 |
+
|
| 52 |
+
currentSlideIndex = index;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
function nextSlide() {
|
| 56 |
+
showSlide(currentSlideIndex + 1);
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
function prevSlide() {
|
| 60 |
+
showSlide(currentSlideIndex - 1);
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
// Add click event listeners to submenu items
|
| 64 |
+
// Update the click event listener
|
| 65 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 66 |
+
const submenuItems = document.querySelectorAll('.dropdown-item');
|
| 67 |
+
|
| 68 |
+
submenuItems.forEach(item => {
|
| 69 |
+
item.addEventListener('click', (e) => {
|
| 70 |
+
e.preventDefault();
|
| 71 |
+
|
| 72 |
+
// Skip carousel for social media links
|
| 73 |
+
if (item.querySelector('.fab') || item.querySelector('svg[viewBox="0 0 24 24"]')) {
|
| 74 |
+
// For social media links, just prevent default behavior
|
| 75 |
+
return;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
// Get the button text
|
| 79 |
+
const buttonTitle = item.textContent.trim();
|
| 80 |
+
|
| 81 |
+
// Get data attributes from the clicked item
|
| 82 |
+
const imageUrls = [
|
| 83 |
+
'https://picsum.photos/800/600?random=1',
|
| 84 |
+
'https://picsum.photos/800/600?random=2',
|
| 85 |
+
'https://picsum.photos/800/600?random=3',
|
| 86 |
+
'https://picsum.photos/800/600?random=4',
|
| 87 |
+
'https://picsum.photos/800/600?random=5'
|
| 88 |
+
];
|
| 89 |
+
|
| 90 |
+
openCarouselModal(imageUrls, buttonTitle);
|
| 91 |
+
});
|
| 92 |
+
});
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
// Close modal when clicking outside the carousel content
|
| 96 |
+
document.getElementById('carouselModal').addEventListener('click', (e) => {
|
| 97 |
+
if (e.target.classList.contains('carousel-modal')) {
|
| 98 |
+
closeCarouselModal();
|
| 99 |
+
}
|
| 100 |
+
});
|
| 101 |
+
|
| 102 |
+
// Handle keyboard navigation
|
| 103 |
+
document.addEventListener('keydown', (e) => {
|
| 104 |
+
if (!document.getElementById('carouselModal').classList.contains('active')) return;
|
| 105 |
+
|
| 106 |
+
if (e.key === 'Escape') closeCarouselModal();
|
| 107 |
+
if (e.key === 'ArrowLeft') prevSlide();
|
| 108 |
+
if (e.key === 'ArrowRight') nextSlide();
|
| 109 |
+
});
|
| 110 |
+
});
|