mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2024-11-11 02:10:11 +01:00
Merge pull request #1199 from jimdouk/fixFrontEndIssue
Enhance UI Search Functionality in Navbar
This commit is contained in:
commit
f2b7aeeb1c
@ -11,7 +11,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
#searchForm {
|
#searchForm {
|
||||||
width: 200px; /* Adjust this value as needed */
|
width: 300px; /* Adjust this value as needed */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Style the search results to match the navbar */
|
/* Style the search results to match the navbar */
|
||||||
@ -21,6 +21,7 @@
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
max-width: 300px; /* Adjust to your preferred width */
|
max-width: 300px; /* Adjust to your preferred width */
|
||||||
transition: height 0.3s ease; /* Smooth height transition */
|
transition: height 0.3s ease; /* Smooth height transition */
|
||||||
|
padding: 0px !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
#searchResults .dropdown-item {
|
#searchResults .dropdown-item {
|
||||||
|
@ -4,6 +4,7 @@ document.querySelector("#search-icon").addEventListener("click", function (e) {
|
|||||||
var searchBar = document.querySelector("#navbarSearch");
|
var searchBar = document.querySelector("#navbarSearch");
|
||||||
searchBar.classList.toggle("show");
|
searchBar.classList.toggle("show");
|
||||||
});
|
});
|
||||||
|
|
||||||
window.onload = function () {
|
window.onload = function () {
|
||||||
var items = document.querySelectorAll(".dropdown-item, .nav-link");
|
var items = document.querySelectorAll(".dropdown-item, .nav-link");
|
||||||
var dummyContainer = document.createElement("div");
|
var dummyContainer = document.createElement("div");
|
||||||
@ -32,13 +33,15 @@ window.onload = function () {
|
|||||||
|
|
||||||
// Show search results as user types in search box
|
// Show search results as user types in search box
|
||||||
document.querySelector("#navbarSearchInput").addEventListener("input", function (e) {
|
document.querySelector("#navbarSearchInput").addEventListener("input", function (e) {
|
||||||
var searchText = e.target.value.toLowerCase();
|
var searchText = e.target.value.trim().toLowerCase(); // Trim whitespace and convert to lowercase
|
||||||
var items = document.querySelectorAll(".dropdown-item, .nav-link");
|
var items = document.querySelectorAll(".dropdown-item, .nav-link");
|
||||||
var resultsBox = document.querySelector("#searchResults");
|
var resultsBox = document.querySelector("#searchResults");
|
||||||
|
|
||||||
// Clear any previous results
|
// Clear any previous results
|
||||||
resultsBox.innerHTML = "";
|
resultsBox.innerHTML = "";
|
||||||
|
|
||||||
|
// Check if search text is not empty
|
||||||
|
if (searchText !== "") {
|
||||||
items.forEach(function (item) {
|
items.forEach(function (item) {
|
||||||
var titleElement = item.querySelector(".icon-text");
|
var titleElement = item.querySelector(".icon-text");
|
||||||
var iconElement = item.querySelector(".icon");
|
var iconElement = item.querySelector(".icon");
|
||||||
@ -49,7 +52,7 @@ document.querySelector("#navbarSearchInput").addEventListener("input", function
|
|||||||
var title = titleElement.innerText;
|
var title = titleElement.innerText;
|
||||||
if (
|
if (
|
||||||
(title.toLowerCase().indexOf(searchText) !== -1 || tags.toLowerCase().indexOf(searchText) !== -1) &&
|
(title.toLowerCase().indexOf(searchText) !== -1 || tags.toLowerCase().indexOf(searchText) !== -1) &&
|
||||||
!resultsBox.querySelector(`a[href="${item.getAttribute("href")}"]`)
|
!resultsBox.querySelector(`a[href="${itemHref}"]`)
|
||||||
) {
|
) {
|
||||||
var result = document.createElement("a");
|
var result = document.createElement("a");
|
||||||
result.href = itemHref;
|
result.href = itemHref;
|
||||||
@ -70,6 +73,7 @@ document.querySelector("#navbarSearchInput").addEventListener("input", function
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Set the width of the search results box to the maximum width
|
// Set the width of the search results box to the maximum width
|
||||||
resultsBox.style.width = window.navItemMaxWidth + "px";
|
resultsBox.style.width = window.navItemMaxWidth + "px";
|
||||||
|
Loading…
Reference in New Issue
Block a user