62 lines
1.9 KiB
JavaScript
62 lines
1.9 KiB
JavaScript
(function () {
|
|
function initTerminosAccordion() {
|
|
var accordions = document.querySelectorAll(".terminos-accordion");
|
|
|
|
if (!accordions.length) return;
|
|
|
|
function closeAllAccordions(exceptIndex = -1) {
|
|
accordions.forEach(function (accordion, index) {
|
|
if (
|
|
index !== exceptIndex &&
|
|
accordion.classList.contains("active")
|
|
) {
|
|
accordion.classList.remove("active");
|
|
}
|
|
});
|
|
}
|
|
|
|
accordions.forEach(function (accordion, index) {
|
|
var title = accordion.querySelector(".terminos-accordion-title");
|
|
|
|
if (title) {
|
|
title.addEventListener("click", function (e) {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
|
|
var isActive = accordion.classList.contains("active");
|
|
|
|
if (!isActive) {
|
|
closeAllAccordions(index);
|
|
accordion.classList.add("active");
|
|
} else {
|
|
accordion.classList.remove("active");
|
|
}
|
|
});
|
|
}
|
|
|
|
var observer = new IntersectionObserver(
|
|
function (entries) {
|
|
entries.forEach(function (entry) {
|
|
if (entry.isIntersecting) {
|
|
entry.target.classList.add("revealed");
|
|
observer.unobserve(entry.target);
|
|
}
|
|
});
|
|
},
|
|
{
|
|
threshold: 0.1,
|
|
rootMargin: "50px",
|
|
},
|
|
);
|
|
|
|
observer.observe(accordion);
|
|
});
|
|
}
|
|
|
|
if (document.readyState === "loading") {
|
|
document.addEventListener("DOMContentLoaded", initTerminosAccordion);
|
|
} else {
|
|
initTerminosAccordion();
|
|
}
|
|
})();
|