MediaWiki:Common.js: mudanças entre as edições

De otPokemon Wiki
Ir para navegação Ir para pesquisar
Sem resumo de edição
Sem resumo de edição
Linha 53: Linha 53:
     }
     }
}
}
function ordenarBoxes() {
        const container = document.getElementById("gymContainer");
        const boxes = Array.from(container.getElementsByClassName("square-box-gym"));
        boxes.sort((a, b) => {
            const textA = a.querySelector(".square-name-gym").textContent;
            const textB = b.querySelector(".square-name-gym").textContent;
           
            const numA = parseInt(textA.match(/\d+/)[0]);
            const numB = parseInt(textB.match(/\d+/)[0]);
            return numA - numB;
        });
        boxes.forEach(box => container.appendChild(box));
    }

Edição das 15h30min de 14 de março de 2025

var coll1 = document.getElementsByClassName("collapsible-battle-pass");
var coll2 = document.getElementsByClassName("collapsible-pokemon");

function toggleContent(clickedButton, contentToToggle) {
  // Fechar todos os conteúdos
  var allContents = document.getElementsByClassName("content");
  for (var j = 0; j < allContents.length; j++) {
    allContents[j].style.maxHeight = null; // Fecha todas as divs
  }

  // Fechar todos os botões (remover a classe "active")
  var allButtons = document.getElementsByClassName("collapsible-battle-pass");
  for (var k = 0; k < allButtons.length; k++) {
    allButtons[k].classList.remove("active");
  }
  allButtons = document.getElementsByClassName("collapsible-pokemon");
  for (var k = 0; k < allButtons.length; k++) {
    allButtons[k].classList.remove("active");
  }

  // Agora, abrir o conteúdo da div clicada
  if (contentToToggle.style.maxHeight) {
    contentToToggle.style.maxHeight = null; // Fecha se estiver aberto
  } else {
    contentToToggle.style.maxHeight = contentToToggle.scrollHeight + "px"; // Abre
  }

  // Adicionar a classe active ao botão clicado
  clickedButton.classList.add("active");
}

// Adiciona eventos de clique aos botões
for (var i = 0; i < coll1.length; i++) {
  coll1[i].addEventListener("click", function() {
    var content = this.nextElementSibling; // Conteúdo relacionado à div de botão
    toggleContent(this, content);  // Chama a função para alternar
  });
}

for (var i = 0; i < coll2.length; i++) {
  coll2[i].addEventListener("click", function() {
    var content = this.nextElementSibling; // Conteúdo relacionado à div de botão
    toggleContent(this, content);  // Chama a função para alternar
  });
}

function toggleShinyList() {
    var shinyList = document.getElementById("shiny-list");
    if (shinyList.style.display === "none" || shinyList.style.display === "") {
        shinyList.style.display = "block";
    } else {
        shinyList.style.display = "flex";
    }
}

function ordenarBoxes() {
        const container = document.getElementById("gymContainer");
        const boxes = Array.from(container.getElementsByClassName("square-box-gym"));

        boxes.sort((a, b) => {
            const textA = a.querySelector(".square-name-gym").textContent;
            const textB = b.querySelector(".square-name-gym").textContent;
            
            const numA = parseInt(textA.match(/\d+/)[0]); 
            const numB = parseInt(textB.match(/\d+/)[0]);

            return numA - numB; 
        });

        boxes.forEach(box => container.appendChild(box));
    }