Widget:Test: mudanças entre as edições

De PokeXGames
Ir para navegação Ir para pesquisar
Sem resumo de edição
Sem resumo de edição
Linha 62: Linha 62:
         });
         });


         document.addEventListener('keydown', function(event) {
         document.addEventListener('keydown', function (event) {
            if (event.key === 'ArrowDown') {
    if (dropdown.style.display === 'none' || !dropdown.childNodes.length) {
                const activeItem = document.querySelector('.dropdown-item.active');
        return; // Não faça nada se o dropdown estiver escondido ou vazio
                if (activeItem) {
    }
                    activeItem.classList.remove('active');
 
                    const nextItem = activeItem.nextElementSibling;
    if (event.key === 'ArrowDown') {
                    if (nextItem) {
        const activeItem = document.querySelector('.dropdown-item.active');
                        nextItem.classList.add('active');
        if (activeItem) {
                    } else {
            activeItem.classList.remove('active');
                        dropdown.firstChild.classList.add('active');
            const nextItem = activeItem.nextElementSibling || dropdown.firstChild;
                    }
            nextItem.classList.add('active');
                } else {
            nextItem.scrollIntoView({ block: "nearest" }); // Garante que o item fique visível
                    dropdown.firstChild.classList.add('active');
        } else {
                }
            dropdown.firstChild.classList.add('active');
            } else if (event.key === 'ArrowUp') {
            dropdown.firstChild.scrollIntoView({ block: "nearest" });
                const activeItem = document.querySelector('.dropdown-item.active');
        }
                if (activeItem) {
        event.preventDefault(); // Evita rolagem da página
                    activeItem.classList.remove('active');
    } else if (event.key === 'ArrowUp') {
                    const previousItem = activeItem.previousElementSibling;
        const activeItem = document.querySelector('.dropdown-item.active');
                    if (previousItem) {
        if (activeItem) {
                        previousItem.classList.add('active');
            activeItem.classList.remove('active');
                    } else {
            const previousItem = activeItem.previousElementSibling || dropdown.lastChild;
                        dropdown.lastChild.classList.add('active');
            previousItem.classList.add('active');
                    }
            previousItem.scrollIntoView({ block: "nearest" });
                } else {
        } else {
                    dropdown.lastChild.classList.add('active');
            dropdown.lastChild.classList.add('active');
                }
            dropdown.lastChild.scrollIntoView({ block: "nearest" });
            } else if (event.key === 'Enter') {
        }
                const activeItem = document.querySelector('.dropdown-item.active');
        event.preventDefault();
                if (activeItem) {
    } else if (event.key === 'Enter') {
                    activeItem.click();
        const activeItem = document.querySelector('.dropdown-item.active');
                }
        if (activeItem) {
            }
            activeItem.click();
        });
        }
        event.preventDefault();
    }
});
 


function showImageInfo(imageName) {
function showImageInfo(imageName) {

Edição das 23h49min de 26 de dezembro de 2024

<!DOCTYPE html> <html lang="pt-BR"> <head>

   <meta charset="UTF-8">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <title>Busca de Imagens por Nome</title>
 

</head> <body>

   <form id="imageForm">
           <input type="text" id="imageSearch" placeholder="Digite o nome do Pokémon" autocomplete="off">
   </form>
   <script>
       const imageSearch = document.getElementById('imageSearch');
       const dropdown = document.getElementById('dropdown');
       const imageContainer = document.getElementById('imageContainer');
       imageSearch.addEventListener('input', function() {
           const searchValue = this.value.trim().toLowerCase();
           dropdown.innerHTML = ;
           if (searchValue) {
               Object.keys(imageList).forEach(imageName => {
                   if (imageName.toLowerCase().includes(searchValue)) {
                       const dropdownItem = document.createElement('div');
                       dropdownItem.classList.add('dropdown-item');
                       
                       const imgElement = document.createElement('img');
                       imgElement.src = imageList[imageName].imageUrl;
                       imgElement.alt = imageName;
                       
                       dropdownItem.appendChild(imgElement);
                       dropdownItem.appendChild(document.createTextNode(imageName));
                       
                       dropdownItem.addEventListener('click', function() {
                           showImageInfo(imageName);
                           dropdown.style.display = 'none';
                       });
                       dropdown.appendChild(dropdownItem);
                   }
               });
               dropdown.style.display = dropdown.childNodes.length ? 'block' : 'none';
           } else {
               dropdown.style.display = 'none';
           }
       });
       document.addEventListener('click', function(event) {
           if (!imageSearch.contains(event.target) && !dropdown.contains(event.target)) {
               dropdown.style.display = 'none';
           }
       });
       document.addEventListener('keydown', function (event) {
   if (dropdown.style.display === 'none' || !dropdown.childNodes.length) {
       return; // Não faça nada se o dropdown estiver escondido ou vazio
   }
   if (event.key === 'ArrowDown') {
       const activeItem = document.querySelector('.dropdown-item.active');
       if (activeItem) {
           activeItem.classList.remove('active');
           const nextItem = activeItem.nextElementSibling || dropdown.firstChild;
           nextItem.classList.add('active');
           nextItem.scrollIntoView({ block: "nearest" }); // Garante que o item fique visível
       } else {
           dropdown.firstChild.classList.add('active');
           dropdown.firstChild.scrollIntoView({ block: "nearest" });
       }
       event.preventDefault(); // Evita rolagem da página
   } else if (event.key === 'ArrowUp') {
       const activeItem = document.querySelector('.dropdown-item.active');
       if (activeItem) {
           activeItem.classList.remove('active');
           const previousItem = activeItem.previousElementSibling || dropdown.lastChild;
           previousItem.classList.add('active');
           previousItem.scrollIntoView({ block: "nearest" });
       } else {
           dropdown.lastChild.classList.add('active');
           dropdown.lastChild.scrollIntoView({ block: "nearest" });
       }
       event.preventDefault();
   } else if (event.key === 'Enter') {
       const activeItem = document.querySelector('.dropdown-item.active');
       if (activeItem) {
           activeItem.click();
       }
       event.preventDefault();
   }

});


function showImageInfo(imageName) {

   const imageInfo = imageList[imageName];
   let imagesHtml = `
           <img src="${imageInfo.imageUrl}" alt="${imageName}">
   `;
   imageInfo.variations.forEach((variation, index) => {
       imagesHtml += `
            <img src="${variation.additionalImages[0].url}" alt="Variation Image" class="variation-image" data-variation-index="${index}" style="width: ${variation.additionalImages[0].width}px;">

                   <img src="${variation.descriptionIMG}" alt="Description Image" style="margin-right: 5px; display: inline-block;"> 
                   
${variation.description}
Como Obter: <a href="${variation.obtain.url}" target="_blank">${variation.obtain.text}</a>
       `;
   });
imagesHtml += `

`;

   imageContainer.innerHTML = imagesHtml;
   imageContainer.classList.remove('hidden');
   // Alternar imagens ao clicar no botão de troca
   const swapButtons = document.querySelectorAll('.swap-button');
   swapButtons.forEach(button => {
       const index = button.getAttribute('data-variation-index');
       const variation = imageInfo.variations[index];
       let currentImageIndex = 0;
       button.addEventListener('click', () => {
           currentImageIndex = (currentImageIndex + 1) % variation.additionalImages.length;
           const variationImage = button.previousElementSibling; // Atualiza a imagem da variação
           variationImage.src = variation.additionalImages[currentImageIndex].url;
           variationImage.style.width = `${variation.additionalImages[currentImageIndex].width}px`;
       });
   });

}

   </script>

</body> </html>