-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
77 lines (72 loc) · 2.94 KB
/
script.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
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
/* eslint-disable no-console */
const closeDropdown = (menuItem, menuItemArr, openDownBtn, dropdownMenu) => {
dropdownMenu.classList.remove('show');
menuItem.classList.remove('d-menu-item');
menuItemArr[0].classList.remove('dropdown-heading');
openDownBtn.style.transform = 'initial';
menuItem.style.backgroundColor = 'inherit';
};
const openDropdown = (menuItem, menuItemArr, openDownBtn, dropdownMenu) => {
dropdownMenu.classList.add('show');
menuItem.classList.add('d-menu-item');
menuItemArr[0].classList.add('dropdown-heading');
openDownBtn.style.transform = 'rotate(0.5turn)';
menuItem.style.backgroundColor = '#371B9D';
};
const closeAllDropdowns = (dropdowns) => {
dropdowns.forEach((menuItem) => {
const menuItemArr = menuItem.children;
const openDownBtn = menuItemArr[0].lastElementChild;
const dropdownMenu = menuItemArr[1];
try {
closeDropdown(menuItem, menuItemArr, openDownBtn, dropdownMenu);
} catch (error) {
// console.log('no dropdowns to close');
}
});
};
const loadFunc = () => {
const toggleBtn = document.querySelector('.fa-bars');
const crossBtn = document.querySelector('.fa-times');
const menu = document.querySelector('.menu');
const copyTxtBtns = document.querySelectorAll('.fa-copy');
const deleteTxtBtns = document.querySelectorAll('.fa-trash');
const dropdowns = document.querySelectorAll('.menu-item');
toggleBtn.addEventListener('click', () => {
menu.style.display = 'block';
toggleBtn.style.display = 'none';
crossBtn.style.display = 'flex';
});
crossBtn.addEventListener('click', () => {
menu.style.display = 'none';
toggleBtn.style.display = 'flex';
crossBtn.style.display = 'none';
});
copyTxtBtns.forEach((copyTxt) => {
copyTxt.addEventListener('click', () => {
const copiedData = copyTxt.parentNode.parentNode.nextSibling.nextSibling;
copiedData.select();
document.execCommand('copy');
});
});
deleteTxtBtns.forEach((deleteTxt) => {
deleteTxt.addEventListener('click', () => {
deleteTxt.parentNode.parentNode.nextSibling.nextSibling.value = '';
});
});
dropdowns.forEach((menuItem) => {
menuItem.addEventListener('click', () => {
const menuItemArr = menuItem.children;
const openDownBtn = menuItemArr[0].lastElementChild;
const dropdownMenu = menuItemArr[1];
const currentDisplay = window.getComputedStyle(dropdownMenu).getPropertyValue('display');
if (currentDisplay === 'none') {
closeAllDropdowns(dropdowns);
openDropdown(menuItem, menuItemArr, openDownBtn, dropdownMenu);
} else {
closeDropdown(menuItem, menuItemArr, openDownBtn, dropdownMenu);
}
});
});
};
window.addEventListener('load', loadFunc);