-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdragonfly-error-script.js
More file actions
125 lines (106 loc) · 3.66 KB
/
dragonfly-error-script.js
File metadata and controls
125 lines (106 loc) · 3.66 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*---------------*/
/*== SELECTORS ==*/
/*---------------*/
/* #region selectors */
const nav = document.querySelector('.nav');
const ham = document.querySelector('.ham-wrapper');
const socials = document.querySelector('.socials');
const accordionList = document.querySelectorAll('.accordion-item-header');
const width = window.innerWidth;
/* #region main-statements */
nav.classList.remove('nav-active');
ham.classList.remove('ham-active');
// Hamburger Menu
ham.addEventListener('click', toggleNav);
/* #endregion */
/*---------------*/
/*== FUNCTIONS ==*/
/*---------------*/
/* #region functions */
// Open / Close the nav menu
function toggleNav() {
nav.classList.toggle('nav-active');
ham.classList.toggle('ham-active');
socials.classList.toggle('socials-active');
}
// Close the nav menu
function closeMenu(e) {
nav.classList.remove('nav-active');
ham.classList.remove('ham-active');
}
// FAQ Accordion
accordionList.forEach((accordionHeader) => {
accordionHeader.addEventListener('click', (event) => {
toggleAccordion(accordionHeader);
});
});
function toggleAccordion(element) {
element.classList.toggle('accordion-active');
const accordionItemBody = element.nextElementSibling.nextElementSibling;
if (element.classList.contains('accordion-active')) {
accordionList.forEach((otherAccordion) => {
if (otherAccordion !== element) {
otherAccordion.classList.remove('accordion-active')
otherAccordion.nextElementSibling.nextElementSibling.style.maxHeight = 0;
}
})
accordionItemBody.style.maxHeight = accordionItemBody.scrollHeight + 'px';
} else {
accordionItemBody.style.maxHeight = '0';
}
}
// Change direction of logo anchor by scroll position
window.addEventListener("scroll", function () {
const logoImg = document.querySelector("#logo a")
if (document.documentElement.scrollTop > 0) {
logoImg.removeAttribute("href")
logoImg.setAttribute("onclick", "scrollToTop()")
} else {
logoImg.setAttribute("href", "https://inceptioncloud.net/dragonfly")
}
})
// /*window.addEventListener("load", () => {
// setTimeout(function () {
// document.getElementsByTagName("html")[0].style.scrollBehavior = "auto"
// }, 600)
// })*/
// auto-scroll
let targetElement
let highlighted = false
window.onload = function () {
let url = window.location.href
let code = url.substr(url.length - 3)
targetElement = document.getElementById(code)
if (code != null && targetElement != null) {
const posY = targetElement.getBoundingClientRect().top - document.getElementById("navbar").clientHeight - 20
window.scrollBy(0, posY)
checkHighlightElement()
} else if (targetElement == null) {
document.getElementsByTagName("html")[0].style.scrollBehavior = "auto"
}
}
function scrollToTop() {
$("html, body").animate({
scrollTop: 0
}, 400)
closeMenu()
}
window.addEventListener('scroll', function () {
checkHighlightElement()
});
function checkHighlightElement() {
if (highlighted || targetElement == null)
return
const position = targetElement.getBoundingClientRect();
// checking whether fully visible
if (position.top >= 0 && position.bottom <= window.innerHeight && !targetElement.parentElement.classList.contains("highlight")) {
highlighted = true
setTimeout(() => {
toggleAccordion(targetElement)
}, 300)
setTimeout(() => {
targetElement.parentElement.classList.add("highlight")
document.getElementsByTagName("html")[0].style.scrollBehavior = "auto"
}, 600)
}
}