Sindbad~EG File Manager
window.addEventListener("load", () => {
console.log("Hello");
const scrollUpBtn = document.querySelector(".scroll-up");
scrollUpBtn.addEventListener("click", () => {
window.scrollTo({
top: 0,
behavior: "smooth",
});
});
const tocButton = document.querySelector(".single-article__toc-button");
const tocContent = document.querySelector(".single-article__toc-content");
const tocArrow = document.querySelector(".single-article__toc-arrow");
tocButton.addEventListener("click", () => {
// PLay with max height
tocContent.style.maxHeight =
tocContent.style.maxHeight !== "0px"
? "0px"
: `${tocContent.scrollHeight}px`;
// Rotate arrow
tocArrow.style.transform = tocArrow.style.transform
? null
: "rotate(180deg)";
});
const wysiwygH2 = document.querySelectorAll(".single-article__wysiwyg h2");
const toc = document.querySelector(".single-article__toc-content ul");
wysiwygH2.forEach((h2, index) => {
// Add id to h2
h2.id = `section-${index + 1}`;
// Create li element
const li = document.createElement("li");
li.innerHTML = `<a class="body-2 text-purple800" href="#section-${
index + 1
}">${h2.textContent}</a>`;
toc.appendChild(li);
});
const wysiwygParagraphs = document.querySelectorAll(
".single-article__wysiwyg p"
);
const newsLetterBlock = document.querySelector(
".single-article__newsletter-container"
);
// I want to map all the paragraphs and append the newsletter block in the middle of the paragraphs (if there is 4 paragraphs, we want to append the newsletter block after the second paragraph)
const paragraphsLength = wysiwygParagraphs.length;
if (paragraphsLength > 0) {
const middleIndex = Math.floor(paragraphsLength / 2);
wysiwygParagraphs[middleIndex].after(newsLetterBlock);
}
});
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists