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

De otPokemon Wiki
Ir para navegação Ir para pesquisar
Sem resumo de edição
Etiqueta: Reversão manual
Sem resumo de edição
 
(38 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 coll = document.getElementsByClassName("collapsible-battle-pass");
var coll2 = document.getElementsByClassName("collapsible-pokemon");
var i;


for (i = 0; i < coll.length; i++) {
function toggleContent(clickedButton, contentToToggle) {
  coll[i].addEventListener("click", function() {
  var allContents = document.getElementsByClassName("content");
     this.classList.toggle("active");
  for (var j = 0; j < allContents.length; j++) {
    var content = this.nextElementSibling;
    allContents[j].style.maxHeight = null;
     if (content.style.maxHeight){
  }
      content.style.maxHeight = null;
 
    } else {
  var allButtons = document.getElementsByClassName("collapsible-battle-pass");
      content.style.maxHeight = content.scrollHeight + "px";
  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); 
   });
   });
}
}


var coll = document.getElementsByClassName("collapsible-pokemon");
for (var i = 0; i < coll2.length; i++) {
var p;
  coll2[i].addEventListener("click", function() {
    var content = this.nextElementSibling;
    toggleContent(this, content);  
  });
}


for (p = 0; p < coll.length; p++) {
function toggleShinyList() {
  coll[p].addEventListener("click", function() {
     var shinyList = document.getElementById("shiny-list");
     this.classList.toggle("active");
     if (shinyList.style.display === "none" || shinyList.style.display === "") {
    var content = this.nextElementSibling;
        shinyList.style.display = "block";
     if (content.style.maxHeight){
      content.style.maxHeight = null;
     } else {
     } else {
      content.style.maxHeight = content.scrollHeight + "px";
        shinyList.style.display = "flex";
     }  
     }
  });
}
}
var tUpload = document.getElementById('t-upload');
      var pTb = document.getElementById('p-tb');


      if (!tUpload) {
        if (pTb) {
          pTb.style.display = 'none';
        }
      }


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


/* Teste */
        $sortButton.on('click', function () {
 
            var $container = $('.square-div-shiny');
function slider(){
            var $boxes = $container.children('.square-box-shiny');
  const slider = document.querySelectorAll('.slide');
  const timer = 10000;
  slider[0].style.display = 'block';
  bullets = sliderBulletsCreation(slider);
  sliderLoop(slider, timer, bullets);
};


function sliderLoop(slider, timer, bullets){
            $boxes.sort(function (a, b) {
  var timeoutFunction = [];
                var numA = parseInt($(a).find('.square-name-shiny').text().match(/\d+/)[0], 10);
  for (var i = 0; slide = slider[i] && (i < slider.length); i++) {
                var numB = parseInt($(b).find('.square-name-shiny').text().match(/\d+/)[0], 10);
    timeoutFunction.push(setTimeout(sliderAnim.bind(null, slider, i, timer, bullets), i*timer));
  };
  bullets.forEach(function(bullet, index){
    bullet.addEventListener("click", function(event){
      console.log(index);
      timeoutFunction.forEach(function(element){
        clearTimeout(element);
      });
      var t=0;
      for (var i = index; slide = slider[i] && (i < slider.length); i++) {
        timeoutFunction.push(setTimeout(sliderAnim.bind(null, slider, i, timer, bullets), t*timer));
        t++;
      };
    })
  })
};


function sliderAnim(slider, i, timer, bullets){
                return isAscending ? numA - numB : numB - numA;
  slider.forEach(function(slide){
            });
    slide.style.display = 'none';
  })
  bullets.forEach(function(bullet){
    bullet.style.backgroundColor = "#e5e5e5";
  })
  slider[i].style.display = 'block';
  bullets[i].style.backgroundColor = "#007ee5";
  if (i == (slider.length - 1)){setTimeout(sliderLoop.bind(null,slider, timer, bullets), timer)};
};


function sliderBulletsCreation(slider){
            $container.append($boxes);
  const sliderContainer = document.querySelector('.slider2');
            isAscending = !isAscending;
  const length = slider.length;
  const bullets = [];
  for (var i = 0; slide = slider[i] && (i < slider.length); i++) {
    var bullet = document.createElement("div");
    bullet.classList.add('slider-bullet');
    bullet.style.right = 20 + (i * 30) + 'px';
    bullet.style.width = "20px";
    bullet.style.height = "20px";
    sliderContainer.appendChild(bullet);
    bullets.push(bullet);
  }
  return bullets;
};


slider();
            var newImage = isAscending
 
                ? 'https://wiki.otpokemon.com/images/e/e2/O-d.png'
/* Teste Menu */
                : 'https://wiki.otpokemon.com/images/9/92/O-c.png';
var coll = document.getElementsByClassName("collapsible");
           
var i;
            $sortButton.css('background-image', 'url(' + newImage + ')');
 
         });
for (i = 0; i < coll.length; i++) {
     });
  coll[i].addEventListener("click", function() {
});
    this.classList.toggle("active");
    var content = this.nextElementSibling;
   
    // Fecha todos os outros conteúdos
    var allContents = document.getElementsByClassName("content");
    for (var j = 0; j < allContents.length; j++) {
      if (allContents[j] !== content) {
         allContents[j].style.maxHeight = null;
      }
    }
 
    // Alterna o conteúdo clicado
    if (content.style.maxHeight) {
      content.style.maxHeight = null;
     } else {
      content.style.maxHeight = content.scrollHeight + "px";
    }
  });
}

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