document.addEventListener(‘DOMContentLoaded’, function() {
// Função para abrir o modal
function openSearchModal() {
document.getElementById(‘search-modal’).style.display = ‘flex’;
document.querySelector(‘.search-form-container input[type=”search”]’).focus();
}
// Função para fechar o modal
function closeSearchModal() {
document.getElementById(‘search-modal’).style.display = ‘none’;
}
// Abrir o modal ao clicar no ícone de busca
document.getElementById(‘search-icon-box’).addEventListener(‘click’, function() {
openSearchModal();
});
// Fechar o modal ao clicar no X
document.querySelector(‘.close-modal’).addEventListener(‘click’, function() {
closeSearchModal();
});
// Fechar o modal ao clicar fora da área de busca
document.getElementById(‘search-modal’).addEventListener(‘click’, function(e) {
if (e.target === this) {
closeSearchModal();
}
});
// Evitar que cliques dentro do conteúdo do modal fechem o modal
document.querySelector(‘.search-modal-content’).addEventListener(‘click’, function(e) {
e.stopPropagation();
});
// Fechar o modal pressionando ESC
document.addEventListener(‘keyup’, function(e) {
if (e.key === “Escape”) {
closeSearchModal();
}
});
// Configurar o formulário de busca para enviar para a URL correta
document.getElementById(‘search-form’).addEventListener(‘submit’, function(e) {
e.preventDefault();
var searchTerm = this.querySelector(‘input[type=”search”]’).val();
window.location.href = window.location.origin + ‘/?s=’ + encodeURIComponent(searchTerm);
});
// Adicionar evento de clique diretamente ao botão
document.querySelector(‘.search-form-container button’).addEventListener(‘click’, function(e) {
e.preventDefault();
var searchTerm = document.querySelector(‘.search-form-container input[type=”search”]’).value;
window.location.href = window.location.origin + ‘/?s=’ + encodeURIComponent(searchTerm);
});
});

