Attempt to convert to ES5

This commit is contained in:
alistair3149 2020-02-15 18:12:09 -05:00
parent 333385feb5
commit 14600612bb
No known key found for this signature in database
GPG key ID: 94D081060FD3DD9C
3 changed files with 51 additions and 47 deletions

View file

@ -4,53 +4,56 @@
*/
(function() {
// Hide header on scroll down
var didScroll,
lastScrollTop = 0,
navbarHeight = 0;
var delta = 0,
header = document.getElementsByTagName('header')[0],
headerContainer = document.querySelector('.mw-header-container');
// Hide header on scroll down
var didScroll,
lastScrollTop = 0,
navbarHeight = 0,
delta = 0,
header = document.getElementsByTagName('header')[0],
headerContainer = document.querySelector('.mw-header-container');
if (headerContainer !== null) {
navbarHeight = headerContainer.offsetHeight;
}
if (headerContainer !== null) {
navbarHeight = headerContainer.offsetHeight;
}
window.addEventListener('scroll', function() {
didScroll = true;
});
window.addEventListener('scroll', function() {
didScroll = true;
});
function hasScrolled() {
var st = window.scrollY; // Make scroll more than delta
function hasScrolled() {
var st = window.scrollY,
body,
html,
documentHeight;
if (Math.abs(lastScrollTop - st) <= delta) {
return;
}
if (Math.abs(lastScrollTop - st) <= delta) {
return;
}
if (st > lastScrollTop && st > navbarHeight) {
// If scrolled down and past the navbar, add class .nav-up.
// Scroll Down
header.classList.remove('nav-down');
header.classList.add('nav-up');
} else {
// Scroll Up
var body = document.body,
html = document.documentElement,
documentHeight = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight);
if (st > lastScrollTop && st > navbarHeight) {
// If scrolled down and past the navbar, add class .nav-up.
// Scroll Down
header.classList.remove('nav-down');
header.classList.add('nav-up');
} else {
// Scroll Up
body = document.body;
html = document.documentElement;
documentHeight = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight);
if (st + window.innerHeight < documentHeight) {
header.classList.remove('nav-up');
header.classList.add('nav-down');
}
}
if (st + window.innerHeight < documentHeight) {
header.classList.remove('nav-up');
header.classList.add('nav-down');
}
}
lastScrollTop = st;
}
lastScrollTop = st;
}
setInterval(function() {
if (didScroll) {
hasScrolled();
didScroll = false;
}
}, 250);
setInterval(function() {
if (didScroll) {
hasScrolled();
didScroll = false;
}
}, 250);
})();

View file

@ -5,6 +5,8 @@
* Lazyloading images with Native API or IntersectionObserver
*/
var observer;
// Native API
if ('loading' in HTMLImageElement.prototype) {
document.querySelectorAll('img.lazy').forEach(function(img) {
@ -19,7 +21,7 @@ if ('loading' in HTMLImageElement.prototype) {
} else {
// IntersectionObserver API
if (typeof IntersectionObserver !== 'undefined' && 'forEach' in NodeList.prototype) {
var observer = new IntersectionObserver(function(changes) {
observer = new IntersectionObserver(function(changes) {
if ('connection' in navigator && navigator.connection.saveData === true) {
return;
}

View file

@ -28,17 +28,16 @@ function ScrollSpy() {
var sections = document.querySelectorAll(".mw-headline");
window.addEventListener("scroll", function() {
var scrollPos = document.documentElement.scrollTop || document.body.scrollTop,
section, id;
section, id, node, active;
for (section in sections) {
if (
Object.prototype.hasOwnProperty.call(sections, section) &&
sections[section].offsetTop <= scrollPos
) {
id = mw.util.escapeIdForAttribute(sections[section].id),
node = document.querySelector('a[href * = "'.concat(id, '"]'))
.parentNode,
active = document.querySelector(".active");
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");
}