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

sem sumário de edição
Sem resumo de edição
Sem resumo de edição
Linha 209: Linha 209:
                 <label for="filterOption" class="maps__label">Filtrar Por</label>
                 <label for="filterOption" class="maps__label">Filtrar Por</label>
                 <select id="filterOption" class="maps__select">
                 <select id="filterOption" class="maps__select">
                    <option value="">Escolha uma Opção</option>
                     <option value="number">Filtrar por Número</option>
                     <option value="number">Filtrar por Número</option>
                     <option value="tag">Filtrar por Tag</option>
                     <option value="tag">Filtrar por Tag</option>
                 </select>
                 </select>
                 <input type="text" id="searchIds" placeholder="Digite os números separados por vírgula"
                 <input type="text" id="searchIds" placeholder="Digite os números ou tags separados por vírgula"
                     class="mapsCalc__select">
                     class="mapsCalc__select">
             </div>
             </div>
             <div class="d-flex justify-center align-center flex-column">
             <div class="d-flex justify-center align-center flex-column">
                 <button type="button" id="filterButton" class="hover-minimize">
                 <button type="button" id="filterButton" class="hover-minimize">
Linha 234: Linha 232:
             1: { // Mapa Vermelho
             1: { // Mapa Vermelho
                 'Areia': [
                 'Areia': [
                     { id: '101', local: 'Green Island', coordinates: '3780, 3326, 7', imageUrl: 'https://wiki.pokexgames.com/images/d/db/3780%2C_3326%2C_7.png', tag: 'Areia' },
                     { id: '101', local: 'Green Island', coordinates: '3780, 3326, 7', tag: 'Areia', imageUrl: 'https://wiki.pokexgames.com/images/d/db/3780%2C_3326%2C_7.png' },
                 ],
                 ],
                 // Outras opções do Mapa Vermelho
                 // Outras opções do Mapa Vermelho
            },
            2: { // Mapa Verde
                'Grama': [
                    { id: '102', local: 'Green Hills', coordinates: '3785, 3320, 7', imageUrl: 'https://wiki.pokexgames.com/images/1/12/Green_Hills.png', tag: 'Grama' },
                ],
                // Outras opções do Mapa Verde
            },
            3: { // Mapa Roxo
                'Pedra': [
                    { id: '103', local: 'Rocky Mountain', coordinates: '3790, 3315, 7', imageUrl: 'https://wiki.pokexgames.com/images/2/23/Rocky_Mountain.png', tag: 'Pedra' },
                ],
                // Outras opções do Mapa Roxo
             }
             }
         };
         };
