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

@ -7,8 +7,8 @@
// Hide header on scroll down
var didScroll,
lastScrollTop = 0,
navbarHeight = 0;
var delta = 0,
navbarHeight = 0,
delta = 0,
header = document.getElementsByTagName('header')[0],
headerContainer = document.querySelector('.mw-header-container');
@ -21,7 +21,10 @@
});
function hasScrolled() {
var st = window.scrollY; // Make scroll more than delta
var st = window.scrollY,
body,
html,
documentHeight;
if (Math.abs(lastScrollTop - st) <= delta) {
return;
@ -34,8 +37,8 @@
header.classList.add('nav-up');
} else {
// Scroll Up
var body = document.body,
html = document.documentElement,
body = document.body;
html = document.documentElement;
documentHeight = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight);
if (st + window.innerHeight < documentHeight) {

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,16 +28,15 @@ 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,
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");