-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathluna-framework.js
79 lines (66 loc) · 2.59 KB
/
luna-framework.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
78
79
// main.js
const navbarToggler = document.getElementById("navbar-toggler");
const dashboardModal = document.getElementById("dashboard-modal");
const profileDropdownObj = document.getElementById("profile-dropdown");
const dropdowns = document.getElementsByClassName("dropdown-toggle");
for (var i = 0; i < dropdowns.length; i++) {
dropdowns[i].addEventListener("click", (e) => {
const linkedDropdown = document.getElementById(e.target.getAttribute("nav-target"));
if (linkedDropdown.classList.contains("show")) {
linkedDropdown.classList.remove("show");
} else {
linkedDropdown.classList.add("show")
}
})
}
// When the navbarToggler is clicked, show and hide the navbar content.
navbarToggler.addEventListener("click", function () {
//
const content = this.nextElementSibling.children[1];
const dropdownMenus = document.getElementsByClassName("dropdown-menu")
// If the collapsable div doesnt have inline maxHeight styling, show it. If it does, hide it.
if (content.classList.contains("expanded")) {
content.classList.remove("expanded");
// Hide any dropdowns
for (var i = 0; i < dropdownMenus.length; i++) {
dropdownMenus[i].style.opacity = 0;
}
} else {
content.classList.add("expanded");
// Show any dropdowns
for (var i = 0; i < dropdownMenus.length; i++) {
dropdownMenus[i].style.opacity = 1;
}
}
});
// When the dashboard modal is clicked outside of the dashboard box, hide it.
dashboardModal.addEventListener("click", function (e) {
if (dashboardModal.style.display == "flex" && e.target == dashboardModal) {
toggleModal();
}
});
// Show or hide the main modal when clicked.
function toggleModal() {
if (dashboardModal.style.display == "flex") {
dashboardModal.style.display = "none";
} else {
dashboardModal.style.display = "flex";
}
}
// Add event listeners for the profile dropdown object when the mouse hovers out of it.
profileDropdownObj.addEventListener("mouseleave", function () {
profileDropdown();
});
function profileDropdown() {
if (profileDropdownObj.style.opacity == 1) {
profileDropdownObj.style.opacity = 0;
profileDropdownObj.style.pointerEvents = "none";
} else {
profileDropdownObj.style.opacity = 1;
profileDropdownObj.style.pointerEvents = "all";
}
}
// Check the no. of characters in a textarea.
function checkCharacters(textArea) {
document.getElementById("character-count").innerHTML = (200 - textArea.value.length).toString();
}