nav.html (1188B)
1 <input type="text" id="mkdocs-search-query" placeholder="Search..." /> 2 <div id="mkdocs-search-results"></div> 3 4 5 6 <script> 7 document.addEventListener("DOMContentLoaded", function() { 8 const searchInput = document.getElementById("mkdocs-search-query"); 9 const searchResults = document.getElementById("mkdocs-search-results"); 10 11 // Show search results when input is focused 12 searchInput.addEventListener("focus", function() { 13 searchResults.style.display = "block"; 14 }); 15 16 // Hide search results when clicking outside, but not when clicking a link inside 17 document.addEventListener("click", function(event) { 18 if (!searchInput.contains(event.target) && !searchResults.contains(event.target)) { 19 searchResults.style.display = "none"; 20 } 21 }); 22 23 // Ensure clicking a search result takes the user to the page before hiding 24 searchResults.addEventListener("click", function(event) { 25 if (event.target.tagName === "A") { 26 setTimeout(() => { 27 searchResults.style.display = "none"; // Hide after navigation 28 }, 100); // Small delay to allow navigation to happen 29 } 30 }); 31 }); 32 </script>