MediaWiki:Common.js: Unterschied zwischen den Versionen

Aus Lost Dreams Of Tomorrow Wiki
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 1: Zeile 1:
//assign custom sidebar collapsible classes
/* Any JavaScript here will be loaded for all users on every page load. */
$("#mw-site-navigation .sidebar-chunk h3, #mw-site-navigation .sidebar-chunk label").addClass("sidebar-collapsible");
$("#mw-site-navigation .sidebar-chunk .sidebar-inner, #mw-site-navigation .sidebar-chunk ul").addClass("sidebar-collapsible-content");
$("#mw-site-navigation").prepend("<div id=\"sidebar-collapsible-toggle\">Expand All</div>");


//hide content except for the ones specified as expanded
$(document).ready(function(){
var expandedContentTitles = ['Players', 'World']; // Edit: Which sections start open
// Username replacement
$(".sidebar-collapsible-content").each(function() {
$.each($('.username'), function(){
var headerText = $(this).prev('.sidebar-collapsible').text().trim();
var username = mw.config.get('wgUserName');
if (!expandedContentTitles.includes(headerText)) {
if (!username) {
$(this).prev('.sidebar-collapsible').addClass('closed');
username = "Pro Gamer";
$(this).hide();
}
} else {
$(this).text(username);
$(this).prev('.sidebar-collapsible').addClass('open');
});
$(this).show();
 
}
// Assign custom sidebar collapsible classes
$("#mw-site-navigation .sidebar-chunk h3, #mw-site-navigation .sidebar-chunk label").addClass("sidebar-collapsible");
$("#mw-site-navigation .sidebar-chunk .sidebar-inner, #mw-site-navigation .sidebar-chunk ul").addClass("sidebar-collapsible-content");
$("#mw-site-navigation").prepend("<div id=\"sidebar-collapsible-toggle\">Expand All</div>");
 
// Hide content except for the ones specified as expanded
var expandedContentTitles = ['Players', 'World']; // Edit: Which sections start open
$(".sidebar-collapsible-content").each(function() {
var headerText = $(this).prev('.sidebar-collapsible').text().trim();
if (!expandedContentTitles.includes(headerText)) {
$(this).prev('.sidebar-collapsible').addClass('closed');
$(this).hide();
} else {
$(this).prev('.sidebar-collapsible').addClass('open');
$(this).show();
}
});
 
// On section title click, show/hide contents and toggle between little right/down arrow
$(".sidebar-collapsible").click(function() {
$(this).toggleClass('open closed');
$(this).next('.sidebar-collapsible-content').slideToggle(200);
});
 
// On Expand/Close All click, show/hide all contents and toggle text
$("#sidebar-collapsible-toggle").click(function() {
if($("#sidebar-collapsible-toggle").text() == "Expand All") {
$(".sidebar-collapsible-content").slideDown(200);
$(".sidebar-collapsible").addClass('open').removeClass('closed');
$("#sidebar-collapsible-toggle").text("Close All");
} else {
$(".sidebar-collapsible-content").slideUp(200);
$(".sidebar-collapsible").addClass('closed').removeClass('open');
$("#sidebar-collapsible-toggle").text("Expand All");
}
});
});
});


// on section title click, show/hide contents and toggle between little right/down arrow.
mw.loader.using('mobile.site.styles');
$(".sidebar-collapsible").click(function() {
 
$(this).toggleClass('open closed');
/* Sets the top property for stickyHeader tables */
$(this).next('.sidebar-collapsible-content').slideToggle(200);
function setStickyHeaderTop() {
});
  const stickyTables = document.getElementsByClassName('stickyHeader');
  const headHeight = document.getElementById('mw-header-container').offsetHeight;
  for (i = 0; i < stickyTables.length; i++) {
    const firstRow = stickyTables[i].getElementsByClassName('headerRow-0');
    const secondRow = stickyTables[i].getElementsByClassName('headerRow-1');
    var firstHeight = 0;
    if (firstRow.length > 0) {
      firstHeight = firstRow[0].offsetHeight;
      const firstHeaders = firstRow[0].getElementsByTagName('th');
      for (j = 0; j < firstHeaders.length; j++) {
        firstHeaders[j].style.top = headHeight + 'px';
      }
      if (secondRow.length > 0) {
        const secondHeaders = secondRow[0].getElementsByTagName('th');
        var secondHeight = headHeight + firstHeight;
        for (j = 0; j < secondHeaders.length; j++) {
          secondHeaders[j].style.top = secondHeight + 'px';
        }
      }
    }
  }
}


