Widget:Test3: 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 15: Linha 15:


         .maps__select,
         .maps__select,
         .input-group input[type="text"],
         .input-group input[type="text"] {
        .input-group button {
             width: 100%;
             width: 100%;
             padding: 10px;
             padding: 10px;
Linha 24: Linha 23:
             border: 1px solid #ccc;
             border: 1px solid #ccc;
         }
         }
.tag-button.disabled {
    background-color: #e0e0e0;
    color: #a0a0a0;
    cursor: not-allowed;
}


         .image-container {
         .image-container {
Linha 67: Linha 60:
             background-color: #15864e;
             background-color: #15864e;
             color: #fff;
             color: #fff;
        }
        .tag-button.disabled {
            background-color: #ddd;
            color: #999;
            cursor: not-allowed;
         }
         }


Linha 138: Linha 137:
             <option value="number">Filtrar por Número</option>
             <option value="number">Filtrar por Número</option>
         </select>
         </select>
         <input type="text" id="searchIds" placeholder="Digite os números ou tags separados por vírgula">
         <input type="text" id="searchIds" placeholder="Digite os números separados por vírgula">
        <button id="filterButton" class="maps__select">Filtrar</button>
     </div>
     </div>


Linha 151: Linha 149:


     <script>
     <script>
        const tagMap = {
            'Areia': 'Areia',
            'Gelo': 'Gelo',
            'Grama': 'Grama',
            'Pedra': 'Pedra',
            'Subaquático': 'Água',
            'Terra': 'Terra',
            'Pisos': 'Piso'
        };
         const specificOptions = {
         const specificOptions = {
             1: { // Mapa Vermelho
             1: { // Mapa Vermelho
                 'Areia': [
                 'Areia': [
                     { id: '101', local: 'Green Island', coordinates: '3780, 3326, 7', tags: ['Areia', 'Água', 'Grama', 'Árvore'], imageUrl: 'https://wiki.pokexgames.com/images/4/4c/Mapas_de_ADV_VERMELHO_-_3780%2C_3326%2C_7.webp' },
                     { id: '101', local: 'Green Island', coordinates: '3780, 3326, 7', tags: ['Areia', 'Água', 'Grama', 'Árvore'], imageUrl: 'https://wiki.pokexgames.com/images/4/4c/Mapas_de_ADV_VERMELHO_-_3780%2C_3326%2C_7.webp' },
                     { id: '102', local: 'Desert', coordinates: '4500, 5300, 5', tags: ['Areia', 'Piso'], imageUrl: 'https://wiki.pokexgames.com/images/5/55/Mapa_Vermelho_ADV_-_4500%2C_5300%2C_5.webp' }
                     { id: '102', local: 'Desert', coordinates: '4500, 5300, 5', tags: ['Areia'], imageUrl: 'https://wiki.pokexgames.com/images/5/55/Mapa_Vermelho_ADV_-_4500%2C_5300%2C_5.webp' }
                 ],
                 ],
                 'Grama': [
                 'Grama': [
Linha 175: Linha 183:
         const enableFilter = document.getElementById('enableFilter');
         const enableFilter = document.getElementById('enableFilter');
         const searchIdsInput = document.getElementById('searchIds');
         const searchIdsInput = document.getElementById('searchIds');
        const filterButton = document.getElementById('filterButton');


const tagMap = {
        function updateTags() {
    'Areia': 'Areia',
            const selectedMapType = mapTypeSelect.value;
    'Gelo': 'Gelo',
            const selectedOption = specificOptionSelect.value;
    'Grama': 'Grama',
    'Pedra': 'Pedra',
    'Subaquático': 'Água',
    'Terra': 'Terra',
    'Pisos': 'Piso'
};


function updateTags() {
            let tags = [];
    const selectedMapType = mapTypeSelect.value;
            if (selectedMapType && selectedOption) {
    const selectedOption = specificOptionSelect.value;
                const options = specificOptions[selectedMapType];
                if (options && options[selectedOption]) {
                    options[selectedOption].forEach(item => {
                        tags = [...new Set([...tags, ...item.tags])];
                    });
                }
            }


    let tags = [];
            tagButtons.innerHTML = '';
    if (selectedMapType && selectedOption) {
            tags.forEach(tag => {
        const options = specificOptions[selectedMapType];
                const button = document.createElement('button');
        if (options && options[selectedOption]) {
                button.textContent = tag;
            options[selectedOption].forEach(item => {
                button.classList.add('tag-button');
                tags = [...new Set([...tags, ...item.tags])];
                button.addEventListener('click', () => {
                    if (!button.classList.contains('disabled')) {
                        button.classList.toggle('selected');
                        filterImages();
                    }
                });
                tagButtons.appendChild(button);
             });
             });
        }
    }


    tagButtons.innerHTML = '';
            // Automatically disable the tag corresponding to the selected option
    tags.forEach(tag => {
            if (selectedOption && tagMap[selectedOption]) {
        const button = document.createElement('button');
                const autoDisabledTag = tagMap[selectedOption];
        button.textContent = tag;
                const tagButton = Array.from(tagButtons.children).find(btn => btn.textContent === autoDisabledTag);
        button.classList.add('tag-button');
 
        button.addEventListener('click', () => {
                if (tagButton) {
            if (!button.classList.contains('disabled')) {
                    tagButton.classList.add('disabled');
                button.classList.toggle('selected');
                    tagButton.removeEventListener('click', () => {
                 filterImages();
                        // Prevent clicks on the disabled button
                    });
                 }
             }
             }
        });
        tagButtons.appendChild(button);
    });


    // Automatically disable the tag corresponding to the selected option
            tagButtons.classList.toggle('hidden', tags.length === 0);
    if (selectedOption && tagMap[selectedOption]) {
        const autoDisabledTag = tagMap[selectedOption];
        const tagButton = Array.from(tagButtons.children).find(btn => btn.textContent === autoDisabledTag);
 
        if (tagButton) {
            tagButton.classList.add('disabled');
            tagButton.removeEventListener('click', () => {
                // Prevent clicks on the disabled button
            });
         }
         }
    }


    tagButtons.classList.toggle('hidden', tags.length === 0);
        function filterImages() {
}
            const selectedTags = Array.from(document.querySelectorAll('.tag-button.selected')).map(btn => btn.textContent);
            const selectedMapType = mapTypeSelect.value;
            const selectedOption = specificOptionSelect.value;
            const filterById = searchIdsInput.value.trim();


function filterImages() {
            imageContainer.innerHTML = '';
    const selectedTags = Array.from(document.querySelectorAll('.tag-button.selected')).map(btn => btn.textContent);
    const selectedMapType = mapTypeSelect.value;
    const selectedOption = specificOptionSelect.value;
    const filterById = searchIdsInput.value.trim();


    imageContainer.innerHTML = '';
            let itemsToFilter = [];


    let itemsToFilter = [];
            if (selectedMapType) {
                const options = specificOptions[selectedMapType];
                if (options) {
                    if (selectedOption && options[selectedOption]) {
                        itemsToFilter = options[selectedOption];
                    }
                }
            }


    if (selectedMapType) {
            if (filterById) {
        const options = specificOptions[selectedMapType];
                const ids = filterById.split(',').map(id => id.trim());
        if (options) {
                 itemsToFilter = itemsToFilter.filter(item => ids.includes(item.id));
            if (selectedOption && options[selectedOption]) {
                 itemsToFilter = options[selectedOption];
             }
             }
        }
 
    } else {
             if (selectedTags.length) {
        // If no map type is selected, gather items from all map types
                 itemsToFilter = itemsToFilter.filter(item => selectedTags.some(tag => item.tags.includes(tag)));
        for (const mapType in specificOptions) {
             for (const local in specificOptions[mapType]) {
                 itemsToFilter = itemsToFilter.concat(specificOptions[mapType][local]);
             }
             }
            itemsToFilter.forEach(item => {
                const imgItem = document.createElement('div');
                imgItem.classList.add('image-item');
                imgItem.innerHTML = `
                    <img src="${item.imageUrl}" alt="Mapa">
                    <div class="image-info">
                        <p><strong>Número:</strong> ${item.id}</p>
                        <p><strong>Local:</strong> ${item.local}</p>
                        <p><strong>Coordenada:</strong> ${item.coordinates}</p>
                        <p><strong>Tag(s):</strong> ${item.tags.join(', ')}</p>
                    </div>
                `;
                imageContainer.appendChild(imgItem);
            });
         }
         }
    }


    if (itemsToFilter.length > 0) {
         mapTypeSelect.addEventListener('change', updateTags);
         const filteredItems = itemsToFilter.filter(item => {
        specificOptionSelect.addEventListener('change', updateTags);
            const matchesTag = selectedTags.length === 0 || selectedTags.some(tag => item.tags.includes(tag));
            const matchesId = filterById === '' || filterById.split(',').map(id => id.trim()).includes(item.id);
            return matchesTag && matchesId;
        });


         filteredItems.forEach(item => {
         enableFilter.addEventListener('change', () => {
             const itemDiv = document.createElement('div');
             const isActive = enableFilter.checked;
             itemDiv.classList.add('image-item');
            document.querySelectorAll('.input-group select').forEach(select => {
                select.disabled = isActive;
             });


             const img = document.createElement('img');
             if (isActive) {
            img.src = item.imageUrl;
                filterOptions.classList.remove('hidden');
            img.alt = `Mapa ${item.id}`;
                tagButtons.classList.add('hidden');
            itemDiv.appendChild(img);
                searchIdsInput.addEventListener('input', filterImages);
 
                filterImages(); // Inicialmente não exibe mapas
            const infoDiv = document.createElement('div');
            } else {
            infoDiv.classList.add('image-info');
                filterOptions.classList.add('hidden');
            infoDiv.innerHTML = `
                tagButtons.classList.remove('hidden');
                 <strong>Número do Mapa:</strong> ${item.id}<br>
                searchIdsInput.value = '';
                <strong>Local:</strong> ${item.local}<br>
                 document.querySelectorAll('.tag-button.selected').forEach(button => {
                <strong>Coordenada:</strong> ${item.coordinates}<br>
                    button.classList.remove('selected');
                <strong>Tag(s):</strong> ${item.tags.join(', ')}
                });
            `;
                filterImages(); // Exibe todos os mapas
            itemDiv.appendChild(infoDiv);
             }
 
             imageContainer.appendChild(itemDiv);
         });
         });


         if (filteredItems.length === 0) {
         searchIdsInput.addEventListener('input', filterImages);
            imageContainer.innerHTML = '<p>Nenhuma imagem encontrada para os critérios selecionados.</p>';
        }
    }
}
 
mapTypeSelect.addEventListener('change', () => {
    updateTags();
    filterImages();
});
 
specificOptionSelect.addEventListener('change', () => {
    updateTags();
    filterImages();
});
 
filterButton.addEventListener('click', () => {
    filterImages();
});
 
searchIdsInput.addEventListener('input', () => {
    filterImages();
});
 
enableFilter.addEventListener('change', () => {
    const isEnabled = enableFilter.checked;
 
    mapTypeSelect.disabled = isEnabled;
    specificOptionSelect.disabled = isEnabled;
 
    filterOptions.classList.toggle('hidden', !isEnabled);
 
    if (isEnabled) {
        mapTypeSelect.value = '';
        specificOptionSelect.value = '';
        searchIdsInput.value = '';
        filterImages();
    }
});
 
function initializePage() {
    specificOptionSelect.classList.remove('hidden');
    filterOptions.classList.add('hidden');
    tagButtons.classList.add('hidden');
    updateTags();
}
 
initializePage();
 
     </script>
     </script>
</body>
</body>
</html>
</html>

Edição das 00h30min de 4 de setembro 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>Seleção de Mapas</title>
   <style>
       .hidden {
           display: none;
       }
       .input-group {
           margin: 20px 0;
       }
       .maps__select,
       .input-group input[type="text"] {
           width: 100%;
           padding: 10px;
           margin-top: 5px;
           font-size: 16px;
           border-radius: 5px;
           border: 1px solid #ccc;
       }
       .image-container {
           display: flex;
           flex-wrap: wrap;
           gap: 10px;
           margin-top: 20px;
       }
       .image-item {
           flex: 1 0 30%;
           text-align: center;
       }
       .image-item img {
           max-width: 100%;
           height: auto;
       }
       .image-info {
           margin-top: 5px;
       }
       .tag-button {
           display: inline-block;
           background-color: #f1f1f1;
           color: #333;
           padding: 10px 20px;
           margin: 5px;
           border: 1px solid #ccc;
           border-radius: 20px;
           cursor: pointer;
           font-size: 16px;
       }
       .tag-button.selected {
           background-color: #15864e;
           color: #fff;
       }
       .tag-button.disabled {
           background-color: #ddd;
           color: #999;
           cursor: not-allowed;
       }
       .filter-container {
           display: flex;
           align-items: center;
           margin-bottom: 20px;
       }
       .filter-container input[type="checkbox"] {
           margin-right: 10px;
       }
       .filter-container label {
           font-size: 16px;
       }
       .selected-tags {
           margin: 20px;
           padding: 10px;
           background-color: #f9f9f9;
           border: 1px solid #ccc;
           border-radius: 5px;
       }
       .tag-item {
           display: inline-block;
           background-color: #007BFF;
           color: white;
           padding: 5px 10px;
           margin-right: 5px;
           border-radius: 3px;
           font-size: 14px;
       }
   </style>

</head> <body>

       <label for="mapType">Tipo de Mapa</label>
       <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="specificOption">Local do X</label>
       <select id="specificOption" class="maps__select">
           <option value="">Selecione uma opção</option>
           <option value="Areia">Areia</option>
           <option value="Gelo">Gelo</option>
           <option value="Grama">Grama</option>
           <option value="Pedra">Pedra</option>
           <option value="Subaquático">Subaquático</option>
           <option value="Terra">Terra</option>
           <option value="Pisos">Pisos</option>
       </select>
       <input type="checkbox" id="enableFilter">
       <label for="enableFilter">Ativar filtro</label>
   <script>
       const tagMap = {
           'Areia': 'Areia',
           'Gelo': 'Gelo',
           'Grama': 'Grama',
           'Pedra': 'Pedra',
           'Subaquático': 'Água',
           'Terra': 'Terra',
           'Pisos': 'Piso'
       };
       const specificOptions = {
           1: { // Mapa Vermelho
               'Areia': [
                   { id: '101', local: 'Green Island', coordinates: '3780, 3326, 7', tags: ['Areia', 'Água', 'Grama', 'Árvore'], imageUrl: 'https://wiki.pokexgames.com/images/4/4c/Mapas_de_ADV_VERMELHO_-_3780%2C_3326%2C_7.webp' },
                   { id: '102', local: 'Desert', coordinates: '4500, 5300, 5', tags: ['Areia'], imageUrl: 'https://wiki.pokexgames.com/images/5/55/Mapa_Vermelho_ADV_-_4500%2C_5300%2C_5.webp' }
               ],
               'Grama': [
                   { id: '103', local: 'Grassland', coordinates: '5600, 4700, 8', tags: ['Grama'], imageUrl: 'https://wiki.pokexgames.com/images/6/67/Mapa_Vermelho_ADV_-_5600%2C_4700%2C_8.webp' }
               ]
           },
           2: { // Mapa Verde
               'Gelo': [
                   { id: '201', local: 'Snowy Peak', coordinates: '2050, 4850, 10', tags: ['Gelo'], imageUrl: 'https://wiki.pokexgames.com/images/5/56/Mapa_Verde_ADV_-_2050%2C_4850%2C_10.webp' }
               ]
           }
       };
       const imageContainer = document.getElementById('imageContainer');
       const tagButtons = document.getElementById('tagButtons');
       const filterOptions = document.getElementById('filterOptions');
       const mapTypeSelect = document.getElementById('mapType');
       const specificOptionSelect = document.getElementById('specificOption');
       const enableFilter = document.getElementById('enableFilter');
       const searchIdsInput = document.getElementById('searchIds');
       function updateTags() {
           const selectedMapType = mapTypeSelect.value;
           const selectedOption = specificOptionSelect.value;
           let tags = [];
           if (selectedMapType && selectedOption) {
               const options = specificOptions[selectedMapType];
               if (options && options[selectedOption]) {
                   options[selectedOption].forEach(item => {
                       tags = [...new Set([...tags, ...item.tags])];
                   });
               }
           }
           tagButtons.innerHTML = ;
           tags.forEach(tag => {
               const button = document.createElement('button');
               button.textContent = tag;
               button.classList.add('tag-button');
               button.addEventListener('click', () => {
                   if (!button.classList.contains('disabled')) {
                       button.classList.toggle('selected');
                       filterImages();
                   }
               });
               tagButtons.appendChild(button);
           });
           // Automatically disable the tag corresponding to the selected option
           if (selectedOption && tagMap[selectedOption]) {
               const autoDisabledTag = tagMap[selectedOption];
               const tagButton = Array.from(tagButtons.children).find(btn => btn.textContent === autoDisabledTag);
               if (tagButton) {
                   tagButton.classList.add('disabled');
                   tagButton.removeEventListener('click', () => {
                       // Prevent clicks on the disabled button
                   });
               }
           }
           tagButtons.classList.toggle('hidden', tags.length === 0);
       }
       function filterImages() {
           const selectedTags = Array.from(document.querySelectorAll('.tag-button.selected')).map(btn => btn.textContent);
           const selectedMapType = mapTypeSelect.value;
           const selectedOption = specificOptionSelect.value;
           const filterById = searchIdsInput.value.trim();
           imageContainer.innerHTML = ;
           let itemsToFilter = [];
           if (selectedMapType) {
               const options = specificOptions[selectedMapType];
               if (options) {
                   if (selectedOption && options[selectedOption]) {
                       itemsToFilter = options[selectedOption];
                   }
               }
           }
           if (filterById) {
               const ids = filterById.split(',').map(id => id.trim());
               itemsToFilter = itemsToFilter.filter(item => ids.includes(item.id));
           }
           if (selectedTags.length) {
               itemsToFilter = itemsToFilter.filter(item => selectedTags.some(tag => item.tags.includes(tag)));
           }
           itemsToFilter.forEach(item => {
               const imgItem = document.createElement('div');
               imgItem.classList.add('image-item');
               imgItem.innerHTML = `
                   <img src="${item.imageUrl}" alt="Mapa">

Número: ${item.id}

Local: ${item.local}

Coordenada: ${item.coordinates}

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

               `;
               imageContainer.appendChild(imgItem);
           });
       }
       mapTypeSelect.addEventListener('change', updateTags);
       specificOptionSelect.addEventListener('change', updateTags);
       enableFilter.addEventListener('change', () => {
           const isActive = enableFilter.checked;
           document.querySelectorAll('.input-group select').forEach(select => {
               select.disabled = isActive;
           });
           if (isActive) {
               filterOptions.classList.remove('hidden');
               tagButtons.classList.add('hidden');
               searchIdsInput.addEventListener('input', filterImages);
               filterImages(); // Inicialmente não exibe mapas
           } else {
               filterOptions.classList.add('hidden');
               tagButtons.classList.remove('hidden');
               searchIdsInput.value = ;
               document.querySelectorAll('.tag-button.selected').forEach(button => {
                   button.classList.remove('selected');
               });
               filterImages(); // Exibe todos os mapas
           }
       });
       searchIdsInput.addEventListener('input', filterImages);
   </script>

</body> </html>