MediaWiki:Common.js: Unterschied zwischen den Versionen
Aus Populus DE
Zur Navigation springenZur Suche springenThk (Diskussion | Beiträge) |
Thk (Diskussion | Beiträge) |
||
Zeile 1: | Zeile 1: | ||
(function () { |
(function () { |
||
+ | |||
+ | const className = "selected"; |
||
var thkOnHashChangedListener = function(){ |
var thkOnHashChangedListener = function(){ |
||
− | var prev = document.querySelector('#toc a. |
+ | var prev = document.querySelector('#toc a.' + className); |
if (prev !== null) { |
if (prev !== null) { |
||
− | prev.classList.remove( |
+ | 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( |
+ | curr.classList.add(className); |
} |
} |
||
}; |
}; |
||
Zeile 16: | Zeile 18: | ||
window.addEventListener("hashchange", thkOnHashChangedListener); |
window.addEventListener("hashchange", thkOnHashChangedListener); |
||
− | var |
+ | var thkOnLoadListener = function(){ |
− | document.querySelector('#toc a:first-of-type').classList.add( |
+ | 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); })();