MediaWiki:Common.js: Unterschied zwischen den Versionen

Aus Lost Dreams Of Tomorrow Wiki
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 9: Zeile 9:
});
});


// Debug: Log what we find
console.log("Sidebar chunks found:", $("#mw-site-navigation .sidebar-chunk").length);
// Assign custom sidebar collapsible classes
// Assign custom sidebar collapsible classes
$("#mw-site-navigation .sidebar-chunk").each(function() {
$("#mw-site-navigation .sidebar-chunk").each(function() {
Zeile 17: Zeile 14:
var $header = $chunk.find('h3, label').first();
var $header = $chunk.find('h3, label').first();
var $content = $chunk.find('.sidebar-inner, ul, .mw-portlet-body').first();
var $content = $chunk.find('.sidebar-inner, ul, .mw-portlet-body').first();
console.log("Header:", $header.text(), "Content found:", $content.length);
if ($header.length && $content.length) {
if ($header.length && $content.length) {
$header.addClass("sidebar-collapsible");
$header.addClass("sidebar-collapsible");
$content.addClass("sidebar-collapsible-content");
$content.addClass("sidebar-collapsible-content");
// Store reference to content in header's data
$header.data('content', $content);
}
}
});
});
Zeile 32: Zeile 30:
$(".sidebar-collapsible").each(function() {
$(".sidebar-collapsible").each(function() {
var headerText = $(this).text().trim();
var headerText = $(this).text().trim();
var $content = $(this).siblings('.sidebar-collapsible-content').first();
var $content = $(this).data('content');
if (!$content.length) {
$content = $(this).parent().find('.sidebar-collapsible-content').first();
}
console.log("Processing:", headerText, "Content siblings:", $content.length);
if (!expandedContentTitles.includes(headerText)) {
if (!expandedContentTitles.includes(headerText)) {
Zeile 52: Zeile 44:
$(".sidebar-collapsible").click(function() {
$(".sidebar-collapsible").click(function() {
$(this).toggleClass('open closed');
$(this).toggleClass('open closed');
var $content = $(this).siblings('.sidebar-collapsible-content').first();
var $content = $(this).data('content');
if (!$content.length) {
$content = $(this).parent().find('.sidebar-collapsible-content').first();
}
console.log("Click - Content to toggle:", $content.length);
$content.slideToggle(200);
$content.slideToggle(200);
});
});
Zeile 74: Zeile 60:
}
}
});
});
});
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);
  }
});
});

Version vom 11. Januar 2026, 04:21 Uhr

$(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").each(function() {
		var $chunk = $(this);
		var $header = $chunk.find('h3, label').first();
		var $content = $chunk.find('.sidebar-inner, ul, .mw-portlet-body').first();
		
		if ($header.length && $content.length) {
			$header.addClass("sidebar-collapsible");
			$content.addClass("sidebar-collapsible-content");
			
			// Store reference to content in header's data
			$header.data('content', $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'];
	$(".sidebar-collapsible").each(function() {
		var headerText = $(this).text().trim();
		var $content = $(this).data('content');
		
		if (!expandedContentTitles.includes(headerText)) {
			$(this).addClass('closed');
			$content.hide();
		} else {
			$(this).addClass('open');
			$content.show();
		}
	});

	// On section title click
	$(".sidebar-collapsible").click(function() {
		$(this).toggleClass('open closed');
		var $content = $(this).data('content');
		$content.slideToggle(200);
	});

	// Expand/Close All
	$("#sidebar-collapsible-toggle").click(function() {
		if($(this).text() == "Expand All") {
			$(".sidebar-collapsible-content").slideDown(200);
			$(".sidebar-collapsible").addClass('open').removeClass('closed');
			$(this).text("Close All");
		} else {
			$(".sidebar-collapsible-content").slideUp(200);
			$(".sidebar-collapsible").addClass('closed').removeClass('open');
			$(this).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);
  }
});