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
 
(62 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;  
for (p = 0; p < coll.length; p++) {
     toggleContent(this, content);  
   coll[p].addEventListener("click", function() {
    this.classList.toggle("active");
     var content = this.nextElementSibling;
     if (content.style.maxHeight){
      content.style.maxHeight = null;
    } else {
      content.style.maxHeight = content.scrollHeight + "px";
    }
   });
   });
}
}
var tUpload = document.getElementById('t-upload');
/* Pokedex */
      var pTb = document.getElementById('p-tb');
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;  
  }


      if (!tUpload) {
  var allButtons2 = document.getElementsByClassName("collapsible-pokedex");
        if (pTb) {
  for (var k = 0; k < allButtons2.length; k++) {
          pTb.style.display = 'none';
    allButtons2[k].classList.remove("active");
        }
  }
      }


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


/* Teste */
  clickedButton.classList.add("active");
}


function slider(){
for (var i = 0; i < coll3.length; i++) {
   const slider = document.querySelectorAll('.slide');
   coll3[i].addEventListener("click", function() {
  const timer = 10000;
    var content = this.nextElementSibling;  
  slider[0].style.display = 'block';
    toggleContent(this, content);
  bullets = sliderBulletsCreation(slider);
   });
   sliderLoop(slider, timer, bullets);
}
};


function sliderLoop(slider, timer, bullets){
/* Pokedex */
  var timeoutFunction = [];
  for (var i = 0; slide = slider[i] && (i < slider.length); i++) {
    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){
function toggleShinyList() {
  slider.forEach(function(slide){
    var shinyList = document.getElementById("shiny-list");
     slide.style.display = 'none';
     if (shinyList.style.display === "none" || shinyList.style.display === "") {
  })
        shinyList.style.display = "block";
  bullets.forEach(function(bullet){
    } else {
    bullet.style.backgroundColor = "#e5e5e5";
        shinyList.style.display = "flex";
  })
    }
  slider[i].style.display = 'block';
}
  bullets[i].style.backgroundColor = "#007ee5";
 
  if (i == (slider.length - 1)){setTimeout(sliderLoop.bind(null,slider, timer, bullets), timer)};
 
};
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 sliderBulletsCreation(slider){
        $sortButton.on('click', function () {
  const sliderContainer = document.querySelector('.slider2');
            var $container = $('.square-div-shiny');
  const length = slider.length;
            var $boxes = $container.children('.square-box-shiny');
  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();
            $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);


/* Teste Menu */
                return isAscending ? numA - numB : numB - numA;
function changeContent(region) {
            });
        const content = document.getElementById('content2');
        let newContent = '';


        switch(region) {
            $container.append($boxes);
            case 'parte1':
             isAscending = !isAscending;
                newContent = `
                    <h3>Parte1</h3>
                    <p>DLorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur eu magna fringilla enim sodales pulvinar in vitae ex. Sed cursus, arcu sed porta fermentum, massa enim consequat erat</p>
                `;
                break;
             case 'parte2':
                newContent = `
                    <h3>Parte2</h3>
                    <p>Descrição específica para Parte 2.</p>
                `;
                break;
            case 'parte3':
                newContent = `
                    <h3>Parte3</h3>
                    <p>Descrição específica para Parte 3.</p>
                    <img src="image-nightmare.png" alt="Imagem de Nightmare World">
                `;
                break;
            case 't1h':
                newContent = `
                    <h3>Parte4</h3>
                    <p>Descrição específica para Parte 4.</p>
                `;
                break;
            default:
                newContent = '<p>Clique em um dos botões acima para ver o conteúdo.</p>';
        }


         content.innerHTML = newContent;
            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 13h51min de 6 de abril 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); 
  });
}
/* 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 */

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