mirror of
https://github.com/StarCitizenTools/mediawiki-skins-Citizen.git
synced 2024-11-25 14:57:31 +00:00
Attempt to convert to ES5
This commit is contained in:
parent
333385feb5
commit
14600612bb
|
@ -7,8 +7,8 @@
|
||||||
// Hide header on scroll down
|
// Hide header on scroll down
|
||||||
var didScroll,
|
var didScroll,
|
||||||
lastScrollTop = 0,
|
lastScrollTop = 0,
|
||||||
navbarHeight = 0;
|
navbarHeight = 0,
|
||||||
var delta = 0,
|
delta = 0,
|
||||||
header = document.getElementsByTagName('header')[0],
|
header = document.getElementsByTagName('header')[0],
|
||||||
headerContainer = document.querySelector('.mw-header-container');
|
headerContainer = document.querySelector('.mw-header-container');
|
||||||
|
|
||||||
|
@ -21,7 +21,10 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
function hasScrolled() {
|
function hasScrolled() {
|
||||||
var st = window.scrollY; // Make scroll more than delta
|
var st = window.scrollY,
|
||||||
|
body,
|
||||||
|
html,
|
||||||
|
documentHeight;
|
||||||
|
|
||||||
if (Math.abs(lastScrollTop - st) <= delta) {
|
if (Math.abs(lastScrollTop - st) <= delta) {
|
||||||
return;
|
return;
|
||||||
|
@ -34,8 +37,8 @@
|
||||||
header.classList.add('nav-up');
|
header.classList.add('nav-up');
|
||||||
} else {
|
} else {
|
||||||
// Scroll Up
|
// Scroll Up
|
||||||
var body = document.body,
|
body = document.body;
|
||||||
html = document.documentElement,
|
html = document.documentElement;
|
||||||
documentHeight = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight);
|
documentHeight = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight);
|
||||||
|
|
||||||
if (st + window.innerHeight < documentHeight) {
|
if (st + window.innerHeight < documentHeight) {
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
* Lazyloading images with Native API or IntersectionObserver
|
* Lazyloading images with Native API or IntersectionObserver
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
var observer;
|
||||||
|
|
||||||
// Native API
|
// Native API
|
||||||
if ('loading' in HTMLImageElement.prototype) {
|
if ('loading' in HTMLImageElement.prototype) {
|
||||||
document.querySelectorAll('img.lazy').forEach(function(img) {
|
document.querySelectorAll('img.lazy').forEach(function(img) {
|
||||||
|
@ -19,7 +21,7 @@ if ('loading' in HTMLImageElement.prototype) {
|
||||||
} else {
|
} else {
|
||||||
// IntersectionObserver API
|
// IntersectionObserver API
|
||||||
if (typeof IntersectionObserver !== 'undefined' && 'forEach' in NodeList.prototype) {
|
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) {
|
if ('connection' in navigator && navigator.connection.saveData === true) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,16 +28,15 @@ function ScrollSpy() {
|
||||||
var sections = document.querySelectorAll(".mw-headline");
|
var sections = document.querySelectorAll(".mw-headline");
|
||||||
window.addEventListener("scroll", function() {
|
window.addEventListener("scroll", function() {
|
||||||
var scrollPos = document.documentElement.scrollTop || document.body.scrollTop,
|
var scrollPos = document.documentElement.scrollTop || document.body.scrollTop,
|
||||||
section, id;
|
section, id, node, active;
|
||||||
|
|
||||||
for (section in sections) {
|
for (section in sections) {
|
||||||
if (
|
if (
|
||||||
Object.prototype.hasOwnProperty.call(sections, section) &&
|
Object.prototype.hasOwnProperty.call(sections, section) &&
|
||||||
sections[section].offsetTop <= scrollPos
|
sections[section].offsetTop <= scrollPos
|
||||||
) {
|
) {
|
||||||
id = mw.util.escapeIdForAttribute(sections[section].id),
|
id = mw.util.escapeIdForAttribute(sections[section].id);
|
||||||
node = document.querySelector('a[href * = "'.concat(id, '"]'))
|
node = document.querySelector('a[href * = "'.concat(id, '"]')).parentNode;
|
||||||
.parentNode,
|
|
||||||
active = document.querySelector(".active");
|
active = document.querySelector(".active");
|
||||||
if (active !== null) {
|
if (active !== null) {
|
||||||
active.classList.remove("active");
|
active.classList.remove("active");
|
||||||
|
|
Loading…
Reference in a new issue