58 lines
1.4 KiB
JavaScript
58 lines
1.4 KiB
JavaScript
// addEventListener Helper
|
|
//
|
|
const listen = (ele, e, callback) => {
|
|
if (document.querySelector(ele) !== null) {
|
|
document.querySelector(ele).addEventListener(e, callback);
|
|
}
|
|
}
|
|
|
|
let header = document.getElementById('site-header');
|
|
|
|
// Mobile Menu Toggle
|
|
//
|
|
let mobileMenuVisible = false;
|
|
|
|
const toggleMobileMenu = () => {
|
|
let mobileMenu = document.getElementById('mobile-menu');
|
|
if (mobileMenuVisible == false) {
|
|
mobileMenu.style.animationName = 'bounceInRight';
|
|
mobileMenu.style.webkitAnimationName = 'bounceInRight';
|
|
mobileMenu.style.display = 'block';
|
|
mobileMenuVisible = true;
|
|
} else {
|
|
mobileMenu.style.animationName = 'bounceOutRight';
|
|
mobileMenu.style.webkitAnimationName = 'bounceOutRight'
|
|
mobileMenuVisible = false;
|
|
}
|
|
}
|
|
|
|
// Featured Image Toggle
|
|
//
|
|
const showImg = () => {
|
|
document.querySelector('.bg-img').classList.add('show-bg-img');
|
|
}
|
|
|
|
const hideImg = () => {
|
|
document.querySelector('.bg-img').classList.remove('show-bg-img');
|
|
}
|
|
|
|
// ToC Toggle
|
|
//
|
|
const toggleToc = () => {
|
|
document.getElementById('toc').classList.toggle('show-toc');
|
|
}
|
|
|
|
|
|
if (header !== null) {
|
|
listen('#menu-btn', "click", toggleMobileMenu);
|
|
listen('#toc-btn', "click", toggleToc);
|
|
listen('#img-btn', "click", showImg);
|
|
listen('.bg-img', "click", hideImg);
|
|
|
|
document.querySelectorAll('.post-year').forEach((ele)=> {
|
|
ele.addEventListener('click', () => {
|
|
window.location.hash = '#' + ele.id;
|
|
});
|
|
});
|
|
}
|