-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
63 lines (55 loc) · 1.69 KB
/
main.js
File metadata and controls
63 lines (55 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
function showPage(pageId) {
page = document.getElementById(pageId)
// hide all pages
document.querySelectorAll('.page').forEach(function (p) {
p.classList.remove('active');
});
// show the clicked page
page.classList.add('active');
}
function showContentFromHash() {
var pageId = window.location.hash.substring(1);
if (!pageId) {
showPage('home');
return
}
var page = document.getElementById(pageId);
if (!page) {
showPage('404');
return
}
showPage(pageId);
}
function showMobileModal() {
// activate modal
document.querySelectorAll('.mobile-nav').forEach((e) => {
e.classList.add('mobile-nav-active');
});
// disable scrolling
document.querySelector('body').classList.add('no-scroll');
document.querySelector('html').classList.add('no-scroll');
}
function closeMobileModal() {
// close modal
document.querySelectorAll('.mobile-nav').forEach((e) => {
e.classList.add('mobile-nav-closing');
// wait for 'close' animation to finish before removing active class
e.addEventListener('animationend', () => {
e.classList.remove('mobile-nav-active', 'mobile-nav-closing');
}, {
once: true,
});
});
// re-enable scrolling
document.querySelectorAll('.no-scroll').forEach((e) => {
e.classList.remove('no-scroll')
})
}
function mobileNav(link) {
closeMobileModal();
window.URL = link;
}
// Call the function on page load to display page content based on URL
window.onload = showContentFromHash;
// Call the function on hash change (for back/forward navigation)
window.onhashchange = showContentFromHash;