Implement DuckDuckGo search functionality with button and Enter key support; update styles for search input and button

This commit is contained in:
MayaChat
2025-11-24 13:05:22 -05:00
parent 216b655dec
commit 960ec53e4a
3 changed files with 38 additions and 6 deletions

View File

@@ -1,6 +1,32 @@
// Search functionality
(function initSearch(){
const searchInput = document.getElementById('search-input');
const ddgButton = document.getElementById('ddg-search-btn');
// DuckDuckGo search function
function searchDuckDuckGo() {
const query = searchInput.value.trim();
if (query) {
const ddgUrl = `https://duckduckgo.com/?q=${encodeURIComponent(query)}`;
window.open(ddgUrl, '_blank', 'noopener,noreferrer');
}
}
// Add click handler for DDG button
if (ddgButton) {
ddgButton.addEventListener('click', (e) => {
e.preventDefault();
searchDuckDuckGo();
});
}
// Add Enter key handler for DDG search
searchInput.addEventListener('keydown', (e) => {
if (e.key === 'Enter') {
e.preventDefault();
searchDuckDuckGo();
}
});
// Wait for services to load
const checkServicesLoaded = setInterval(() => {
@@ -32,7 +58,7 @@
// Hide empty groups
groupSections.forEach(section => {
const visibleCards = section.querySelectorAll('.card:not([style*="display: none"])');
const visibleCards = section.querySelectorAll('.service-card:not([style*="display: none"])');
section.style.display = visibleCards.length > 0 ? '' : 'none';
});
@@ -42,7 +68,7 @@
if(visibleCount === 0 && searchTerm !== ''){
const msg = document.createElement('p');
msg.className = 'notes no-results';
msg.textContent = `No services found matching "${e.target.value}"`;
msg.textContent = `No services found matching "${e.target.value}". Press Enter to search on DuckDuckGo.`;
container.appendChild(msg);
}
});