// const sidebar = document.querySelector('#sidebar') // const sidebar = document.querySelector('#sidebar') // window.onscroll = function () { // let navbar = document.querySelector("#navbar"); // let secondNav = document.querySelector("nav#second-nav"); // if (window.scrollY > 300) { // if (navbar) navbar.classList.add("second-nav-active"); // navbar.classList.add("nav-resp"); // } else { // if (navbar) navbar.classList.remove("second-nav-active"); // navbar.classList.remove("nav-resp"); // } // }; // scroll responsive window.onscroll = function () { let navbar = document.querySelector("#navbar"); if (window.scrollY > 300) { if (navbar) navbar.classList.add("scroll"); } else { if (navbar) navbar.classList.remove("scroll"); } }; // show mega menu in upper nav const menuItem = document.querySelectorAll("#navbar .menu > .menu-item"); // const allMenuBtn = document.querySelectorAll(".menu-btn"); const allMenuContent = document.querySelectorAll(".sub-menu"); if (menuItem) { menuItem.forEach((item) => { const menuBtn = item.querySelector("a"); const menuContent = item.querySelector(".sub-menu"); menuBtn.addEventListener("click", () => { if (menuContent) { menuContent.classList.toggle("show-mega-menu"); item.classList.toggle("active"); } menuItem.forEach((singleItem) => { if (singleItem !== item) { singleItem.classList.remove("active"); } }); allMenuContent.forEach((content) => { if (menuContent !== content) { content.classList.remove("show-mega-menu"); // item.classList.remove('active') } }); }); }); } // toggle responsive menu // global menu const toggleBtnGlobal = document.getElementById("menu-bars"); const menuContainerGlobal = document.querySelector("#uiu-global-nav .menu"); if (toggleBtnGlobal && menuContainerGlobal) { toggleBtnGlobal.addEventListener("click", () => { menuContainerGlobal.classList.toggle("show"); }); } // department menu const toggleBtnDepartment = document.getElementById("responsive-btn"); const menuContainerDepartment = document.querySelector("#uiu-departmental-nav"); if (toggleBtnDepartment && menuContainerDepartment) { toggleBtnDepartment.addEventListener("click", () => { menuContainerDepartment.classList.toggle("show"); }); } // fetch submenu extra item data const addMenuFeature = (url, parentClass) => { const fetchMenudata = async () => { try { const res = await fetch(url, { method: "GET" }); const data = await res.json(); return data; } catch (error) { console.log(`Error: ${error}`); } }; fetchMenudata().then((data) => { // adding menu data into html addDataToMenu(data); }); function addDataToMenu(data) { if (data) { const menuItem = document.querySelectorAll(`.${parentClass} .menu-item`); menuItem.forEach((item) => { const targetData = data.find((data) => item.innerHTML .toLowerCase() .includes(data.parent_navigation_label.toLowerCase()) ); const menuTitle = item.querySelector(".menu_title"); const menuDesc = item.querySelector(".menu_description"); const menuFeatureImage = item.querySelector(".menu_feature_image"); if (targetData && menuFeatureImage) { menuFeatureImage.src = targetData.menu_feature_image; } if (targetData && menuTitle) { menuTitle.innerHTML = targetData.menu_title; } if (targetData && menuDesc) { menuDesc.innerHTML = targetData.menu_description; } }); } } }; // add content in global menu addMenuFeature( "https://cse.uiu.local/wp-json/options/menu/global-header", "uiu-global-header-menu" ); // add content in departmentalmenu menu addMenuFeature( "https://cse.uiu.local/wp-json/options/menu/departmental-header", "uiu-departmental-header-menu" ); // fetch submenu extra item data end // accordion const accordionAll = document.querySelectorAll("#accordion"); const accordionBodyAll = document.querySelectorAll(".accordion-body"); if (accordionAll) { accordionAll.forEach((accordion) => { const accordionBtn = accordion.querySelector(".accordion-btn"); const accordionBody = accordion.querySelector(".accordion-body"); accordionBtn.addEventListener("click", () => { accordionBody.classList.toggle("show"); accordionBodyAll.forEach((accordion) => { if (accordionBody !== accordion) { accordion.classList.remove("show"); } }); }); }); } // const buttons = document.querySelectorAll("[data-carousel-button]") document.querySelectorAll("[data-banner-slider-button]").forEach((button) => { button.addEventListener("click", () => { const offset = button.dataset.carouselButton === "next" ? 1 : -1; const slides = button .closest("[data-banner-slider]") .querySelector("[data-slides]"); const activeSlide = slides.querySelector("[data-active]"); let newIndex = [...slides.children].indexOf(activeSlide) + offset; if (newIndex < 0) newIndex = slides.children.length - 1; if (newIndex >= slides.children.length) newIndex = 0; slides.children[newIndex].dataset.active = true; delete activeSlide.dataset.active; }); }); setInterval(function () { if (document.querySelector(".carousel-button.next")) document.querySelector(".carousel-button.next").click(); }, 5000); function openSearch() { document.getElementById("search-modal").style.height = "100%"; console.log("search opened"); } /* Close when someone clicks on the "x" symbol inside the overlay */ function closeSearch() { document.getElementById("search-modal").style.height = "0%"; } let totalDivs = document.querySelectorAll( "#faculty-carousel > .profile-carousel > .car-item" ).length; let screenWidth = Math.max( document.documentElement.clientWidth || 0, window.innerWidth || 0 ); let totalWidth = totalDivs * 340; let extraWidth = screenWidth - totalWidth; let scrolled = 0; function scrollToNext() { scrolled -= 345; let moveX = ""; if (scrolled <= extraWidth - 400) { scrolled = 0; } moveX = scrolled.toString() + "px"; //console.log(moveX, (-1*extraWidth), screenWidth, totalWidth, totalDivs) document.querySelectorAll( "#faculty-carousel > .profile-carousel" )[0].style.left = moveX; } function scrollToPrev() { scrolled = scrolled + 345; let moveX = ""; if (scrolled > 340) { scrolled = extraWidth - 50; } moveX = scrolled.toString() + "px"; //console.log(scrolled, moveX, (extraWidth), screenWidth, totalWidth, totalDivs) document.querySelectorAll( "#faculty-carousel > .profile-carousel" )[0].style.left = moveX; } let totalDivsAl = document.querySelectorAll( "#alumni-carousel > .profile-carousel > .car-item" ).length; let screenWidthAl = Math.max( document.documentElement.clientWidth || 0, window.innerWidth || 0 ); let totalWidthAl = totalDivsAl * 340; let extraWidthAl = screenWidthAl - totalWidthAl; let scrolledAl = 0; function scrollToNextAl() { scrolledAl -= 340; let moveXAl = ""; if (scrolledAl <= extraWidthAl - 400) { scrolledAl = 0; } moveXAl = scrolledAl.toString() + "px"; document.querySelectorAll( "#alumni-carousel > .profile-carousel" )[0].style.left = moveXAl; } function scrollToPrevAl() { scrolledAl = scrolledAl + 340; let moveXAl = ""; if (scrolledAl > 340) { scrolledAl = extraWidthAl - 50; } moveXAl = scrolledAl.toString() + "px"; document.querySelectorAll( "#alumni-carousel > .profile-carousel" )[0].style.left = moveXAl; } //for NAV function openNav() { document.getElementById("myNav").style.height = "100%"; } /* Close when someone clicks on the "x" symbol inside the overlay */ function closeNav() { document.getElementById("myNav").style.height = "0%"; } //profile const facultyProfile = document.querySelector("body.single-faculty"); if (facultyProfile) { window.addEventListener("resize", showSidebarOptions); const biosTitle = document.querySelectorAll("h2.m-text"); const list = document.querySelector("ul.profile-choices"); const bios = document.querySelectorAll(".desc-block"); if (window.innerWidth < 600) { bios.forEach((el) => el.classList.remove(".desc-block-hidden")); } else { biosTitle.forEach((el, index) => { console.log(el.textContent); let text = '