Widget:Test3

De PokeXGames
Revisão de 03h30min de 4 de setembro de 2024 por Renee (discussão | contribs)
Ir para navegação Ir para pesquisar

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

   <meta charset="UTF-8">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <title>Seleção e Exibição de Imagens</title>
   <style>
       .hidden {
           display: none;
       }
       .image-container {
           display: flex;
           flex-wrap: wrap;
           justify-content: center;
           gap: 10px;
       }
       .image-item {
           flex: 1 0 30%;
           text-align: center;
       }
       .image-item img {
           max-width: 100%;
           height: auto;
           margin-bottom: 5px;
       }
       .input-group {
           margin: 10px 0;
       }
       .maps__select {
           width: 100%;
           padding: 10px;
           font-size: 16px;
           border-radius: 5px;
           border: 1px solid #ccc;
       }
       .tag-button {
           background-color: #f0f0f0;
           border: 1px solid #ccc;
           border-radius: 20px;
           padding: 5px 15px;
           font-size: 14px;
           cursor: pointer;
           margin: 5px;
           transition: background-color 0.3s, color 0.3s;
       }
       .tag-button.selected {
           background-color: #007bff;
           color: #fff;
       }
       .tag-button.disabled {
           background-color: #e0e0e0;
           color: #a0a0a0;
           border-color: #d0d0d0;
           cursor: not-allowed;
       }
   </style>

</head> <body>

   <form id="mapForm">
           <select id="mapType" class="maps__select">
               <option value="">Selecione um mapa</option>
               <option value="1">Mapa Vermelho</option>
               <option value="2">Mapa Verde</option>
               <option value="3">Mapa Roxo</option>
           </select>
           <label for="mapType">Tipo de Mapa</label>
           <input type="checkbox" id="enableFilter">
           <label for="enableFilter">Ativar filtro</label>
   </form>
   <script>
       const specificOptions = {
           1: { 
               'Areia': [ 
                   { id: '101', local: 'Green Island', coordinates: '3780, 3326, 7', tags: ['Areia'], imageUrl: 'https://wiki.pokexgames.com/images/4/4c/Mapas_de_ADV_VERMELHO_-_3780%2C_3326%2C_7.webp' }, 
                   { id: '102', local: 'Wildwind Island', coordinates: '3969, 3300, 7', tags: ['Areia'], imageUrl: 'https://wiki.pokexgames.com/images/5/58/Mapas_de_ADV_VERMELHO_-_3969%2C_3300%2C_7.webp' } 
               ],
               'Gelo': [ 
                   { id: '103', local: 'Snowy Mountain', coordinates: '3500, 3400, 7', tags: ['Gelo'], imageUrl: 'https://wiki.pokexgames.com/images/7/74/Mapas_de_ADV_VERDE_-_3500%2C_3400%2C_7.webp' } 
               ]
           },
           2: { 
               'Grama': [ 
                   { id: '104', local: 'Green Forest', coordinates: '3000, 3100, 7', tags: ['Grama'], imageUrl: 'https://wiki.pokexgames.com/images/9/94/Mapas_de_ADV_VERDE_-_3000%2C_3100%2C_7.webp' } 
               ],
               'Pedra': [ 
                   { id: '105', local: 'Rocky Terrain', coordinates: '3200, 3400, 7', tags: ['Pedra'], imageUrl: 'https://wiki.pokexgames.com/images/1/12/Mapas_de_ADV_VERDE_-_3200%2C_3400%2C_7.webp' } 
               ]
           }
       };
       const tagButtonsContainer = document.getElementById('tagButtonsContainer');
       const filterButton = document.getElementById('filterButton');
       const filterOption = document.getElementById('filterOption');
       const searchIds = document.getElementById('searchIds');
       const imageContainer = document.getElementById('imageContainer');
       const mapType = document.getElementById('mapType');
       const specificOption = document.getElementById('specificOption');
       const enableFilter = document.getElementById('enableFilter');
       const filterSection = document.getElementById('filterSection');
       const mapTypeSelection = document.getElementById('mapTypeSelection');
       const specificOptionsSection = document.getElementById('specificOptions');
       const tags = ['Areia', 'Gelo', 'Grama', 'Pedra', 'Subaquático', 'Terra', 'Pisos'];
       function renderTagButtons() {
           tags.forEach(tag => {
               const button = document.createElement('button');
               button.className = 'tag-button';
               button.dataset.value = tag;
               button.textContent = tag;
               button.addEventListener('click', function() {
                   this.classList.toggle('selected');
                   filterImages();
               });
               tagButtonsContainer.appendChild(button);
           });
       }
       function filterImages() {
           imageContainer.innerHTML = ;
           const selectedMapType = mapType.value;
           const selectedLocal = specificOption.value;
           const filterByNumber = filterOption.value === 'number';
           const filterByTag = filterOption.value === 'tag';
           let selectedTags = [];
           document.querySelectorAll('.tag-button.selected').forEach(button => {
               selectedTags.push(button.dataset.value);
           });
           let filteredImages = [];
           for (const [mapTypeKey, locales] of Object.entries(specificOptions)) {
               if (selectedMapType && selectedMapType !== mapTypeKey) continue;
               for (const [local, items] of Object.entries(locales)) {
                   if (selectedLocal && selectedLocal !== local) continue;
                   items.forEach(item => {
                       if (filterByNumber && searchIds.value.split(',').map(id => id.trim()).includes(item.id)) {
                           filteredImages.push(item);
                       } else if (filterByTag && selectedTags.some(tag => item.tags.includes(tag))) {
                           filteredImages.push(item);
                       } else if (!filterByNumber && !filterByTag) {
                           filteredImages.push(item);
                       }
                   });
               }
           }
           displayImages(filteredImages);
       }
       function displayImages(images) {
           images.forEach(image => {
               const imageItem = document.createElement('div');
               imageItem.className = 'image-item';
               imageItem.innerHTML = `
                   <img src="${image.imageUrl}" alt="Map Image">

Número do Mapa: ${image.id}

Local: ${image.local}

Coordenada: ${image.coordinates}

Tag(s): ${image.tags.join(', ')}

               `;
               imageContainer.appendChild(imageItem);
           });
           imageContainer.classList.remove('hidden');
       }
       renderTagButtons();
       filterButton.addEventListener('click', filterImages);
       enableFilter.addEventListener('change', function() {
           if (this.checked) {
               mapTypeSelection.classList.add('hidden');
               specificOptionsSection.classList.add('hidden');
               filterSection.classList.remove('hidden');
               imageContainer.innerHTML = ;
               imageContainer.classList.remove('hidden');
           } else {
               mapTypeSelection.classList.remove('hidden');
               specificOptionsSection.classList.remove('hidden');
               filterSection.classList.add('hidden');
               imageContainer.classList.add('hidden');
               searchIds.value = ;
               document.querySelectorAll('.tag-button.selected').forEach(button => button.classList.remove('selected'));
           }
       });
   </script>

</body> </html>