MediaWiki:Common.js: Unterschied zwischen den Versionen

Aus Lost Dreams Of Tomorrow Wiki
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 1: Zeile 1:
$(document).ready(function(){
// MediaWiki Sidebar Toggle Script
// Username replacement
$(document).ready(function() {
$.each($('.username'), function(){
    // Finde alle sidebar-collapsible Überschriften
var username = mw.config.get('wgUserName');
    $('.sidebar-collapsible').each(function() {
if (!username) {
        var $header = $(this);
username = "Pro Gamer";
        var $portletBody = $header.next('.mw-portlet-body');
}
       
$(this).text(username);
        // Füge ein Icon hinzu
});
        if ($header.find('.toggle-icon').length === 0) {
 
            $header.prepend('<span class="toggle-icon"></span> ');
// 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';
         }
         }
      }
       
    }
        // Mache die Überschrift klickbar
  }
        $header.css('cursor', 'pointer');
}
       
 
        // Überprüfe den initialen Status (open/closed Klasse)
$(document).ready(function () {
        if (!$header.hasClass('open')) {
  if (document.getElementsByClassName('stickyHeader').length > 0) {
            $portletBody.hide();
    setStickyHeaderTop();
            $header.find('.toggle-icon').text('▶');
    $(window).resize(setStickyHeaderTop);
        }
  }
       
        // Click Event
        $header.on('click', function(e) {
            e.preventDefault();
           
            var $icon = $(this).find('.toggle-icon');
            var $body = $(this).next('.mw-portlet-body');
           
            // Toggle
            if ($body.is(':visible')) {
                $body.slideUp(200);
                $icon.text('▶');
                $(this).removeClass('open');
            } else {
                $body.slideDown(200);
                $icon.text('▼');
                $(this).addClass('open');
            }
        });
    });
});
});

Version vom 11. Januar 2026, 04:26 Uhr

// MediaWiki Sidebar Toggle Script
$(document).ready(function() {
    // Finde alle sidebar-collapsible Überschriften
    $('.sidebar-collapsible').each(function() {
        var $header = $(this);
        var $portletBody = $header.next('.mw-portlet-body');
        
        // Füge ein Icon hinzu
        if ($header.find('.toggle-icon').length === 0) {
            $header.prepend('<span class="toggle-icon">▼</span> ');
        }
        
        // Mache die Überschrift klickbar
        $header.css('cursor', 'pointer');
        
        // Überprüfe den initialen Status (open/closed Klasse)
        if (!$header.hasClass('open')) {
            $portletBody.hide();
            $header.find('.toggle-icon').text('▶');
        }
        
        // Click Event
        $header.on('click', function(e) {
            e.preventDefault();
            
            var $icon = $(this).find('.toggle-icon');
            var $body = $(this).next('.mw-portlet-body');
            
            // Toggle
            if ($body.is(':visible')) {
                $body.slideUp(200);
                $icon.text('▶');
                $(this).removeClass('open');
            } else {
                $body.slideDown(200);
                $icon.text('▼');
                $(this).addClass('open');
            }
        });
    });
});