-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
31 lines (26 loc) · 963 Bytes
/
main.js
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
import { toggleMenu, setCurrentPageLink } from './menu.js';
import { setCurrentPageLinkOnReload } from './helpers.js';
import { hamburger, anchorsContainer, inputs } from './elements.js';
window.addEventListener('keydown', e => e.key === " " && e.preventDefault());
if (history.scrollRestoration && location.hash) {
history.scrollRestoration = 'manual';
}
hamburger.addEventListener('click', toggleMenu);
anchorsContainer.addEventListener('click', setCurrentPageLink);
anchorsContainer.addEventListener('keyup', (e) => {
e.preventDefault();
if (e.which === 13 || e.which === 32) {
setCurrentPageLink(e);
}
});
inputs.forEach(
input => input.addEventListener('blur', ({ currentTarget }) => {
const { labels: [ label ] } = currentTarget;
if (currentTarget.value) {
label.classList.add('form__label--input-focused');
} else {
label.classList.remove('form__label--input-focused');
}
})
)
setCurrentPageLinkOnReload();