// On Expand/Close All click, show/hide all contents and toggle text.
$(document).ready(function () {
$("#sidebar-collapsible-toggle").click(function() {
  if (document.getElementsByClassName('stickyHeader').length > 0) {
if($("#sidebar-collapsible-toggle").text() == "Expand All") {
    setStickyHeaderTop();
$(".sidebar-collapsible-content").slideDown(200);
    $(window).resize(setStickyHeaderTop);
$(".sidebar-collapsible").addClass('open').removeClass('closed');
  }
$("#sidebar-collapsible-toggle").text("Close All");
} else {
$(".sidebar-collapsible-content").slideUp(200);
$(".sidebar-collapsible").addClass('closed').removeClass('open');
$("#sidebar-collapsible-toggle").text("Expand All");
}
});
});

Version vom 11. Januar 2026, 04:19 Uhr

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

$(document).ready(function(){
	// Username replacement
	$.each($('.username'), function(){
		var username = mw.config.get('wgUserName');
		if (!username) {
			username = "Pro Gamer";
		}
	 	$(this).text(username);
	});

	// Assign custom sidebar collapsible classes
	$("#mw-site-navigation .sidebar-chunk h3, #mw-site-navigation .sidebar-chunk label").addClass("sidebar-collapsible");
	$("#mw-site-navigation .sidebar-chunk .sidebar-inner, #mw-site-navigation .sidebar-chunk ul").addClass("sidebar-collapsible-content");
	$("#mw-site-navigation").prepend("<div id=\"sidebar-collapsible-toggle\">Expand All</div>");

	// Hide content except for the ones specified as expanded
	var expandedContentTitles = ['Players', 'World']; // Edit: Which sections start open
	$(".sidebar-collapsible-content").each(function() {
		var headerText = $(this).prev('.sidebar-collapsible').text().trim();
		if (!expandedContentTitles.includes(headerText)) {
			$(this).prev('.sidebar-collapsible').addClass('closed');
			$(this).hide();
		} else {
			$(this).prev('.sidebar-collapsible').addClass('open');
			$(this).show();
		}
	});

	// On section title click, show/hide contents and toggle between little right/down arrow
	$(".sidebar-collapsible").click(function() {
		$(this).toggleClass('open closed');
		$(this).next('.sidebar-collapsible-content').slideToggle(200);
	});

	// On Expand/Close All click, show/hide all contents and toggle text
	$("#sidebar-collapsible-toggle").click(function() {
		if($("#sidebar-collapsible-toggle").text() == "Expand All") {
			$(".sidebar-collapsible-content").slideDown(200);
			$(".sidebar-collapsible").addClass('open').removeClass('closed');
			$("#sidebar-collapsible-toggle").text("Close All");
		} else {
			$(".sidebar-collapsible-content").slideUp(200);
			$(".sidebar-collapsible").addClass('closed').removeClass('open');
			$("#sidebar-collapsible-toggle").text("Expand All");
		}
	});
});

mw.loader.using('mobile.site.styles');

/* Sets the top property for stickyHeader tables */
function setStickyHeaderTop() {
  const stickyTables = document.getElementsByClassName('stickyHeader');
  const headHeight = document.getElementById('mw-header-container').offsetHeight;
  for (i = 0; i < stickyTables.length; i++) {
    const firstRow = stickyTables[i].getElementsByClassName('headerRow-0');
    const secondRow = stickyTables[i].getElementsByClassName('headerRow-1');
    var firstHeight = 0;
    if (firstRow.length > 0) {
      firstHeight = firstRow[0].offsetHeight;
      const firstHeaders = firstRow[0].getElementsByTagName('th');
      for (j = 0; j < firstHeaders.length; j++) {
        firstHeaders[j].style.top = headHeight + 'px';
      }
      if (secondRow.length > 0) {
        const secondHeaders = secondRow[0].getElementsByTagName('th');
        var secondHeight = headHeight + firstHeight;
        for (j = 0; j < secondHeaders.length; j++) {
          secondHeaders[j].style.top = secondHeight + 'px';
        }
      }
    }
  }
}

$(document).ready(function () {
  if (document.getElementsByClassName('stickyHeader').length > 0) {
    setStickyHeaderTop();
    $(window).resize(setStickyHeaderTop);
  }
});