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
|
||||
*/
|
||||
|
||||
(function() {
|
||||
( function () {
|
||||
// Hide header on scroll down
|
||||
var didScroll,
|
||||
lastScrollTop = 0,
|
||||
navbarHeight = 0,
|
||||
delta = 0,
|
||||
header = document.getElementsByTagName('header')[0],
|
||||
headerContainer = document.querySelector('.mw-header-container');
|
||||
header = document.getElementsByTagName( 'header' )[ 0 ],
|
||||
headerContainer = document.querySelector( '.mw-header-container' );
|
||||
|
||||
if (headerContainer !== null) {
|
||||
if ( headerContainer !== null ) {
|
||||
navbarHeight = headerContainer.offsetHeight;
|
||||
}
|
||||
|
||||
window.addEventListener('scroll', function() {
|
||||
window.addEventListener( 'scroll', function () {
|
||||
didScroll = true;
|
||||
});
|
||||
} );
|
||||
|
||||
function hasScrolled() {
|
||||
var st = window.scrollY,
|
||||
|
@ -26,34 +26,34 @@
|
|||
html,
|
||||
documentHeight;
|
||||
|
||||
if (Math.abs(lastScrollTop - st) <= delta) {
|
||||
if ( Math.abs( lastScrollTop - st ) <= delta ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (st > lastScrollTop && st > navbarHeight) {
|
||||
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');
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
setInterval(function() {
|
||||
if (didScroll) {
|
||||
setInterval( function () {
|
||||
if ( didScroll ) {
|
||||
hasScrolled();
|
||||
didScroll = false;
|
||||
}
|
||||
}, 250);
|
||||
})();
|
||||
}, 250 );
|
||||
}() );
|
||||
|
|
|
@ -8,39 +8,39 @@
|
|||
var observer;
|
||||
|
||||
// Native API
|
||||
if ('loading' in HTMLImageElement.prototype) {
|
||||
document.querySelectorAll('img.lazy').forEach(function(img) {
|
||||
img.setAttribute('src', img.getAttribute('data-src'));
|
||||
if ( 'loading' in HTMLImageElement.prototype ) {
|
||||
document.querySelectorAll( 'img.lazy' ).forEach( function ( img ) {
|
||||
img.setAttribute( 'src', img.getAttribute( 'data-src' ) );
|
||||
|
||||
if (img.hasAttribute('data-srcset')) {
|
||||
img.setAttribute('srcset', img.getAttribute('data-srcset'));
|
||||
if ( img.hasAttribute( 'data-srcset' ) ) {
|
||||
img.setAttribute( 'srcset', img.getAttribute( 'data-srcset' ) );
|
||||
}
|
||||
|
||||
img.classList.remove('lazy');
|
||||
});
|
||||
img.classList.remove( 'lazy' );
|
||||
} );
|
||||
} else {
|
||||
// IntersectionObserver API
|
||||
if (typeof IntersectionObserver !== 'undefined' && 'forEach' in NodeList.prototype) {
|
||||
observer = new IntersectionObserver(function(changes) {
|
||||
if ('connection' in navigator && navigator.connection.saveData === true) {
|
||||
if ( typeof IntersectionObserver !== 'undefined' && 'forEach' in NodeList.prototype ) {
|
||||
observer = new IntersectionObserver( function ( changes ) {
|
||||
if ( 'connection' in navigator && navigator.connection.saveData === true ) {
|
||||
return;
|
||||
}
|
||||
|
||||
changes.forEach(function(change) {
|
||||
if (change.isIntersecting) {
|
||||
change.target.setAttribute('src', change.target.getAttribute('data-src'));
|
||||
changes.forEach( function ( change ) {
|
||||
if ( change.isIntersecting ) {
|
||||
change.target.setAttribute( 'src', change.target.getAttribute( 'data-src' ) );
|
||||
|
||||
if (change.target.hasAttribute('data-srcset')) {
|
||||
change.target.setAttribute('srcset', change.target.getAttribute('data-srcset'));
|
||||
if ( change.target.hasAttribute( 'data-srcset' ) ) {
|
||||
change.target.setAttribute( 'srcset', change.target.getAttribute( 'data-srcset' ) );
|
||||
}
|
||||
|
||||
change.target.classList.remove('lazy');
|
||||
observer.unobserve(change.target);
|
||||
change.target.classList.remove( 'lazy' );
|
||||
observer.unobserve( change.target );
|
||||
}
|
||||
});
|
||||
});
|
||||
document.querySelectorAll('img.lazy').forEach(function(img) {
|
||||
observer.observe(img);
|
||||
});
|
||||
} );
|
||||
} );
|
||||
document.querySelectorAll( 'img.lazy' ).forEach( function ( img ) {
|
||||
observer.observe( img );
|
||||
} );
|
||||
}
|
||||
}
|
|
@ -7,65 +7,65 @@
|
|||
|
||||
function SmoothScroll() {
|
||||
var navLinks, eventListener, link;
|
||||
if (!("scrollBehavior" in document.documentElement.style)) {
|
||||
navLinks = document.querySelectorAll("#toc a");
|
||||
eventListener = function eventListener(e) {
|
||||
if ( !( 'scrollBehavior' in document.documentElement.style ) ) {
|
||||
navLinks = document.querySelectorAll( '#toc a' );
|
||||
eventListener = function eventListener( e ) {
|
||||
e.preventDefault();
|
||||
e.target.scrollIntoView({
|
||||
behavior: "smooth"
|
||||
});
|
||||
e.target.scrollIntoView( {
|
||||
behavior: 'smooth'
|
||||
} );
|
||||
};
|
||||
|
||||
for (link in navLinks) {
|
||||
if (Object.prototype.hasOwnProperty.call(navLinks, link)) {
|
||||
navLinks[link].addEventListener("click", eventListener);
|
||||
for ( link in navLinks ) {
|
||||
if ( Object.prototype.hasOwnProperty.call( navLinks, link ) ) {
|
||||
navLinks[ link ].addEventListener( 'click', eventListener );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function ScrollSpy() {
|
||||
var sections = document.querySelectorAll(".mw-headline");
|
||||
window.addEventListener("scroll", function() {
|
||||
var sections = document.querySelectorAll( '.mw-headline' );
|
||||
window.addEventListener( 'scroll', function () {
|
||||
var scrollPos = document.documentElement.scrollTop || document.body.scrollTop,
|
||||
section, id, node, active;
|
||||
|
||||
for (section in sections) {
|
||||
for ( section in sections ) {
|
||||
if (
|
||||
Object.prototype.hasOwnProperty.call(sections, section) &&
|
||||
sections[section].offsetTop <= scrollPos
|
||||
Object.prototype.hasOwnProperty.call( sections, section ) &&
|
||||
sections[ section ].offsetTop <= scrollPos
|
||||
) {
|
||||
id = mw.util.escapeIdForAttribute(sections[section].id);
|
||||
node = document.querySelector("a[href='#" + id + "']").parentNode;
|
||||
active = document.querySelector(".active");
|
||||
if (active !== null) {
|
||||
active.classList.remove("active");
|
||||
id = mw.util.escapeIdForAttribute( sections[ section ].id );
|
||||
node = document.querySelector( "a[href='#" + id + "']" ).parentNode;
|
||||
active = document.querySelector( '.active' );
|
||||
if ( active !== null ) {
|
||||
active.classList.remove( 'active' );
|
||||
}
|
||||
if (node !== null) {
|
||||
node.classList.add("active");
|
||||
if ( node !== null ) {
|
||||
node.classList.add( 'active' );
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
} );
|
||||
}
|
||||
|
||||
function CheckToC() {
|
||||
if (document.getElementById("toc")) {
|
||||
if ( document.getElementById( 'toc' ) ) {
|
||||
SmoothScroll();
|
||||
ScrollSpy();
|
||||
}
|
||||
}
|
||||
|
||||
if (document.readyState !== "loading") {
|
||||
if ( document.readyState !== 'loading' ) {
|
||||
CheckToC();
|
||||
} else if (document.addEventListener) {
|
||||
} else if ( document.addEventListener ) {
|
||||
// All modern browsers to register DOMContentLoaded
|
||||
document.addEventListener("DOMContentLoaded", CheckToC);
|
||||
document.addEventListener( 'DOMContentLoaded', CheckToC );
|
||||
} else {
|
||||
// Old IE browsers
|
||||
document.attachEvent("onreadystatechange", function() {
|
||||
if (document.readyState === "complete") {
|
||||
document.attachEvent( 'onreadystatechange', function () {
|
||||
if ( document.readyState === 'complete' ) {
|
||||
CheckToC();
|
||||
}
|
||||
});
|
||||
} );
|
||||
}
|
Loading…
Reference in a new issue