71 lines
2.2 KiB
JavaScript
71 lines
2.2 KiB
JavaScript
(function () {
|
|
var root = document.documentElement;
|
|
var stored = localStorage.getItem('theme');
|
|
var isLight = stored ? stored === 'light' : false;
|
|
root.classList.toggle('lm', isLight);
|
|
|
|
function syncThemeIcons() {
|
|
document.querySelectorAll('[data-theme-icon="sun"]').forEach(function (el) {
|
|
el.style.display = isLight ? 'inline' : 'none';
|
|
});
|
|
document.querySelectorAll('[data-theme-icon="moon"]').forEach(function (el) {
|
|
el.style.display = isLight ? 'none' : 'inline';
|
|
});
|
|
}
|
|
|
|
function toggleTheme() {
|
|
isLight = !isLight;
|
|
root.classList.toggle('lm', isLight);
|
|
localStorage.setItem('theme', isLight ? 'light' : 'dark');
|
|
syncThemeIcons();
|
|
}
|
|
|
|
document.querySelectorAll('[data-theme-toggle]').forEach(function (btn) {
|
|
btn.addEventListener('click', toggleTheme);
|
|
});
|
|
syncThemeIcons();
|
|
|
|
var nav = document.getElementById('site-nav');
|
|
if (nav) {
|
|
var onScroll = function () {
|
|
nav.classList.toggle('scrolled', window.scrollY > 40);
|
|
};
|
|
window.addEventListener('scroll', onScroll);
|
|
onScroll();
|
|
}
|
|
|
|
var mobileMenu = document.getElementById('mobile-menu');
|
|
var mobileToggle = document.getElementById('mobile-menu-toggle');
|
|
if (mobileMenu && mobileToggle) {
|
|
var open = false;
|
|
var setOpen = function (next) {
|
|
open = next;
|
|
mobileMenu.classList.toggle('open', open);
|
|
var barIcon = mobileToggle.querySelector('[data-icon="bars"]');
|
|
var xIcon = mobileToggle.querySelector('[data-icon="xmark"]');
|
|
if (barIcon) barIcon.style.display = open ? 'none' : 'inline';
|
|
if (xIcon) xIcon.style.display = open ? 'inline' : 'none';
|
|
};
|
|
mobileToggle.addEventListener('click', function () {
|
|
setOpen(!open);
|
|
});
|
|
mobileMenu.querySelectorAll('a').forEach(function (link) {
|
|
link.addEventListener('click', function () {
|
|
setOpen(false);
|
|
});
|
|
});
|
|
}
|
|
|
|
var revealObserver = new IntersectionObserver(
|
|
function (entries) {
|
|
entries.forEach(function (entry) {
|
|
if (entry.isIntersecting) entry.target.classList.add('is-in');
|
|
});
|
|
},
|
|
{ threshold: 0.1, rootMargin: '0px 0px -40px 0px' }
|
|
);
|
|
document.querySelectorAll('.reveal').forEach(function (el) {
|
|
revealObserver.observe(el);
|
|
});
|
|
})();
|