Mitarbeit willkommen! Bitte schau unter Hilfe:Benutzerkonto oder informiere Dich über Populus.Wiki.

MediaWiki:Common.js: Unterschied zwischen den Versionen

Aus Populus DE
Zur Navigation springenZur Suche springen
Zeile 1: Zeile 1:
 
(function () {
 
(function () {
  +
  +
const className = "selected";
   
 
var thkOnHashChangedListener = function(){
 
var thkOnHashChangedListener = function(){
var prev = document.querySelector('#toc a.selected');
+
var prev = document.querySelector('#toc a.' + className);
   
 
if (prev !== null) {
 
if (prev !== null) {
prev.classList.remove('selected');
+
prev.classList.remove(className);
 
}
 
}
   
 
var curr = document.querySelector('#toc a[href="' + window.location.hash + '"]');
 
var curr = document.querySelector('#toc a[href="' + window.location.hash + '"]');
 
if (curr !== null) {
 
if (curr !== null) {
curr.classList.add('selected');
+
curr.classList.add(className);
 
}
 
}
 
};
 
};
Zeile 16: Zeile 18:
 
window.addEventListener("hashchange", thkOnHashChangedListener);
 
window.addEventListener("hashchange", thkOnHashChangedListener);
   
var thkOnHashChangedListener = function(){
+
var thkOnLoadListener = function(){
document.querySelector('#toc a:first-of-type').classList.add('selected');
+
document.querySelector('#toc a:first-of-type').classList.add(className);
 
};
 
};
   

Version vom 16. Juli 2023, 12:10 Uhr

(function () {

const className = "selected";

var thkOnHashChangedListener = function(){
  var prev = document.querySelector('#toc a.' + className);

  if (prev !== null) {
    prev.classList.remove(className);
  }

  var curr = document.querySelector('#toc a[href="' + window.location.hash + '"]');
  if (curr !== null) {
    curr.classList.add(className);
  }
};

window.addEventListener("hashchange", thkOnHashChangedListener);

var thkOnLoadListener = function(){
  document.querySelector('#toc a:first-of-type').classList.add(className);
};

window.addEventListener("load", thkOnLoadListener);

})();