MediaWiki:Common.js: Difference between revisions

From the Kingdom Hearts Wiki, the Kingdom Hearts encyclopedia
Jump to navigationJump to search
No edit summary
No edit summary
Line 2: Line 2:


/* Automatically add Aboutfile template to file upload description. Source: nl.wikipedia.org/wiki/MediaWiki:Common.js */
/* Automatically add Aboutfile template to file upload description. Source: nl.wikipedia.org/wiki/MediaWiki:Common.js */
if (mw.config.get('wgCanonicalSpecialPageName') === 'Upload' && !document.getElementById('wpForReUpload') && !document.getElementsByClassName('mw-destfile-warning')[0] && !document.getElementsByClassName('error')[0]) {
$(function() {
function loadAutoAboutfileTemplate() {
if (mw.config.get('wgCanonicalSpecialPageName') === 'Upload' && !document.getElementById('wpForReUpload') && !document.getElementsByClassName('mw-destfile-warning')[0] && !document.getElementsByClassName('error')[0]) {
uploadDescription = document.getElementById('wpUploadDescription');
uploadDescription = document.getElementById('wpUploadDescription');
var doubleBracket = '{' + '{';
var doubleBracket = '{' + '{';
uploadDescription.value = doubleBracket + 'aboutfile\n|description=\n|purpose=\n|game=\n|source=\n}}';
uploadDescription.value = doubleBracket + 'aboutfile\n|description=\n|purpose=\n|game=\n|source=\n}}';
}
}
$(loadAutoAboutfileTemplate);
});
}


/* Fix game icons when new user message */
/* Fix game icons when new user message */
if (document.getElementById('title-linktabs') && document.getElementsByClassName('usermessage')[0]) {
$(function() {
function fixGameIcons() {
if (document.getElementById('title-linktabs') && document.getElementsByClassName('usermessage')[0]) {
var gameIcons = $('#title-linktabs');
var gameIcons = $('#title-linktabs');
gameIcons.css('top', '-48px');
gameIcons.css('top', '-48px');
}
}
$(fixGameIcons);
});
}


/* Shrinking talk bubble sprites */
/* Shrinking talk bubble sprites */
$(document).ready(function () {
$(function() {
if (document.readyState != "complete") {
if (document.readyState != "complete") {
setTimeout(arguments.callee, 100);
setTimeout(arguments.callee, 100);
return;
return;
}
}
$("table.talkbubble").each(function () {
$("table.talkbubble").each(function() {
$(this).find("td").first().width(90).css("text-align", "center").find("img").each(function () {
$(this).find("td").first().width(90).css("text-align", "center").find("img").each(function () {
if ($(this).width() > 90) $(this).css("height", "auto").width(90);
if ($(this).width() > 90) $(this).css("height", "auto").width(90);
Line 34: Line 32:


/* Username inserts for the USERNAME template */
/* Username inserts for the USERNAME template */
function UserNameReplace() {
$(function() {
if (typeof(disableUsernameReplace) != 'undefined' && disableUsernameReplace || mw.config.get('wgUserName') == null) return;
if (typeof(disableUsernameReplace) != 'undefined' && disableUsernameReplace || mw.config.get('wgUserName') == null) return;
$('span.insertusername').each(function () {
$('span.insertusername').each(function() {
$(this).text(mw.config.get('wgUserName'));
$(this).text(mw.config.get('wgUserName'));
});
});
}
});
$(UserNameReplace);


/* Alternating wiki logo */
/* Alternating wiki logo */
Line 52: Line 49:
// Author: Soxra
// Author: Soxra
// ==================
// ==================
$(document).ready(function () {
$(function() {
$(".morphMaster").each(function () {
$(".morphMaster").each(function() {
var $master = $(this);
var $master = $(this);
var $tabs = $master.find(".morphTabBox");
var $tabs = $master.find(".morphTabBox");
var $container = $master.find(".morphTabContainer");
var $container = $master.find(".morphTabContainer");


$tabs.find(".morphLink").click(function () {
$tabs.find(".morphLink").click(function() {
var id = $(this).attr("id");
var id = $(this).attr("id");
id = id.substr(0, id.length - 4);
id = id.substr(0, id.length - 4);

Revision as of 16:34, 1 March 2019

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

/* Automatically add Aboutfile template to file upload description. Source: nl.wikipedia.org/wiki/MediaWiki:Common.js */
$(function() {
	if (mw.config.get('wgCanonicalSpecialPageName') === 'Upload' && !document.getElementById('wpForReUpload') && !document.getElementsByClassName('mw-destfile-warning')[0] && !document.getElementsByClassName('error')[0]) {
		uploadDescription = document.getElementById('wpUploadDescription');
		var doubleBracket = '{' + '{';
		uploadDescription.value = doubleBracket + 'aboutfile\n|description=\n|purpose=\n|game=\n|source=\n}}';
	}
});

/* Fix game icons when new user message */
$(function() {
	if (document.getElementById('title-linktabs') && document.getElementsByClassName('usermessage')[0]) {
		var gameIcons = $('#title-linktabs');
		gameIcons.css('top', '-48px');
	}
});

/* Shrinking talk bubble sprites */
$(function() {
	if (document.readyState != "complete") {
		setTimeout(arguments.callee, 100);
		return;
	}
	$("table.talkbubble").each(function() {
		$(this).find("td").first().width(90).css("text-align", "center").find("img").each(function () {
			if ($(this).width() > 90) $(this).css("height", "auto").width(90);
		});
	});
});

/* Username inserts for the USERNAME template */
$(function() {
	if (typeof(disableUsernameReplace) != 'undefined' && disableUsernameReplace || mw.config.get('wgUserName') == null) return;
	$('span.insertusername').each(function() {
		$(this).text(mw.config.get('wgUserName'));
	});
});

/* Alternating wiki logo */
$(function() {
	var logos = ['/images/b/bc/Wiki.png', '/images/9/97/Wiki_3.png', '/images/d/d7/Wiki_2.png'];
	$('#p-logo a').css('background-image', 'url(' + logos[Math.floor(Math.random() * logos.length)] + ')');
});

// ==================
// Code for Template:Suite3
// Author: Soxra
// ==================
$(function() {
	$(".morphMaster").each(function() {
		var $master = $(this);
		var $tabs = $master.find(".morphTabBox");
		var $container = $master.find(".morphTabContainer");

		$tabs.find(".morphLink").click(function() {
			var id = $(this).attr("id");
			id = id.substr(0, id.length - 4);
			$container.find(".morphContent").hide();
			$container.find("#" + id + "Content").show();
		});
	});
});