mirror of
https://github.com/StarCitizenTools/mediawiki-skins-Citizen.git
synced 2024-11-25 06:47:16 +00:00
Attempt to convert to ES5
This commit is contained in:
parent
ed22023fce
commit
a40547ec1b
|
@ -5,56 +5,57 @@
|
||||||
* Smooth scroll fallback and Scrollspy
|
* Smooth scroll fallback and Scrollspy
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var SmoothScroll = function SmoothScroll() {
|
function SmoothScroll() {
|
||||||
if (!("scrollBehavior" in document.documentElement.style)) {
|
var navLinks, eventListener, link;
|
||||||
var navLinks = document.querySelectorAll("#toc a"),
|
if (!("scrollBehavior" in document.documentElement.style)) {
|
||||||
eventListener = function eventListener(e) {
|
navLinks = document.querySelectorAll("#toc a"),
|
||||||
e.preventDefault();
|
eventListener = function eventListener(e) {
|
||||||
e.target.scrollIntoView({
|
e.preventDefault();
|
||||||
behavior: "smooth"
|
e.target.scrollIntoView({
|
||||||
});
|
behavior: "smooth"
|
||||||
};
|
});
|
||||||
|
};
|
||||||
|
|
||||||
for (var link in navLinks) {
|
for (link in navLinks) {
|
||||||
if (Object.prototype.hasOwnProperty.call(navLinks, link)) {
|
if (Object.prototype.hasOwnProperty.call(navLinks, link)) {
|
||||||
navLinks[link].addEventListener("click", eventListener);
|
navLinks[link].addEventListener("click", eventListener);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
function ScrollSpy() {
|
||||||
|
var sections = document.querySelectorAll(".mw-headline");
|
||||||
|
window.addEventListener("scroll", function() {
|
||||||
|
var scrollPos =
|
||||||
|
document.documentElement.scrollTop || document.body.scrollTop;
|
||||||
|
|
||||||
|
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");
|
||||||
|
|
||||||
|
if (active !== null) {
|
||||||
|
active.classList.remove("active");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node !== null) {
|
||||||
|
node.classList.add("active");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
});
|
||||||
ScrollSpy = function ScrollSpy() {
|
},
|
||||||
var sections = document.querySelectorAll(".mw-headline");
|
function CheckToC() {
|
||||||
window.addEventListener("scroll", function() {
|
if (document.getElementById("toc")) {
|
||||||
var scrollPos =
|
SmoothScroll();
|
||||||
document.documentElement.scrollTop || document.body.scrollTop;
|
ScrollSpy();
|
||||||
|
}
|
||||||
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");
|
|
||||||
|
|
||||||
if (active !== null) {
|
|
||||||
active.classList.remove("active");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (node !== null) {
|
|
||||||
node.classList.add("active");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
CheckToC = function CheckToC() {
|
|
||||||
if (document.getElementById("toc")) {
|
|
||||||
SmoothScroll();
|
|
||||||
ScrollSpy();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (document.readyState !== "loading") {
|
if (document.readyState !== "loading") {
|
||||||
CheckToC();
|
CheckToC();
|
||||||
|
|
Loading…
Reference in a new issue