mirror of
https://github.com/StarCitizenTools/mediawiki-skins-Citizen.git
synced 2024-11-27 15:50:34 +00:00
Merge branch 'dev' of github.com:StarCitizenTools/mediawiki-skins-Citizen into dev
This commit is contained in:
commit
14b5ba8e51
|
@ -3,22 +3,22 @@
|
||||||
* Modified from https://codepen.io/sajjad/pen/vgEZNy
|
* Modified from https://codepen.io/sajjad/pen/vgEZNy
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function() {
|
( function () {
|
||||||
// Hide header on scroll down
|
// Hide header on scroll down
|
||||||
var didScroll,
|
var didScroll,
|
||||||
lastScrollTop = 0,
|
lastScrollTop = 0,
|
||||||
navbarHeight = 0,
|
navbarHeight = 0,
|
||||||
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' );
|
||||||
|
|
||||||
if (headerContainer !== null) {
|
if ( headerContainer !== null ) {
|
||||||
navbarHeight = headerContainer.offsetHeight;
|
navbarHeight = headerContainer.offsetHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener('scroll', function() {
|
window.addEventListener( 'scroll', function () {
|
||||||
didScroll = true;
|
didScroll = true;
|
||||||
});
|
} );
|
||||||
|
|
||||||
function hasScrolled() {
|
function hasScrolled() {
|
||||||
var st = window.scrollY,
|
var st = window.scrollY,
|
||||||
|
@ -26,34 +26,34 @@
|
||||||
html,
|
html,
|
||||||
documentHeight;
|
documentHeight;
|
||||||
|
|
||||||
if (Math.abs(lastScrollTop - st) <= delta) {
|
if ( Math.abs( lastScrollTop - st ) <= delta ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (st > lastScrollTop && st > navbarHeight) {
|
if ( st > lastScrollTop && st > navbarHeight ) {
|
||||||
// If scrolled down and past the navbar, add class .nav-up.
|
// If scrolled down and past the navbar, add class .nav-up.
|
||||||
// Scroll Down
|
// Scroll Down
|
||||||
header.classList.remove('nav-down');
|
header.classList.remove( 'nav-down' );
|
||||||
header.classList.add('nav-up');
|
header.classList.add( 'nav-up' );
|
||||||
} else {
|
} else {
|
||||||
// Scroll Up
|
// Scroll Up
|
||||||
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 ) {
|
||||||
header.classList.remove('nav-up');
|
header.classList.remove( 'nav-up' );
|
||||||
header.classList.add('nav-down');
|
header.classList.add( 'nav-down' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lastScrollTop = st;
|
lastScrollTop = st;
|
||||||
}
|
}
|
||||||
|
|
||||||
setInterval(function() {
|
setInterval( function () {
|
||||||
if (didScroll) {
|
if ( didScroll ) {
|
||||||
hasScrolled();
|
hasScrolled();
|
||||||
didScroll = false;
|
didScroll = false;
|
||||||
}
|
}
|
||||||
}, 250);
|
}, 250 );
|
||||||
})();
|
}() );
|
||||||
|
|
|
@ -8,39 +8,39 @@
|
||||||
var observer;
|
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 ) {
|
||||||
img.setAttribute('src', img.getAttribute('data-src'));
|
img.setAttribute( 'src', img.getAttribute( 'data-src' ) );
|
||||||
|
|
||||||
if (img.hasAttribute('data-srcset')) {
|
if ( img.hasAttribute( 'data-srcset' ) ) {
|
||||||
img.setAttribute('srcset', img.getAttribute('data-srcset'));
|
img.setAttribute( 'srcset', img.getAttribute( 'data-srcset' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
img.classList.remove('lazy');
|
img.classList.remove( 'lazy' );
|
||||||
});
|
} );
|
||||||
} else {
|
} else {
|
||||||
// IntersectionObserver API
|
// IntersectionObserver API
|
||||||
if (typeof IntersectionObserver !== 'undefined' && 'forEach' in NodeList.prototype) {
|
if ( typeof IntersectionObserver !== 'undefined' && 'forEach' in NodeList.prototype ) {
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
changes.forEach(function(change) {
|
changes.forEach( function ( change ) {
|
||||||
if (change.isIntersecting) {
|
if ( change.isIntersecting ) {
|
||||||
change.target.setAttribute('src', change.target.getAttribute('data-src'));
|
change.target.setAttribute( 'src', change.target.getAttribute( 'data-src' ) );
|
||||||
|
|
||||||
if (change.target.hasAttribute('data-srcset')) {
|
if ( change.target.hasAttribute( 'data-srcset' ) ) {
|
||||||
change.target.setAttribute('srcset', change.target.getAttribute('data-srcset'));
|
change.target.setAttribute( 'srcset', change.target.getAttribute( 'data-srcset' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
change.target.classList.remove('lazy');
|
change.target.classList.remove( 'lazy' );
|
||||||
observer.unobserve(change.target);
|
observer.unobserve( change.target );
|
||||||
}
|
}
|
||||||
});
|
} );
|
||||||
});
|
} );
|
||||||
document.querySelectorAll('img.lazy').forEach(function(img) {
|
document.querySelectorAll( 'img.lazy' ).forEach( function ( img ) {
|
||||||
observer.observe(img);
|
observer.observe( img );
|
||||||
});
|
} );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,65 +7,65 @@
|
||||||
|
|
||||||
function SmoothScroll() {
|
function SmoothScroll() {
|
||||||
var navLinks, eventListener, link;
|
var navLinks, eventListener, link;
|
||||||
if (!("scrollBehavior" in document.documentElement.style)) {
|
if ( !( 'scrollBehavior' in document.documentElement.style ) ) {
|
||||||
navLinks = document.querySelectorAll("#toc a");
|
navLinks = document.querySelectorAll( '#toc a' );
|
||||||
eventListener = function eventListener(e) {
|
eventListener = function eventListener( e ) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.target.scrollIntoView({
|
e.target.scrollIntoView( {
|
||||||
behavior: "smooth"
|
behavior: 'smooth'
|
||||||
});
|
} );
|
||||||
};
|
};
|
||||||
|
|
||||||
for (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() {
|
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, node, active;
|
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='#" + id + "']").parentNode;
|
node = document.querySelector( "a[href='#" + id + "']" ).parentNode;
|
||||||
active = document.querySelector(".active");
|
active = document.querySelector( '.active' );
|
||||||
if (active !== null) {
|
if ( active !== null ) {
|
||||||
active.classList.remove("active");
|
active.classList.remove( 'active' );
|
||||||
}
|
}
|
||||||
if (node !== null) {
|
if ( node !== null ) {
|
||||||
node.classList.add("active");
|
node.classList.add( 'active' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
function CheckToC() {
|
function CheckToC() {
|
||||||
if (document.getElementById("toc")) {
|
if ( document.getElementById( 'toc' ) ) {
|
||||||
SmoothScroll();
|
SmoothScroll();
|
||||||
ScrollSpy();
|
ScrollSpy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (document.readyState !== "loading") {
|
if ( document.readyState !== 'loading' ) {
|
||||||
CheckToC();
|
CheckToC();
|
||||||
} else if (document.addEventListener) {
|
} else if ( document.addEventListener ) {
|
||||||
// All modern browsers to register DOMContentLoaded
|
// All modern browsers to register DOMContentLoaded
|
||||||
document.addEventListener("DOMContentLoaded", CheckToC);
|
document.addEventListener( 'DOMContentLoaded', CheckToC );
|
||||||
} else {
|
} else {
|
||||||
// Old IE browsers
|
// Old IE browsers
|
||||||
document.attachEvent("onreadystatechange", function() {
|
document.attachEvent( 'onreadystatechange', function () {
|
||||||
if (document.readyState === "complete") {
|
if ( document.readyState === 'complete' ) {
|
||||||
CheckToC();
|
CheckToC();
|
||||||
}
|
}
|
||||||
});
|
} );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue