(function () { if (window.__cqDropdownPortalInit) return; window.__cqDropdownPortalInit = true; function getDropdownRootFromToggle(toggle) { return toggle.closest('.dropdown, .btn-group, .dropdown-center, .dropup, .dropend, .dropstart'); } function getMenuFromToggle(toggle) { const dropdown = getDropdownRootFromToggle(toggle); if (!dropdown) return null; return dropdown.querySelector(':scope > .dropdown-menu') || dropdown.querySelector('.dropdown-menu'); } function clamp(value, min, max) { return Math.max(min, Math.min(value, max)); } document.addEventListener('shown.bs.dropdown', function (e) { const toggle = e.target; const dropdown = getDropdownRootFromToggle(toggle); if (!dropdown) return; // Allow explicit opt-out for special cases. if (dropdown.getAttribute('data-cq-portal') === '0') return; const menu = getMenuFromToggle(toggle); if (!menu || menu.dataset.cqPortaled === '1') return; menu._cqOriginalParent = menu.parentElement; document.body.appendChild(menu); menu.style.transform = 'none'; menu.style.inset = 'auto'; menu.style.position = 'fixed'; menu.style.zIndex = '2147483647'; menu.style.overflow = 'visible'; const r = toggle.getBoundingClientRect(); const menuRect = menu.getBoundingClientRect(); const menuW = Math.max(menuRect.width || 0, menu.offsetWidth || 0); const viewportW = window.innerWidth || document.documentElement.clientWidth || 0; const edge = 8; // Keep Bootstrap's end-aligned behavior for right-side navbar/user menus. const prefersEnd = menu.classList.contains('dropdown-menu-end'); let left = prefersEnd ? (r.right - menuW) : r.left; left = clamp(left, edge, Math.max(edge, viewportW - menuW - edge)); menu.style.top = (r.bottom + 4) + 'px'; menu.style.left = left + 'px'; if (menu.getAttribute('data-cq-scroll') === '1') { menu.style.maxHeight = '70vh'; menu.style.overflowY = 'auto'; menu.style.overflowX = 'hidden'; } menu.dataset.cqPortaled = '1'; toggle.addEventListener('hidden.bs.dropdown', function () { if (menu.dataset.cqPortaled !== '1' || !menu._cqOriginalParent) return; menu._cqOriginalParent.appendChild(menu); menu.style.position = ''; menu.style.top = ''; menu.style.left = ''; menu.style.zIndex = ''; menu.style.maxHeight = ''; menu.style.overflow = ''; menu.style.overflowY = ''; menu.style.overflowX = ''; menu.style.transform = ''; menu.style.inset = ''; delete menu.dataset.cqPortaled; }, { once: true }); }); })();