-
Notifications
You must be signed in to change notification settings - Fork 101
/
main.js
53 lines (44 loc) · 1.36 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
43
44
45
46
47
48
49
50
51
52
53
var sidebar = document.getElementById('sidebar');
function sidebarToggle() {
if (sidebar.style.display === "none") {
sidebar.style.display = "block";
} else {
sidebar.style.display = "none";
}
}
var profileDropdown = document.getElementById('ProfileDropDown');
function profileToggle() {
if (profileDropdown.style.display === "none") {
profileDropdown.style.display = "block";
} else {
profileDropdown.style.display = "none";
}
}
/**
* ### Modals ###
*/
function toggleModal(action, elem_trigger)
{
elem_trigger.addEventListener('click', function () {
if (action == 'add') {
let modal_id = this.dataset.modal;
document.getElementById(`${modal_id}`).classList.add('modal-is-open');
} else {
// Automaticlly get the opned modal ID
let modal_id = elem_trigger.closest('.modal-wrapper').getAttribute('id');
document.getElementById(`${modal_id}`).classList.remove('modal-is-open');
}
});
}
// Check if there is modals on the page
if (document.querySelector('.modal-wrapper'))
{
// Open the modal
document.querySelectorAll('.modal-trigger').forEach(btn => {
toggleModal('add', btn);
});
// close the modal
document.querySelectorAll('.close-modal').forEach(btn => {
toggleModal('remove', btn);
});
}