// Utilise le helper domReady exposé globalement par core/dom-ready.js (function() { var domReady = (window.MG && window.MG.domReady) || window.__MG_domReady || function(cb){ if (document.readyState==='loading') document.addEventListener('DOMContentLoaded', cb); else cb(); }; function initDropdowns() { const toggles = document.querySelectorAll('[data-bs-toggle="dropdown"]'); if (!toggles.length) { return; } if (window.bootstrap && window.bootstrap.Dropdown) { var count = 0; toggles.forEach(function(toggle) { try { if (!window.bootstrap.Dropdown.getInstance(toggle)) { new window.bootstrap.Dropdown(toggle); count++; } else { } } catch (err) { // swallow initialization errors silently } }); return; // Si Bootstrap fonctionne, ne pas activer le fallback } else { // fallback will be used } // Fallback manuel si Bootstrap absent function closeAll() { document.querySelectorAll('.dropdown-menu.show').forEach(function(menu) { menu.classList.remove('show'); }); toggles.forEach(function(t) { t.setAttribute('aria-expanded', 'false'); }); } toggles.forEach(function(toggle) { toggle.addEventListener('click', function(e) { e.preventDefault(); e.stopPropagation(); const parent = toggle.closest('.dropdown') || toggle.parentElement; const menu = parent ? parent.querySelector('.dropdown-menu') : null; if (!menu) return; const isOpen = menu.classList.contains('show'); closeAll(); if (!isOpen) { menu.classList.add('show'); toggle.setAttribute('aria-expanded', 'true'); adjustDropdownMenu(menu, toggle); } }); }); document.addEventListener('click', function() { closeAll(); }); function adjustDropdownMenu(menu, toggle) { if (!menu) return; menu.style.maxHeight = ''; menu.classList.remove('dropdown-menu-end'); const rect = menu.getBoundingClientRect(); const vw = Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0); const vh = Math.max(document.documentElement.clientHeight || 0, window.innerHeight || 0); if (rect.right > vw - 8) { menu.classList.add('dropdown-menu-end'); } const rect2 = menu.getBoundingClientRect(); if (rect2.bottom > vh - 8) { const available = vh - 16 - rect2.top; if (available > 100) { menu.style.maxHeight = available + 'px'; menu.style.overflowY = 'auto'; } } } } domReady(function() { const loadBtn = document.getElementById('loadBtn'); if (loadBtn) { loadBtn.addEventListener('click', function(e) { e.preventDefault(); window.location.href = '/projects'; }); } // Initialiser les dropdowns immédiatement si Bootstrap est disponible if (window.bootstrap && window.bootstrap.Dropdown) { initDropdowns(); } else { // Si Bootstrap n'est pas encore chargé, attendre avec plusieurs tentatives var attempts = 0; var checkBootstrap = setInterval(function() { attempts++; if (window.bootstrap && window.bootstrap.Dropdown) { clearInterval(checkBootstrap); initDropdowns(); } else if (attempts >= 20) { clearInterval(checkBootstrap); initDropdowns(); // Tenter quand même avec le fallback } }, 50); } }); // Exposer une fonction globale pour réinitialiser les dropdowns window.initDropdownsManually = function() { console.log('Manual dropdown initialization called'); initDropdowns(); }; })();