-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
88 lines (75 loc) · 2.76 KB
/
Copy pathapp.js
File metadata and controls
88 lines (75 loc) · 2.76 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
(() => {
'use strict';
const root = document.documentElement;
const toggle = document.querySelector('[data-menu-toggle]');
const nav = document.querySelector('[data-nav]');
const closeMenu = () => {
if (!toggle || !nav) return;
toggle.setAttribute('aria-expanded', 'false');
nav.classList.remove('is-open');
document.body.classList.remove('menu-is-open');
};
const openMenu = () => {
if (!toggle || !nav) return;
toggle.setAttribute('aria-expanded', 'true');
nav.classList.add('is-open');
document.body.classList.add('menu-is-open');
nav.querySelector('a')?.focus();
};
if (toggle && nav) {
toggle.addEventListener('click', () => {
const isOpen = toggle.getAttribute('aria-expanded') === 'true';
if (isOpen) closeMenu();
else openMenu();
});
nav.querySelectorAll('a').forEach((link) => link.addEventListener('click', closeMenu));
document.addEventListener('keydown', (event) => {
const isOpen = toggle.getAttribute('aria-expanded') === 'true';
if (!isOpen) return;
if (event.key === 'Escape') {
closeMenu();
toggle.focus();
return;
}
if (event.key !== 'Tab') return;
const focusable = [toggle, ...nav.querySelectorAll('a[href]')];
const first = focusable[0];
const last = focusable[focusable.length - 1];
if (event.shiftKey && document.activeElement === first) {
event.preventDefault();
last.focus();
} else if (!event.shiftKey && document.activeElement === last) {
event.preventDefault();
first.focus();
}
});
}
const yearNode = document.querySelector('[data-year]');
if (yearNode) yearNode.textContent = new Date().getFullYear();
const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)');
const revealItems = document.querySelectorAll('.reveal');
root.classList.add('js');
document.body.classList.add('page-ready');
if (reduceMotion.matches || !('IntersectionObserver' in window)) {
revealItems.forEach((item) => item.classList.add('is-visible'));
} else {
const observer = new IntersectionObserver(
(entries, currentObserver) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add('is-visible');
currentObserver.unobserve(entry.target);
}
});
},
{ threshold: 0.12 }
);
revealItems.forEach((item) => observer.observe(item));
}
if (!reduceMotion.matches && window.matchMedia('(pointer: fine)').matches) {
window.addEventListener('pointermove', (event) => {
root.style.setProperty('--cursor-x', `${event.clientX}px`);
root.style.setProperty('--cursor-y', `${event.clientY}px`);
}, { passive: true });
}
})();