mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2025-08-11 13:48:37 +02:00
Update search.js
This commit is contained in:
parent
b5f0611bd4
commit
925d4c54b6
@ -82,13 +82,20 @@ document.querySelector("#navbarSearchInput").addEventListener("input", function
|
|||||||
resultsBox.style.width = window.navItemMaxWidth + "px";
|
resultsBox.style.width = window.navItemMaxWidth + "px";
|
||||||
});
|
});
|
||||||
|
|
||||||
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
|
const searchDropdown = document.getElementById('searchDropdown');
|
||||||
|
const searchInput = document.getElementById('navbarSearchInput');
|
||||||
|
|
||||||
const searchDropdown = document.getElementById('searchDropdown');
|
// Check if elements exist before proceeding
|
||||||
const searchInput = document.getElementById('navbarSearchInput');
|
if (!searchDropdown || !searchInput) {
|
||||||
|
console.warn('Search dropdown or input not found. Skipping initialization.');
|
||||||
// Check if elements exist before proceeding
|
return;
|
||||||
if (searchDropdown && searchInput) {
|
}
|
||||||
const dropdownMenu = searchDropdown.querySelector('.dropdown-menu');
|
const dropdownMenu = searchDropdown.querySelector('.dropdown-menu');
|
||||||
|
if (!dropdownMenu) {
|
||||||
|
console.warn('Dropdown menu not found within the search dropdown. Skipping initialization.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Create a single dropdown instance
|
// Create a single dropdown instance
|
||||||
const dropdownInstance = new bootstrap.Dropdown(searchDropdown);
|
const dropdownInstance = new bootstrap.Dropdown(searchDropdown);
|
||||||
@ -123,7 +130,7 @@ if (searchDropdown && searchInput) {
|
|||||||
|
|
||||||
// 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 (dropdownMenu && !searchDropdown.contains(e.target) && dropdownMenu.classList.contains('show')) {
|
if (!searchDropdown.contains(e.target) && dropdownMenu.classList.contains('show')) {
|
||||||
dropdownInstance.hide();
|
dropdownInstance.hide();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -133,4 +140,4 @@ if (searchDropdown && searchInput) {
|
|||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user