Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

MediaWiki:Common.js: Difference between revisions

MediaWiki interface page
Content added Content deleted
No edit summary
Tag: Manual revert
No edit summary
Line 29: Line 29:
"[[Category:Fox]]");
"[[Category:Fox]]");
//==== Movelist Toggles ====
//==== Movelist Toggles ==== Written by SageVarq
if (document.getElementsByClassName("movelist-toggles").length > 0) {
if (document.getElementsByClassName("movelist-toggles")) {
// Hide all move lists
// Variable to track th current movelist
var $movelists = $('.movelist');
var currentMovelist = -1;

var currentMovelist = 1;
// Sets the current movelist based on the URL

setMovelistByUrlSection();
displayMovelist(currentMovelist);
// Adds the movelist swap function to the movelist toggle buttons
$('.movelist-toggle-button').each(addToggles);
$('.movelist-toggle-button').each(addToggles);

// Adds the "setMovelistByUrlSection" function to all "a" type elements
function swapMovelist(e) {
// This is so that if a link is clicked, it will set the correct movelist
var movelistToggleClicked = $(this).data("id");
//$('a').click(setMovelistByUrlSection);
var nextMovelist = movelistToggleClicked.substring(movelistToggleClicked.length - 1);
/*$('a').each(function() {
if (currentMovelist != nextMovelist) {
var $t = $(this);
currentMovelist = nextMovelist;
var $tString = $t.attr("href");
displayMovelist(nextMovelist);
var url = window.location.href;
}
if($tString.substring(0, $tString.indexOf("#")) ==
}
});*/

$(window).bind('hashchange', function() {

console.log("hashchange");
function displayMovelist(target) {
setMovelistByUrlSection();
hideAllMovelists();
});
$("#movelist-" + target).css("display", "block");
$("#movelist-toggle-" + target).addClass("movelist-toggle-on");
/*$(window).bind('popstate', function() {
}
console.log("popstate");

setMovelistByUrlSection();
function hideAllMovelists() {
});*/
$movelists.css("display", "none");
$('.movelist-toggle-button').removeClass("movelist-toggle-on").addClass("movelist-toggle-off");
// Sets the movelist based on the section in the URL
}
function setMovelistByUrlSection() {

// Get the page URL
function addToggles() {
var pageUrl = window.location.href;
$(this).data("id", $(this).attr("id"));
var nextMovelist = 1;
$(this).click(swapMovelist);
}
// If page URL contains "#", proceed
}
if (pageUrl.indexOf("#") > 0) {

// Get section, which is the "#" and everything after it
$('.lazyimg').prop('loading', 'lazy');
var targetSection = pageUrl.substring(pageUrl.indexOf("#"));
// Check all class "movelist" elements
// This is under the assumption that movelists are manually labeled correctly starting from 1 and incrementing.
var maxIterations = $('.movelist').length;
var i = 1;
var sectionNotFound = true;
/* This for-loop doesn't work for some reason (syntax error???), so I made a while-loop version below
for (let i=1; i <= maxIterations; i++) {
console.log("checking movelist-"+i);
// If the movelist contains the target section
if ($('#movelist-' + i).find(targetSection).length > 0) {
// Set the nextMoveList to this movelist and break the for loop
nextMovelist = i;
console.log("found " + targetSection + "in movelist-"+i);
break;
}
}*/
while(i <= maxIterations && sectionNotFound) {
console.log("checking movelist-"+i);
// If the movelist contains the target section
if ($('#movelist-' + i).find(targetSection).length > 0) {
// Set the nextMoveList to this movelist and break the for loop
nextMovelist = i;
console.log("found " + targetSection + "in movelist-"+i);
sectionNotFound = false;
}
i++;
}
}
// Display the movelist
if (currentMovelist != nextMovelist) {
currentMovelist = nextMovelist;
displayMovelist(currentMovelist);
}
if(sectionNotFound == false)
$('html,body').animate({scrollTop: $(targetSection).offset().top},'slow');
}
// Swap the movelist
function swapMovelistByButton(e) {
// Variable for the element data "id" for movelist that was clicked
var movelistToggleClicked = $(this).data("id");
// A string just for counting it's length of the movelist-toggle ID
var movelistIdString = "movelist-toggle-";
// Variable snipping on the number value of the movelist
// This assumes that it is a number appended to these movelists
var nextMovelist = movelistToggleClicked.substring(movelistIdString.length);
// Changse the movelist if it's not the currently selected one
if (currentMovelist != nextMovelist) {
currentMovelist = nextMovelist;
displayMovelist(currentMovelist);
}
}
// Display the target movelist
function displayMovelist(target) {
// Hides all movelists
hideAllMovelists();
// Displays the target movelist
$("#movelist-" + target).css("display", "block");
// Highlights the current movelist toggle button by changing its classes around
$("#movelist-toggle-" + target).removeClass("movelist-toggle-off").addClass("movelist-toggle-on");
}
// Hides all movelists
function hideAllMovelists() {
// Sets all movelists "display" to "none"
$(".movelist").css("display", "none");
// Removes highlights from all movelist toggle buttons by changing its classes around
$('.movelist-toggle-button').removeClass("movelist-toggle-on").addClass("movelist-toggle-off");
}
// Adds toggles to movelist toggle buttons
function addToggles() {
// Adds data "id" which is just equal to the buttons attribute id
$(this).data("id", $(this).attr("id"));
// Run "swapMovelistByButton" function when this is clicked
$(this).click(swapMovelistByButton);
}
}
});
});

