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 5: Linha 5:
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <title>Busca de Imagens por Nome</title>
     <title>Busca de Imagens por Nome</title>
 
</head>
</head>
<body>
<body>
Linha 20: Linha 19:


     <script>
     <script>


        // Elementos do DOM
         const imageSearch = document.getElementById('imageSearch');
         const imageSearch = document.getElementById('imageSearch');
         const dropdown = document.getElementById('dropdown');
         const dropdown = document.getElementById('dropdown');
         const imageContainer = document.getElementById('imageContainer');
         const imageContainer = document.getElementById('imageContainer');


        // Filtro de busca
         imageSearch.addEventListener('input', function() {
         imageSearch.addEventListener('input', function() {
             const searchValue = this.value.trim().toLowerCase();
             const searchValue = this.value.trim().toLowerCase();
Linha 34: Linha 36:
                         const dropdownItem = document.createElement('div');
                         const dropdownItem = document.createElement('div');
                         dropdownItem.classList.add('dropdown-item');
                         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.appendChild(document.createTextNode(imageName));
                       
                         dropdownItem.addEventListener('click', function() {
                         dropdownItem.addEventListener('click', function() {
                             showImageInfo(imageName);
                             showImageInfo(imageName);
Linha 62: Linha 58:
         });
         });


function showImageInfo(imageName) {
        // Exibir informações da imagem
    const imageInfo = imageList[imageName];
        function showImageInfo(imageName) {
    let imagesHtml = `
            const imageInfo = imageList[imageName];
        <div class="image-item">
            let imagesHtml = `
            <img src="${imageInfo.imageUrl}" alt="${imageName}">
                <div class="image-item">
        </div>
                    <div>[[file:${imageInfo.imageUrl}|link]]</div> <!-- Formato MediaWiki -->
        <div class="variations-container">
    `;
 
    imageInfo.variations.forEach((variation, index) => {
        imagesHtml += `
            <div class="variation-item">
                <img src="${variation.additionalImages[0].url}" alt="Variation Image" class="variation-image" data-variation-index="${index}" style="width: ${variation.additionalImages[0].width}px;">
                <div class="swap-button" data-variation-index="${index}"></div><br>
                <div class="image-info">
                    <img src="${variation.descriptionIMG}" alt="Description Image" style="margin-right: 5px; display: inline-block;"> <!-- Exibe a imagem antes da descrição -->
                    <br> ${variation.description} <br> <!-- Descrição após a imagem -->
                    <b>Como Obter</b>: <a href="${variation.obtain.url}" target="_blank">${variation.obtain.text}</a>
                 </div>
                 </div>
            </div>
                <div class="variations-container">
        `;
            `;
    });


    imagesHtml += '</div>';
            imageInfo.variations.forEach((variation, index) => {
                imagesHtml += `
                    <div class="variation-item">
                        <div>[[file:${variation.additionalImages[0].url}|link]]</div> <!-- Formato MediaWiki -->
                        <button class="swap-button" data-variation-index="${index}">Trocar Imagem</button>
                        <div class="image-info">
                            <div>[[file:${variation.descriptionIMG}|link]]</div> <!-- Formato MediaWiki -->
                            <br>${variation.description}<br>
                            <b>Como Obter</b>: <a href="${variation.obtain.url}" target="_blank">${variation.obtain.text}</a>
                        </div>
                    </div>
                `;
            });


    imageContainer.innerHTML = imagesHtml;
            imagesHtml += '</div>';
    imageContainer.classList.remove('hidden');


    // Alternar imagens ao clicar no botão de troca
            imageContainer.innerHTML = imagesHtml;
    const swapButtons = document.querySelectorAll('.swap-button');
            imageContainer.classList.remove('hidden');


    swapButtons.forEach(button => {
            // Alternar imagens ao clicar no botão de troca
        const index = button.getAttribute('data-variation-index');
            const swapButtons = document.querySelectorAll('.swap-button');
        const variation = imageInfo.variations[index];
        let currentImageIndex = 0;


        button.addEventListener('click', () => {
            swapButtons.forEach(button => {
            currentImageIndex = (currentImageIndex + 1) % variation.additionalImages.length;
                const index = button.getAttribute('data-variation-index');
            const variationImage = button.previousElementSibling; // Atualiza a imagem da variação
                const variation = imageInfo.variations[index];
            variationImage.src = variation.additionalImages[currentImageIndex].url;
                let currentImageIndex = 0;
            variationImage.style.width = `${variation.additionalImages[currentImageIndex].width}px`;
        });
    });
}


                button.addEventListener('click', () => {
                    currentImageIndex = (currentImageIndex + 1) % variation.additionalImages.length;
                    const variationDiv = button.previousElementSibling; // Atualiza a imagem no formato MediaWiki
                    variationDiv.innerHTML = `[[file:${variation.additionalImages[currentImageIndex].url}|link]]`;
                });
            });
        }
     </script>
     </script>
</body>
</body>
</html>
</html>

Edição das 18h44min de 22 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 da imagem" autocomplete="off">
   </form>
   <script>

       // Elementos do DOM
       const imageSearch = document.getElementById('imageSearch');
       const dropdown = document.getElementById('dropdown');
       const imageContainer = document.getElementById('imageContainer');
       // Filtro de busca
       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');
                       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';
           }
       });
       // Exibir informações da imagem
       function showImageInfo(imageName) {
           const imageInfo = imageList[imageName];
           let imagesHtml = `
[[file:${imageInfo.imageUrl}|link]]
           `;
           imageInfo.variations.forEach((variation, index) => {
               imagesHtml += `
[[file:${variation.additionalImages[0].url}|link]]
                       <button class="swap-button" data-variation-index="${index}">Trocar Imagem</button>
[[file:${variation.descriptionIMG}|link]]
                           
${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 variationDiv = button.previousElementSibling; // Atualiza a imagem no formato MediaWiki
                   variationDiv.innerHTML = `[[file:${variation.additionalImages[currentImageIndex].url}|link]]`;
               });
           });
       }
   </script>

</body> </html>