2025-04-08 06:37:14 +04:00
|
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
|
|
|
// Gestion du menu mobile
|
|
|
|
|
const mobileMenuToggle = document.querySelector('.mobile-menu-toggle');
|
2025-04-08 06:51:33 +04:00
|
|
|
const mobileMenu = document.querySelector('.mobile-menu');
|
2025-04-08 06:37:14 +04:00
|
|
|
const mobileMenuClose = document.querySelector('.mobile-menu-close');
|
|
|
|
|
|
|
|
|
|
if (mobileMenuToggle) {
|
|
|
|
|
mobileMenuToggle.addEventListener('click', function() {
|
2025-04-08 06:51:33 +04:00
|
|
|
mobileMenu.classList.add('active');
|
2025-04-08 06:37:14 +04:00
|
|
|
document.body.style.overflow = 'hidden'; // Empêche le défilement de la page
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mobileMenuClose) {
|
|
|
|
|
mobileMenuClose.addEventListener('click', function() {
|
2025-04-08 06:51:33 +04:00
|
|
|
mobileMenu.classList.remove('active');
|
2025-04-08 06:37:14 +04:00
|
|
|
document.body.style.overflow = ''; // Réactive le défilement
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-08 06:51:33 +04:00
|
|
|
// Gestion du mode sombre
|
|
|
|
|
const darkModeToggle = document.querySelector('.dark-mode-toggle');
|
|
|
|
|
const body = document.body;
|
|
|
|
|
|
|
|
|
|
if (darkModeToggle) {
|
|
|
|
|
darkModeToggle.addEventListener('click', function() {
|
|
|
|
|
body.classList.toggle('dark-mode');
|
|
|
|
|
|
|
|
|
|
// Changer l'icône
|
|
|
|
|
const icon = darkModeToggle.querySelector('i');
|
|
|
|
|
if (body.classList.contains('dark-mode')) {
|
|
|
|
|
icon.classList.remove('fa-moon');
|
|
|
|
|
icon.classList.add('fa-sun');
|
|
|
|
|
} else {
|
|
|
|
|
icon.classList.remove('fa-sun');
|
|
|
|
|
icon.classList.add('fa-moon');
|
2025-04-08 06:37:14 +04:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-08 06:51:33 +04:00
|
|
|
// Gestion des carousels
|
|
|
|
|
const carousels = document.querySelectorAll('.carousel');
|
|
|
|
|
|
|
|
|
|
carousels.forEach(carousel => {
|
|
|
|
|
const container = carousel.querySelector('.carousel-container');
|
|
|
|
|
const dots = carousel.querySelectorAll('.carousel-dot');
|
|
|
|
|
const items = carousel.querySelectorAll('.carousel-item');
|
|
|
|
|
|
|
|
|
|
if (dots.length > 0 && items.length > 0) {
|
|
|
|
|
dots.forEach((dot, index) => {
|
|
|
|
|
dot.addEventListener('click', function() {
|
|
|
|
|
// Calculer la distance à translater
|
|
|
|
|
const itemWidth = items[0].offsetWidth + parseInt(getComputedStyle(items[0]).marginRight);
|
|
|
|
|
const newTransform = -index * itemWidth;
|
|
|
|
|
|
|
|
|
|
// Appliquer la transformation
|
|
|
|
|
container.style.transform = `translateX(${newTransform}px)`;
|
|
|
|
|
|
|
|
|
|
// Mettre à jour les dots
|
|
|
|
|
dots.forEach(d => d.classList.remove('active'));
|
|
|
|
|
dot.classList.add('active');
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Gestion des clics sur les vidéos
|
2025-04-08 10:49:46 +04:00
|
|
|
function initVideoCardClicks() {
|
|
|
|
|
const videoCards = document.querySelectorAll('.video-card');
|
|
|
|
|
|
|
|
|
|
videoCards.forEach(card => {
|
|
|
|
|
if (!card.hasAttribute('data-click-initialized')) {
|
|
|
|
|
card.setAttribute('data-click-initialized', 'true');
|
|
|
|
|
card.addEventListener('click', function() {
|
|
|
|
|
const videoId = this.dataset.videoId;
|
|
|
|
|
if (videoId) {
|
|
|
|
|
window.location.href = 'video.php?id=' + videoId;
|
|
|
|
|
}
|
|
|
|
|
});
|
2025-04-08 06:37:14 +04:00
|
|
|
}
|
|
|
|
|
});
|
2025-04-08 10:49:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Initialiser les clics sur les vidéos existantes
|
|
|
|
|
initVideoCardClicks();
|
2025-04-08 06:37:14 +04:00
|
|
|
|
|
|
|
|
// Lazy loading des images
|
2025-04-08 10:49:46 +04:00
|
|
|
function initLazyLoading() {
|
|
|
|
|
if ('IntersectionObserver' in window) {
|
|
|
|
|
const imageObserver = new IntersectionObserver((entries, observer) => {
|
|
|
|
|
entries.forEach(entry => {
|
|
|
|
|
if (entry.isIntersecting) {
|
|
|
|
|
const img = entry.target;
|
|
|
|
|
const src = img.getAttribute('data-src');
|
|
|
|
|
if (src) {
|
|
|
|
|
img.src = src;
|
|
|
|
|
img.removeAttribute('data-src');
|
|
|
|
|
}
|
|
|
|
|
observer.unobserve(img);
|
2025-04-08 06:37:14 +04:00
|
|
|
}
|
2025-04-08 10:49:46 +04:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
document.querySelectorAll('img[data-src]').forEach(img => {
|
|
|
|
|
imageObserver.observe(img);
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
// Fallback pour les navigateurs qui ne supportent pas IntersectionObserver
|
|
|
|
|
document.querySelectorAll('img[data-src]').forEach(img => {
|
|
|
|
|
const src = img.getAttribute('data-src');
|
|
|
|
|
if (src) {
|
|
|
|
|
img.src = src;
|
|
|
|
|
img.removeAttribute('data-src');
|
2025-04-08 06:37:14 +04:00
|
|
|
}
|
|
|
|
|
});
|
2025-04-08 10:49:46 +04:00
|
|
|
}
|
2025-04-08 06:37:14 +04:00
|
|
|
}
|
|
|
|
|
|
2025-04-08 10:49:46 +04:00
|
|
|
// Initialiser le lazy loading
|
|
|
|
|
initLazyLoading();
|
|
|
|
|
|
2025-04-08 06:51:33 +04:00
|
|
|
// Gestion des boutons "Voir plus"
|
|
|
|
|
const viewMoreButtons = document.querySelectorAll('.view-more');
|
2025-04-08 06:37:14 +04:00
|
|
|
|
2025-04-08 06:51:33 +04:00
|
|
|
viewMoreButtons.forEach(button => {
|
2025-04-08 10:49:46 +04:00
|
|
|
// Déterminer le type de vidéos à charger
|
|
|
|
|
const section = button.closest('.video-section');
|
|
|
|
|
const sectionTitle = section.querySelector('.section-title').textContent.trim().toLowerCase();
|
|
|
|
|
const videoGrid = section.querySelector('.video-grid');
|
|
|
|
|
let videoType = '';
|
|
|
|
|
|
|
|
|
|
if (sectionTitle.includes('dernières')) {
|
|
|
|
|
videoType = 'recent';
|
|
|
|
|
} else if (sectionTitle.includes('tendances')) {
|
|
|
|
|
videoType = 'trending';
|
|
|
|
|
} else if (sectionTitle.includes('indépendance')) {
|
|
|
|
|
videoType = 'independence';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Stocker le numéro de page actuel
|
|
|
|
|
button.dataset.page = '1';
|
|
|
|
|
|
2025-04-08 06:51:33 +04:00
|
|
|
button.addEventListener('click', function() {
|
2025-04-08 10:49:46 +04:00
|
|
|
const page = parseInt(this.dataset.page);
|
|
|
|
|
|
|
|
|
|
// Changer le texte du bouton pendant le chargement
|
|
|
|
|
button.textContent = 'Chargement...';
|
|
|
|
|
button.disabled = true;
|
|
|
|
|
|
|
|
|
|
// Faire la requête AJAX
|
|
|
|
|
fetch(`ajax/load-more-videos.php?type=${videoType}&page=${page}`, {
|
|
|
|
|
headers: {
|
|
|
|
|
'X-Requested-With': 'XMLHttpRequest'
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.then(response => response.json())
|
|
|
|
|
.then(data => {
|
|
|
|
|
if (data.success) {
|
|
|
|
|
// Ajouter les nouvelles vidéos à la grille
|
|
|
|
|
const tempDiv = document.createElement('div');
|
|
|
|
|
tempDiv.innerHTML = data.html;
|
|
|
|
|
|
|
|
|
|
// Ajouter chaque vidéo à la grille
|
|
|
|
|
while (tempDiv.firstChild) {
|
|
|
|
|
videoGrid.appendChild(tempDiv.firstChild);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Mettre à jour le numéro de page
|
|
|
|
|
this.dataset.page = data.page + 1;
|
|
|
|
|
|
|
|
|
|
// Réinitialiser le texte du bouton
|
|
|
|
|
button.textContent = 'Voir plus';
|
|
|
|
|
button.disabled = false;
|
|
|
|
|
|
|
|
|
|
// Si plus de vidéos à charger, masquer le bouton
|
|
|
|
|
if (!data.hasMore) {
|
|
|
|
|
button.style.display = 'none';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Initialiser les clics sur les nouvelles vidéos
|
|
|
|
|
initVideoCardClicks();
|
|
|
|
|
// Initialiser le lazy loading pour les nouvelles images
|
|
|
|
|
initLazyLoading();
|
|
|
|
|
} else {
|
|
|
|
|
// En cas d'erreur, afficher un message et réactiver le bouton
|
|
|
|
|
console.error('Erreur lors du chargement des vidéos:', data.error);
|
|
|
|
|
button.textContent = 'Voir plus';
|
|
|
|
|
button.disabled = false;
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch(error => {
|
|
|
|
|
console.error('Erreur lors de la requête AJAX:', error);
|
|
|
|
|
button.textContent = 'Voir plus';
|
|
|
|
|
button.disabled = false;
|
|
|
|
|
});
|
2025-04-08 06:51:33 +04:00
|
|
|
});
|
|
|
|
|
});
|
2025-04-08 06:37:14 +04:00
|
|
|
});
|