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 18: Zeile 18:
 
window.addEventListener("hashchange", thkOnHashChangedListener);
 
window.addEventListener("hashchange", thkOnHashChangedListener);
   
 
var firstA = document.querySelector('#toc a:first-of-type');
var thkOnLoadListener = function(){
 
  +
console.log(firstA);
var firstA = document.querySelector('#toc a:first-of-type');
 
console.log(firstA);
+
if (firstA !== null) {
if (firstA !== null) {
+
firstA.classList.add(className);
 
}
firstA.classList.add(className);
 
}
 
};
 
 
window.addEventListener("load", thkOnLoadListener);
 
   
 
})();
 
})();

Version vom 16. Juli 2023, 12:14 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 firstA = document.querySelector('#toc a:first-of-type');
console.log(firstA);
if (firstA !== null) {
  firstA.classList.add(className);
}

})();