Lifestyle Calculators

Fun and useful tools for everyday life, pet care, and entertainment.

tag document.addEventListener('DOMContentLoaded', function() { const searchInput = document.getElementById('calculator-search'); const clearBtn = document.getElementById('clear-search'); const resultsCount = document.getElementById('search-results-count'); const calculatorCards = document.querySelectorAll('.tool-card'); const mainElement = document.querySelector('main'); const footerElement = document.querySelector('footer'); // Function to ensure footer stays at bottom with few/no results function adjustFooterPosition() { const visibleSections = document.querySelectorAll('.our-tools[style*="display: block"]'); // If no sections are visible or very few results if (visibleSections.length === 0) { // Calculate the minimum height needed const windowHeight = window.innerHeight; const mainTop = mainElement.getBoundingClientRect().top; const footerHeight = footerElement.offsetHeight; const minMainHeight = windowHeight - mainTop - footerHeight; // Set min-height to push footer down mainElement.style.minHeight = `${minMainHeight}px`; } else { // Reset if normal content amount mainElement.style.minHeight = 'auto'; } } // Function to toggle clear button visibility function toggleClearButton() { if (searchInput.value.length > 0) { clearBtn.style.display = 'block'; } else { clearBtn.style.display = 'none'; } } // Function to filter calculators based on search term function filterCalculators(searchTerm) { searchTerm = searchTerm.toLowerCase().trim(); let visibleCount = 0; let totalCount = calculatorCards.length; calculatorCards.forEach(card => { const title = card.querySelector('.tool-title').textContent.toLowerCase(); const description = card.querySelector('.tool-description').textContent.toLowerCase(); // Check if card matches search term if (title.includes(searchTerm) || description.includes(searchTerm)) { card.style.display = 'block'; visibleCount++; } else { card.style.display = 'none'; } }); // Update results count if (searchTerm === '') { resultsCount.textContent = ''; } else if (visibleCount === 0) { resultsCount.innerHTML = 'No calculators found. Request a calculator'; } else if (visibleCount === 1) { resultsCount.textContent = '1 calculator found'; } else { resultsCount.textContent = `${visibleCount} calculators found`; } // Check if any calculators are visible in each section document.querySelectorAll('.our-tools').forEach(section => { const sectionCards = section.querySelectorAll('.tool-card'); let sectionVisible = false; sectionCards.forEach(card => { if (card.style.display !== 'none') { sectionVisible = true; } }); // Show/hide section based on visible cards if (sectionVisible) { section.style.display = 'block'; } else { section.style.display = 'none'; } }); // Adjust footer position adjustFooterPosition(); // Toggle clear button toggleClearButton(); } // Event listener for search input searchInput.addEventListener('input', function() { filterCalculators(this.value); }); // Event listener for clear button clearBtn.addEventListener('click', function() { searchInput.value = ''; filterCalculators(''); searchInput.focus(); }); // Clear search on page load searchInput.value = ''; filterCalculators(''); // Handle window resize window.addEventListener('resize', adjustFooterPosition); });