Revision as of 20:14, 6 June 2023

/* Any JavaScript here will be loaded for all users on every page load. */

$(document).ready(function() {
	
	$('.hitbox-toggle-off').click(function() {
		$('.hitbox-toggle-off').hide();
		$('.move-image').hide();
		$('.caption').hide();
		$('.hitbox-toggle-on').show();
		$('.hitbox-image').show();
		$('.hitbox-caption').show();
	});
	
	$('.hitbox-toggle-on').click(function() {
		$('.hitbox-toggle-on').hide();
		$('.hitbox-image').hide();
		$('.hitbox-caption').hide();
		$('.hitbox-toggle-off').show();
		$('.move-image').show();
		$('.caption').show();
	});
	
	// Add placeholder text to Upload Summary
	$('#wpUploadDescription').attr("placeholder",
		"Add a description here.\n" +
		"If you're uploading a new file, make sure to categorize!\n" +
		"Example:\n" +
		"[[Category:Super Smash Bros Ultimate]]\n" +
		"[[Category:Fox]]");
		
    //==== Movelist Toggles ==== Written by SageVarq
  if (document.getElementsByClassName("movelist-toggles")) {
    // Hide all move lists
    var $movelists = $('.movelist');

    var currentMovelist = 1;

    displayMovelist(currentMovelist);
    $('.movelist-toggle-button').each(addToggles);

    function swapMovelist(e) {
      var movelistToggleClicked = $(this).data("id");
      var nextMovelist = movelistToggleClicked.substring(movelistToggleClicked.length - 1);
      if (currentMovelist != nextMovelist) {
        currentMovelist = nextMovelist;
        displayMovelist(nextMovelist);
      }
    }


    function displayMovelist(target) {
      hideAllMovelists();
      $("#movelist-" + target).css("display", "block");
      $("#movelist-toggle-" + target).addClass("movelist-toggle-on");
    }

    function hideAllMovelists() {
      $movelists.css("display", "none");
      $('.movelist-toggle-button').removeClass("movelist-toggle-on").addClass("movelist-toggle-off");
    }

    function addToggles() {
      $(this).data("id", $(this).attr("id"));
      $(this).click(swapMovelist);
    }
  }

  $('.lazyimg').prop('loading', 'lazy');
});
Cookies help us deliver our services. By using our services, you agree to our use of cookies.