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

sem sumário de edição
Sem resumo de edição
Sem resumo de edição
 
(40 revisões intermediárias por 2 usuários não estão sendo mostradas)
Linha 1: Linha 1:
var coll1 = document.getElementsByClassName("collapsible-battle-pass");
var coll2 = document.getElementsByClassName("collapsible-pokemon");


/* Teste Menu */
function toggleContent(clickedButton, contentToToggle) {
var coll = document.getElementsByClassName("collapsible");
  var allContents = document.getElementsByClassName("content");
var i;
  for (var j = 0; j < allContents.length; j++) {
    allContents[j].style.maxHeight = null;
  }


for (i = 0; i < coll.length; i++) {
  var allButtons = document.getElementsByClassName("collapsible-battle-pass");
   coll[i].addEventListener("click", function() {
  for (var k = 0; k < allButtons.length; k++) {
     this.classList.toggle("active");
    allButtons[k].classList.remove("active");
     var content = this.nextElementSibling;
  }
      
  allButtons = document.getElementsByClassName("collapsible-pokemon");
    // Fecha todos os outros conteúdos
  for (var k = 0; k < allButtons.length; k++) {
    var allContents = document.getElementsByClassName("content");
    allButtons[k].classList.remove("active");
    for (var j = 0; j < allContents.length; j++) {
  }
      if (allContents[j] !== content) {
 
        allContents[j].style.maxHeight = null;
  if (contentToToggle.style.maxHeight) {
      }
    contentToToggle.style.maxHeight = null;
     }
  } else {
    contentToToggle.style.maxHeight = contentToToggle.scrollHeight + "px";
  }
 
  clickedButton.classList.add("active");
}
 
for (var i = 0; i < coll1.length; i++) {
   coll1[i].addEventListener("click", function() {
     var content = this.nextElementSibling;
    toggleContent(this, content); 
  });
}
 
for (var i = 0; i < coll2.length; i++) {
  coll2[i].addEventListener("click", function() {
     var content = this.nextElementSibling;  
     toggleContent(this, content);
  });
}
/* Pokedex */
var coll3 = document.getElementsByClassName("collapsible-pokedex");
 
function toggleContent(clickedButton, contentToToggle) {
  var allContents = document.getElementsByClassName("content");
  for (var j = 0; j < allContents.length; j++) {
    allContents[j].style.maxHeight = null;
  }
 
  var allButtons2 = document.getElementsByClassName("collapsible-pokedex");
  for (var k = 0; k < allButtons2.length; k++) {
    allButtons2[k].classList.remove("active");
  }
 
  if (contentToToggle.style.maxHeight) {
    contentToToggle.style.maxHeight = null;  
  } else {
     contentToToggle.style.maxHeight = contentToToggle.scrollHeight + "px";
  }
 
  clickedButton.classList.add("active");
}
 
for (var i = 0; i < coll3.length; i++) {
  coll3[i].addEventListener("click", function() {
    var content = this.nextElementSibling;
    toggleContent(this, content); 
  });
}
 
/* Pokedex */


     // Alterna o conteúdo clicado
function toggleShinyList() {
     if (content.style.maxHeight) {
     var shinyList = document.getElementById("shiny-list");
      content.style.maxHeight = null;
     if (shinyList.style.display === "none" || shinyList.style.display === "") {
        shinyList.style.display = "block";
     } else {
     } else {
      content.style.maxHeight = content.scrollHeight + "px";
        shinyList.style.display = "flex";
     }
     }
  });
}
}
mw.loader.using('jquery', function () {
    $(document).ready(function () {
        var isAscending = true;
        var $sortButton = $('<div class="sort-button" style="width: 60px; height: 50px; background-image: url(https://wiki.otpokemon.com/images/9/92/O-c.png); background-position: center; background-repeat: no-repeat; background-size: cover; border-radius: 3px; cursor: pointer; float: right; margin-right: 0.5%;margin-top: -50px;"></div>');
        $('.square-div-shiny').before($sortButton);
   
        $sortButton.on('click', function () {
            var $container = $('.square-div-shiny');
            var $boxes = $container.children('.square-box-shiny');
            $boxes.sort(function (a, b) {
                var numA = parseInt($(a).find('.square-name-shiny').text().match(/\d+/)[0], 10);
                var numB = parseInt($(b).find('.square-name-shiny').text().match(/\d+/)[0], 10);
                return isAscending ? numA - numB : numB - numA;
            });
            $container.append($boxes);
            isAscending = !isAscending;
            var newImage = isAscending
                ? 'https://wiki.otpokemon.com/images/e/e2/O-d.png'
                : 'https://wiki.otpokemon.com/images/9/92/O-c.png';
           
            $sortButton.css('background-image', 'url(' + newImage + ')');
        });
    });
});