-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
42 lines (36 loc) · 1.24 KB
/
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
32
33
34
35
36
37
38
39
40
41
42
const sharePanel = document.querySelector('.share__panel');
const shareButton = document.querySelector('#share-btn');
const internShareButton = document.querySelector('.share__panel .share__btn');
const openSharePanel = () => {
sharePanel.classList.remove('d--none');
sharePanel.classList.remove('close');
sharePanel.classList.add('open');
};
const closeSharePanel = () => {
sharePanel.classList.remove('open');
sharePanel.classList.add('close');
};
const hideSharePanel = () => {
if (sharePanel.classList.contains('close')) {
sharePanel.classList.add('d--none');
}
};
const updateButtonStates = (attribute, value) => {
shareButton.setAttribute(attribute, value);
internShareButton.setAttribute(attribute, value);
};
const toggleSharePanel = (event) => {
const btn = event.target;
const attribute = 'aria-expanded';
const ariaExpanded = btn.getAttribute(attribute) === 'true';
const newAriaExpanded = !ariaExpanded;
if (newAriaExpanded) {
openSharePanel();
} else {
closeSharePanel();
}
updateButtonStates(attribute, newAriaExpanded);
};
sharePanel.addEventListener('animationend', hideSharePanel);
shareButton.addEventListener('click', toggleSharePanel);
internShareButton.addEventListener('click', toggleSharePanel);