Linha 272: Linha 258:
             const specificOptionSelect = document.getElementById('specificOption');
             const specificOptionSelect = document.getElementById('specificOption');


             if (selectedMapType && specificOptions[selectedMapType]) {
             if (selectedMapType) {
                 specificOptionSelect.innerHTML = '<option value="">Selecione uma opção</option>';
                 specificOptionSelect.innerHTML = '<option value="">Selecione uma opção</option>';
                 const options = Object.keys(specificOptions[selectedMapType]);
                 const options = Object.keys(specificOptions[selectedMapType]);
Linha 289: Linha 275:
             const imageContainer = document.getElementById('imageContainer');
             const imageContainer = document.getElementById('imageContainer');


             if (selectedMapType && selectedOption && specificOptions[selectedMapType][selectedOption]) {
             if (selectedMapType && selectedOption) {
                 const images = specificOptions[selectedMapType][selectedOption];
                 const images = specificOptions[selectedMapType][selectedOption];
                 let imagesHtml = '';
                 let imagesHtml = '';
Linha 314: Linha 300:
                                 <b>Número do Mapa</b>: ${images.id} <br>
                                 <b>Número do Mapa</b>: ${images.id} <br>
                                 <b>Local</b>: ${images.local} <br>
                                 <b>Local</b>: ${images.local} <br>
                                 <b>Coordenada</b>: ${images.coordinates}
                                 <b>Coordenada</b>: ${images.coordinates}<br>
                                <b>Tag(s)</b>: ${images.tag}
                             </div>
                             </div>
                         </div>
                         </div>
Linha 327: Linha 314:


         document.getElementById('filterButton').addEventListener('click', function () {
         document.getElementById('filterButton').addEventListener('click', function () {
             const searchIds = document.getElementById('searchIds').value.split(',').map(id => id.trim());
             const filterOption = document.getElementById('filterOption').value;
            const searchIdsOrTags = document.getElementById('searchIds').value.split(',').map(item => item.trim());
             const imageContainer = document.getElementById('imageContainer');
             const imageContainer = document.getElementById('imageContainer');
            let imagesHtml = '';
            let allImages = [];


             if (searchIds.length > 0) {
             if (filterOption === 'number' && searchIdsOrTags.length > 0) {
                 let imagesHtml = '';
                 // Filtrar por números
                let allImages = [];
                Object.keys(specificOptions).forEach(mapType => {
 
                    const mapOptions = specificOptions[mapType];
                 // Recolhe todas as imagens que correspondem aos IDs
                    Object.keys(mapOptions).forEach(option => {
                        const images = mapOptions[option].filter(image => searchIdsOrTags.includes(image.id));
                        allImages = allImages.concat(images);
                    });
                });
            } else if (filterOption === 'tag' && searchIdsOrTags.length > 0) {
                 // Filtrar por tags
                 Object.keys(specificOptions).forEach(mapType => {
                 Object.keys(specificOptions).forEach(mapType => {
                     const mapOptions = specificOptions[mapType];
                     const mapOptions = specificOptions[mapType];
                     Object.keys(mapOptions).forEach(option => {
                     Object.keys(mapOptions).forEach(option => {
                         const images = mapOptions[option].filter(image => searchIds.includes(image.id));
                         const images = mapOptions[option].filter(image => {
                            return searchIdsOrTags.some(tag => image.tag && image.tag.toLowerCase().includes(tag.toLowerCase()));
                        });
                         allImages = allImages.concat(images);
                         allImages = allImages.concat(images);
                     });
                     });
                 });
                 });
            }


                // Ordena as imagens pelo nome do local
            // Ordenar as imagens pelo nome do local
                allImages.sort((a, b) => a.local.localeCompare(b.local));
            allImages.sort((a, b) => a.local.localeCompare(b.local));


                // Gera o HTML para exibir as imagens ordenadas
            // Gerar o HTML para exibir as imagens ordenadas
                allImages.forEach(image => {
            allImages.forEach(image => {
                    imagesHtml += `
                imagesHtml += `
                        <div class="image-item">
                    <div class="image-item">
                            <img src="${image.imageUrl}" alt="Imagem ID ${image.id}">
                        <img src="${image.imageUrl}" alt="Imagem ID ${image.id}">
                            <div class="image-info">
                        <div class="image-info">
                                <b>Número do Mapa</b>: ${image.id} <br>
                            <b>Número do Mapa</b>: ${image.id} <br>
                                <b>Local</b>: ${image.local} <br>
                            <b>Local</b>: ${image.local} <br>
                                <b>Coordenada</b>: ${image.coordinates}<br>
                            <b>Coordenada</b>: ${image.coordinates}<br>
                                <b>Tag(s)</b>: ${image.tag}
                            <b>Tag(s)</b>: ${image.tag}  
                            </div>
                         </div>
                         </div>
                     `;
                     </div>
                });
                `;
 
            });
                if (imagesHtml === '') {
                    imageContainer.innerHTML = 'Nenhum mapa encontrado com o(s) número(s) informado(s).';
                } else {
                    imageContainer.innerHTML = imagesHtml;
                }


                imageContainer.classList.remove('hidden');
            imageContainer.innerHTML = imagesHtml || 'Nenhuma imagem encontrada com os números ou tags fornecidos.';
             } else {
             imageContainer.classList.remove('hidden');
                imageContainer.classList.add('hidden');
            }
         });
         });
     </script>
     </script>
</body>
</body>
</html>
</html>
5 171

edições