mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2025-08-06 13:48:58 +02:00
add null check dropdown
This commit is contained in:
parent
64d8ef4a39
commit
4149804183
@ -88,49 +88,49 @@ const searchInput = document.getElementById('navbarSearchInput');
|
|||||||
|
|
||||||
// Check if elements exist before proceeding
|
// Check if elements exist before proceeding
|
||||||
if (searchDropdown && searchInput) {
|
if (searchDropdown && searchInput) {
|
||||||
const dropdownMenu = searchDropdown.querySelector('.dropdown-menu');
|
const dropdownMenu = searchDropdown.querySelector('.dropdown-menu');
|
||||||
|
|
||||||
// Create a single dropdown instance
|
// Create a single dropdown instance
|
||||||
const dropdownInstance = new bootstrap.Dropdown(searchDropdown);
|
const dropdownInstance = new bootstrap.Dropdown(searchDropdown);
|
||||||
|
|
||||||
// Handle click for mobile
|
// Handle click for mobile
|
||||||
searchDropdown.addEventListener('click', function (e) {
|
searchDropdown.addEventListener('click', function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const isOpen = dropdownMenu.classList.contains('show');
|
const isOpen = dropdownMenu.classList.contains('show');
|
||||||
// Close all other open dropdowns
|
// Close all other open dropdowns
|
||||||
document.querySelectorAll('.navbar-nav .dropdown-menu.show').forEach((menu) => {
|
document.querySelectorAll('.navbar-nav .dropdown-menu.show').forEach((menu) => {
|
||||||
if (menu !== dropdownMenu) {
|
if (menu !== dropdownMenu) {
|
||||||
const parentDropdown = menu.closest('.dropdown');
|
const parentDropdown = menu.closest('.dropdown');
|
||||||
if (parentDropdown) {
|
if (parentDropdown) {
|
||||||
const parentToggle = parentDropdown.querySelector('[data-bs-toggle="dropdown"]');
|
const parentToggle = parentDropdown.querySelector('[data-bs-toggle="dropdown"]');
|
||||||
if (parentToggle) {
|
if (parentToggle) {
|
||||||
let instance = bootstrap.Dropdown.getInstance(parentToggle);
|
let instance = bootstrap.Dropdown.getInstance(parentToggle);
|
||||||
if (!instance) {
|
if (!instance) {
|
||||||
instance = new bootstrap.Dropdown(parentToggle);
|
instance = new bootstrap.Dropdown(parentToggle);
|
||||||
}
|
|
||||||
instance.hide();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
instance.hide();
|
||||||
if (!isOpen) {
|
}
|
||||||
dropdownInstance.show();
|
|
||||||
setTimeout(() => searchInput.focus(), 150);
|
|
||||||
} else {
|
|
||||||
dropdownInstance.hide();
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
if (!isOpen) {
|
||||||
|
dropdownInstance.show();
|
||||||
|
setTimeout(() => searchInput.focus(), 150);
|
||||||
|
} else {
|
||||||
|
dropdownInstance.hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Hide dropdown if it's open and user clicks outside
|
// Hide dropdown if it's open and user clicks outside
|
||||||
document.addEventListener('click', function(e) {
|
document.addEventListener('click', function (e) {
|
||||||
if (!searchDropdown.contains(e.target) && dropdownMenu.classList.contains('show')) {
|
if (dropdownMenu && !searchDropdown.contains(e.target) && dropdownMenu.classList.contains('show')) {
|
||||||
dropdownInstance.hide();
|
dropdownInstance.hide();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Keep dropdown open if search input is clicked
|
// Keep dropdown open if search input is clicked
|
||||||
searchInput.addEventListener('click', function (e) {
|
searchInput.addEventListener('click', function (e) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user