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
 
(133 revisões intermediárias por 2 usuários não estão sendo mostradas)
Linha 1: Linha 1:
/* Códigos JavaScript aqui colocados serão carregados por todos aqueles que acessarem alguma página deste wiki */
var coll1 = document.getElementsByClassName("collapsible-battle-pass");
var coll2 = document.getElementsByClassName("collapsible-pokemon");


$('document').ready(function() {
function toggleContent(clickedButton, contentToToggle) {
   var slideshow = document.getElementById('slideshow');
   var allContents = document.getElementsByClassName("content");
   var images = $('.image');
   for (var j = 0; j < allContents.length; j++) {
  var num_images = images.length;
    allContents[j].style.maxHeight = null;  
  var bars = $('.bar');
   }
  var titles = $('.image-title');
  var active = 0;
   var next;


   function changeTitleToLeft(slide) {
   var allButtons = document.getElementsByClassName("collapsible-battle-pass");
 
  for (var k = 0; k < allButtons.length; k++) {
    $(titles[active]).addClass('slide-out-to-left');
    allButtons[k].classList.remove("active");
    $(titles[active]).one('animationend', function(e) {
  }
      $(titles[active]).addClass('hidden');
  allButtons = document.getElementsByClassName("collapsible-pokemon");
      $(titles[active]).removeClass('slide-out-to-left');
  for (var k = 0; k < allButtons.length; k++) {
      if ($(titles[active]).hasClass('slide-in-from-right')) {
    allButtons[k].classList.remove("active");
        $(titles[active]).removeClass('slide-in-from-right');
  }
      }
      else if ($(titles[active]).hasClass('slide-in-from-left')) {
        $(titles[active]).removeClass('slide-in-from-left');
      }
      $(titles[slide]).removeClass('hidden');
      $(titles[slide]).addClass('slide-in-from-right');
      active=slide;
    });


  if (contentToToggle.style.maxHeight) {
    contentToToggle.style.maxHeight = null;
  } else {
    contentToToggle.style.maxHeight = contentToToggle.scrollHeight + "px";
   }
   }


  clickedButton.classList.add("active");
}


   function changeTitleToRight(slide) {
for (var i = 0; i < coll1.length; i++) {
   coll1[i].addEventListener("click", function() {
    var content = this.nextElementSibling;
    toggleContent(this, content); 
  });
}


    $(titles[active]).addClass('slide-out-to-right');
for (var i = 0; i < coll2.length; i++) {
    $(titles[active]).one('animationend', function(e) {
  coll2[i].addEventListener("click", function() {
      $(titles[active]).addClass('hidden');
    var content = this.nextElementSibling;  
      $(titles[active]).removeClass('slide-out-to-right');
    toggleContent(this, content);  
      if ($(titles[active]).hasClass('slide-in-from-right')) {
  });
        $(titles[active]).removeClass('slide-in-from-right');
}
      }
      else if ($(titles[active]).hasClass('slide-in-from-left')) {
        $(titles[active]).removeClass('slide-in-from-left');
      }
      $(titles[slide]).removeClass('hidden');
      $(titles[slide]).addClass('slide-in-from-left');
      active=slide;
    });


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 changeActiveBar(slide) {
    $(bars[active]).toggleClass('active-bar');
    $(bars[slide]).toggleClass('active-bar');
  }


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);
   


  function showSlide(slide) {
        $sortButton.on('click', function () {
    $(images[active]).toggleClass('hidden');
            var $container = $('.square-div-shiny');
    $(images[slide]).toggleClass('hidden');
            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);


  $('#prev').click(function() {
                return isAscending ? numA - numB : numB - numA;
    if (active == 0) {
            });
      next = num_images-1;
      showSlide(next);
      changeActiveBar(next);
      changeTitleToLeft(next);
    }
    else {
      next = active-1
      showSlide(next);
      changeActiveBar(next);
      changeTitleToLeft(next);
    }
  });


  $('#next').click(function() {
            $container.append($boxes);
    if (active == num_images - 1) {
            isAscending = !isAscending;
      next = 0;
      showSlide(next);
      changeActiveBar(next);
      changeTitleToRight(next);
    }
    else {
      next = active + 1;
      showSlide(next);
      changeActiveBar(next);
      changeTitleToRight(next);
    }
  });


            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 + ')');
        });
    });
});
});

Edição atual tal como às 00h17min de 17 de março de 2025

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

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

  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");
  }

  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); 
  });
}

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";
    }
}


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 + ')');
        });
    });
});