mirror of
https://github.com/StarCitizenTools/mediawiki-skins-Citizen.git
synced 2024-11-24 14:34:09 +00:00
JS check for browser support
This commit is contained in:
parent
bb78f97785
commit
9a58200117
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* Scroll up Header
|
||||
* Modified from https://codepen.io/sajjad/pen/vgEZNy
|
||||
* TODO: Convert to Vanilla JS
|
||||
*/
|
||||
|
||||
// Hide header on scroll down
|
||||
|
|
|
@ -6,37 +6,58 @@
|
|||
*/
|
||||
|
||||
const SmoothScroll = () => {
|
||||
const navLinks = document.querySelectorAll('#toc a');
|
||||
if (!'scrollBehavior' in document.documentElement.style) {
|
||||
const navLinks = document.querySelectorAll('#toc a');
|
||||
|
||||
for (let n in navLinks) {
|
||||
if (navLinks.hasOwnProperty(n)) {
|
||||
navLinks[n].addEventListener('click', e => {
|
||||
e.preventDefault();
|
||||
document.querySelector(navLinks[n].hash)
|
||||
.scrollIntoView({
|
||||
behavior: "smooth"
|
||||
});
|
||||
});
|
||||
for (let n in navLinks) {
|
||||
if (navLinks.hasOwnProperty(n)) {
|
||||
navLinks[n].addEventListener('click', e => {
|
||||
e.preventDefault();
|
||||
document.querySelector(navLinks[n].hash)
|
||||
.scrollIntoView({
|
||||
behavior: "smooth"
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const ScrollSpy = () => {
|
||||
const sections = document.querySelectorAll('.mw-headline');
|
||||
const sections = document.querySelectorAll('.mw-headline');
|
||||
|
||||
window.onscroll = () => {
|
||||
const scrollPos = document.documentElement.scrollTop || document.body.scrollTop;
|
||||
window.onscroll = () => {
|
||||
const scrollPos = document.documentElement.scrollTop || document.body.scrollTop;
|
||||
|
||||
for (let s in sections)
|
||||
if (sections.hasOwnProperty(s) && sections[s].offsetTop <= scrollPos) {
|
||||
const id = mw.util.escapeIdForAttribute(sections[s].id);
|
||||
document.querySelector('.active').classList.remove('active');
|
||||
document.querySelector(`a[href*="${ id }"]`).parentNode.classList.add('active');
|
||||
}
|
||||
}
|
||||
for (let s in sections)
|
||||
if (sections.hasOwnProperty(s) && sections[s].offsetTop <= scrollPos) {
|
||||
const id = mw.util.escapeIdForAttribute(sections[s].id);
|
||||
document.querySelector('.active').classList.remove('active');
|
||||
document.querySelector(`a[href*="${ id }"]`).parentNode.classList.add('active');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
SmoothScroll();
|
||||
ScrollSpy();
|
||||
});
|
||||
const CheckToC = () => {
|
||||
var ToC = document.getElementById("toc");
|
||||
if (toc) {
|
||||
SmoothScroll();
|
||||
ScrollSpy();
|
||||
}
|
||||
}
|
||||
|
||||
function ready(callbackFunc) {
|
||||
if (document.readyState !== 'loading') {
|
||||
CheckToC();
|
||||
} else if (document.addEventListener) {
|
||||
// All modern browsers to register DOMContentLoaded
|
||||
document.addEventListener('DOMContentLoaded', callbackFunc);
|
||||
} else {
|
||||
// Old IE browsers
|
||||
document.attachEvent('onreadystatechange', function() {
|
||||
if (document.readyState === 'complete') {
|
||||
CheckToC();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue