mirror of
https://github.com/StarCitizenTools/mediawiki-skins-Citizen.git
synced 2024-11-25 14:57:31 +00:00
Converted toc script from ES6 to ES5
This commit is contained in:
parent
54f03d7c3a
commit
ed22023fce
|
@ -5,66 +5,67 @@
|
|||
* Smooth scroll fallback and Scrollspy
|
||||
*/
|
||||
|
||||
const SmoothScroll = () => {
|
||||
if ( !( 'scrollBehavior' in document.documentElement.style ) ) {
|
||||
const navLinks = document.querySelectorAll( '#toc a' ),
|
||||
eventListener = e => {
|
||||
var SmoothScroll = function SmoothScroll() {
|
||||
if (!("scrollBehavior" in document.documentElement.style)) {
|
||||
var navLinks = document.querySelectorAll("#toc a"),
|
||||
eventListener = function eventListener(e) {
|
||||
e.preventDefault();
|
||||
e.target.scrollIntoView( {
|
||||
behavior: 'smooth'
|
||||
} );
|
||||
e.target.scrollIntoView({
|
||||
behavior: "smooth"
|
||||
});
|
||||
};
|
||||
|
||||
for ( let link in navLinks ) {
|
||||
if ( Object.prototype.hasOwnProperty.call( navLinks, link ) ) {
|
||||
navLinks[ link ].addEventListener( 'click', eventListener );
|
||||
for (var link in navLinks) {
|
||||
if (Object.prototype.hasOwnProperty.call(navLinks, link)) {
|
||||
navLinks[link].addEventListener("click", eventListener);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
ScrollSpy = function ScrollSpy() {
|
||||
var sections = document.querySelectorAll(".mw-headline");
|
||||
window.addEventListener("scroll", function() {
|
||||
var scrollPos =
|
||||
document.documentElement.scrollTop || document.body.scrollTop;
|
||||
|
||||
ScrollSpy = () => {
|
||||
const sections = document.querySelectorAll( '.mw-headline' );
|
||||
for (var section in sections) {
|
||||
if (
|
||||
Object.prototype.hasOwnProperty.call(sections, section) &&
|
||||
sections[section].offsetTop <= scrollPos
|
||||
) {
|
||||
var id = mw.util.escapeIdForAttribute(sections[section].id),
|
||||
node = document.querySelector('a[href * = "'.concat(id, '"]'))
|
||||
.parentNode,
|
||||
active = document.querySelector(".active");
|
||||
|
||||
window.addEventListener( 'scroll', () => {
|
||||
const scrollPos = document.documentElement.scrollTop || document.body.scrollTop;
|
||||
|
||||
for ( let section in sections ) {
|
||||
if ( Object.prototype.hasOwnProperty.call( sections, section ) &&
|
||||
sections[ section ].offsetTop <= scrollPos ) {
|
||||
const id = mw.util.escapeIdForAttribute( sections[ section ].id ),
|
||||
node = document.querySelector( `a[href * = "${id}"]` ).parentNode,
|
||||
active = document.querySelector( '.active' );
|
||||
|
||||
if ( active !== null ) {
|
||||
active.classList.remove( 'active' );
|
||||
if (active !== null) {
|
||||
active.classList.remove("active");
|
||||
}
|
||||
|
||||
if ( node !== null ) {
|
||||
node.classList.add( 'active' );
|
||||
if (node !== null) {
|
||||
node.classList.add("active");
|
||||
}
|
||||
}
|
||||
}
|
||||
} );
|
||||
});
|
||||
},
|
||||
|
||||
CheckToC = () => {
|
||||
if ( document.getElementById( 'toc' ) ) {
|
||||
CheckToC = function CheckToC() {
|
||||
if (document.getElementById("toc")) {
|
||||
SmoothScroll();
|
||||
ScrollSpy();
|
||||
}
|
||||
};
|
||||
|
||||
if ( document.readyState !== 'loading' ) {
|
||||
if (document.readyState !== "loading") {
|
||||
CheckToC();
|
||||
} else if ( document.addEventListener ) {
|
||||
} else if (document.addEventListener) {
|
||||
// All modern browsers to register DOMContentLoaded
|
||||
document.addEventListener( 'DOMContentLoaded', CheckToC );
|
||||
document.addEventListener("DOMContentLoaded", CheckToC);
|
||||
} else {
|
||||
// Old IE browsers
|
||||
document.attachEvent( 'onreadystatechange', function () {
|
||||
if ( document.readyState === 'complete' ) {
|
||||
document.attachEvent("onreadystatechange", function() {
|
||||
if (document.readyState === "complete") {
|
||||
CheckToC();
|
||||
}
|
||||
} );
|
||||
});
|
||||
}
|
Loading…
Reference in a new issue