Difference between revisions of "MediaWiki:Common.js"

From Pathfinder Wiki
(Created page with "→‎Any JavaScript here will be loaded for all users on every page load.: var interfaceLang = document.documentElement.lang; var navItems = [ 'n-Home', 'n-All-Honors', 'n-...")
 
 
Line 1: Line 1:
 
/* Any JavaScript here will be loaded for all users on every page load. */
 
/* Any JavaScript here will be loaded for all users on every page load. */
 
var interfaceLang = document.documentElement.lang;
 
var interfaceLang = document.documentElement.lang;
 +
if (interfaceLang === 'pt') {
 +
interfaceLang = 'pt-br';
 +
}
 
var navItems = [
 
var navItems = [
 
'n-Home',
 
'n-Home',
Line 17: Line 20:
 
];
 
];
  
if (interfaceLang !== 'en') {
+
if (
//navItems.forEach((item) => {
+
interfaceLang === 'es' ||
 +
interfaceLang === 'de' ||
 +
interfaceLang === 'pt-br' ||
 +
interfaceLang === 'fr'
 +
) {
 
for (var i = 0; i < navItems.length; i++) {
 
for (var i = 0; i < navItems.length; i++) {
 
var parent = document.getElementById(navItems[i]);
 
var parent = document.getElementById(navItems[i]);
Line 27: Line 34:
 
}
 
}
 
}
 
}
//});
 
 
}
 
}

Latest revision as of 20:22, 29 July 2022

/* Any JavaScript here will be loaded for all users on every page load. */
var interfaceLang = document.documentElement.lang;
if (interfaceLang === 'pt') {
	interfaceLang = 'pt-br';
}
var navItems = [
	'n-Home',
	'n-All-Honors',
	'n-Arts.2C-Crafts.2C-and-Hobbies',
	'n-Health-and-Science',
	'n-Household-Arts',
	'n-Nature',
	'n-Outdoor-Industries',
	'n-Recreation',
	'n-Spiritual-Growth.2C-Outreach-and-Heritage',
	'n-Vocational',
	'n-Honor-Pilots',
	'n-Investiture-Achievement',
	'n-Master-Guide',
];

if (
	interfaceLang === 'es' ||
	interfaceLang === 'de' ||
	interfaceLang === 'pt-br' ||
	interfaceLang === 'fr'
	) {
	for (var i = 0; i < navItems.length; i++) {
		var parent = document.getElementById(navItems[i]);
		if (parent) {
			if (parent.childNodes[0] && parent.childNodes[0].tagName === 'A') {
				parent.childNodes[0].href = parent.childNodes[0].href +'/'+interfaceLang;
			}
		}
	}
}