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
 
(19 intermediate revisions by 3 users not shown)
Line 20: Line 20:
$('.caption').show();
$('.caption').show();
});
});
// Add placeholder text to Upload Summary
// Add placeholder text to Upload Summary
Line 29: Line 30:
"[[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("#"));


} );
//tippy tooltip function
//credit to Dustloop Wiki and Alistair3149 for writing the code
//mw.loader.getScript( 'https://cdn.jsdelivr.net/npm/@popperjs/core@2.0.0/dist/umd/popper.min.js');
//mw.loader.getScript( 'https://cdn.jsdelivr.net/npm/tippy.js@6.0.0/dist/tippy.umd.min.js');
mw.hook( 'wikipage.content' ).add( function ( content ) {
/*
* Tippy.js
* @see https://atomiks.github.io/tippyjs/
*/
// content is a jQuery object, content[0] returns the bodyContent element
// Select top-level tooltips
const tooltips = content[ 0 ].querySelectorAll( '.tooltip:not( .tooltip .tooltip )' );
if ( tooltips ) {
mw.loader.getScript( 'https://cdn.jsdelivr.net/npm/@popperjs/core@2/dist/umd/popper.js' ).then( function () {
mw.loader.getScript( ' https://cdn.jsdelivr.net/npm/tippy.js@6/dist/tippy.umd.js' ).then( function () {
// Load styles for shift-away animation
mw.loader.load( 'https://cdn.jsdelivr.net/npm/tippy.js@6/animations/shift-away.css', 'text/css' );
const createTippy = function ( element, position ) {
const tooltipContent = element.querySelector( ':scope > .tooltiptext' );
tippy( element, {
content: tooltipContent.innerHTML,
placement: position
} );
// Make tooltip focusable by keyboard
element.setAttribute( 'tabindex' , '0' );
};
tippy.setDefaultProps( {
// Check all class "movelist" elements
animation: 'shift-away',
// This is under the assumption that movelists are manually labeled correctly starting from 1 and incrementing.
arrow: true,
var maxIterations = $('.movelist').length;
var i = 1;
allowHTML: true,
appendTo: document.body,
var sectionNotFound = true;
ignoreAttributes: true,
/* This for-loop doesn't work for some reason (syntax error???), so I made a while-loop version below
interactive: true
for (let i=1; i <= maxIterations; i++) {
} );
console.log("checking movelist-"+i);
// If the movelist contains the target section
tooltips.forEach( function ( tooltip ) {
if ($('#movelist-' + i).find(targetSection).length > 0) {
createTippy( tooltip, 'top' );
// Set the nextMoveList to this movelist and break the for loop
nextMovelist = i;
const nestedTooltip = tooltip.querySelector( '.tooltip' );
console.log("found " + targetSection + "in movelist-"+i);
break;
if ( nestedTooltip ) {
createTippy( nestedTooltip, 'bottom' );
}
}
}*/
} );
},
while(i <= maxIterations && sectionNotFound) {
function ( e ) {
console.log("checking movelist-"+i);
mw.log.error( e.message );
// 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) {
function ( e ) {
currentMovelist = nextMovelist;
mw.log.error( e.message );
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);
}
}
}
});
} );

Latest revision as of 16:29, 18 July 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');


} );
  //tippy tooltip function
  //credit to Dustloop Wiki and Alistair3149 for writing the code
  
  //mw.loader.getScript( 'https://cdn.jsdelivr.net/npm/@popperjs/core@2.0.0/dist/umd/popper.min.js');  
  //mw.loader.getScript( 'https://cdn.jsdelivr.net/npm/tippy.js@6.0.0/dist/tippy.umd.min.js');
  mw.hook( 'wikipage.content' ).add( function ( content ) {
	/*
     * Tippy.js
     * @see https://atomiks.github.io/tippyjs/
    */
	// content is a jQuery object, content[0] returns the bodyContent element
	// Select top-level tooltips
	const tooltips = content[ 0 ].querySelectorAll( '.tooltip:not( .tooltip .tooltip )' );
	
	if ( tooltips ) {
		mw.loader.getScript( 'https://cdn.jsdelivr.net/npm/@popperjs/core@2/dist/umd/popper.js' ).then( function () {
			mw.loader.getScript( ' https://cdn.jsdelivr.net/npm/tippy.js@6/dist/tippy.umd.js' ).then( function () {
				// Load styles for shift-away animation
				mw.loader.load( 'https://cdn.jsdelivr.net/npm/tippy.js@6/animations/shift-away.css', 'text/css' );
	
				const createTippy = function ( element, position ) {
					const tooltipContent = element.querySelector( ':scope > .tooltiptext' );
	
					tippy( element, {
						content: tooltipContent.innerHTML,
						placement: position
					} );
					
					// Make tooltip focusable by keyboard
					element.setAttribute( 'tabindex' ,  '0' );
				};
				
				tippy.setDefaultProps( {
					animation: 'shift-away',
					arrow: true,
					allowHTML: true,
					appendTo: document.body,
					ignoreAttributes: true,
					interactive: true
				} );
	
				tooltips.forEach( function ( tooltip ) {
					createTippy( tooltip, 'top' );
	
					const nestedTooltip = tooltip.querySelector( '.tooltip' );
	
					if ( nestedTooltip ) {
						createTippy( nestedTooltip, 'bottom' );
					}
				} );
			},
			function ( e ) {
				mw.log.error( e.message );
			}
			);
		},
		function ( e ) {
			mw.log.error( e.message );
		} );
	}
} );
Cookies help us deliver our services. By using our services, you agree to our use of cookies.