theme-script.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. //************************** Site Header Menu - Global ***************************************/
  2. // show mega menu in upper nav
  3. const menuItem = document.querySelectorAll("#navbar .menu > .menu-item");
  4. const allMenuContent = document.querySelectorAll(".sub-menu");
  5. if (menuItem) {
  6. menuItem.forEach((item) => {
  7. const menuBtn = item.querySelector("a");
  8. const menuContent = item.querySelector(".sub-menu");
  9. menuBtn.addEventListener("click", () => {
  10. if (menuContent) {
  11. menuContent.classList.toggle("show-mega-menu");
  12. item.classList.toggle("active");
  13. }
  14. menuItem.forEach((singleItem) => {
  15. if (singleItem !== item) {
  16. singleItem.classList.remove("active");
  17. }
  18. });
  19. allMenuContent.forEach((content) => {
  20. if (menuContent !== content) {
  21. content.classList.remove("show-mega-menu");
  22. // item.classList.remove('active')
  23. }
  24. });
  25. });
  26. });
  27. }
  28. // global menu
  29. const toggleBtnGlobal = document.getElementById("menu-bars");
  30. const menuContainerGlobal = document.querySelector("#uiu-global-nav .menu");
  31. if (toggleBtnGlobal && menuContainerGlobal) {
  32. toggleBtnGlobal.addEventListener("click", () => {
  33. menuContainerGlobal.classList.toggle("show");
  34. });
  35. }
  36. // department menu
  37. const toggleBtnDepartment = document.getElementById("responsive-btn");
  38. const menuContainerDepartment = document.querySelector("#uiu-departmental-nav");
  39. if (toggleBtnDepartment && menuContainerDepartment) {
  40. toggleBtnDepartment.addEventListener("click", () => {
  41. menuContainerDepartment.classList.toggle("show");
  42. });
  43. }
  44. // fetch submenu extra item data
  45. const addMenuFeature = (url, parentClass) => {
  46. const fetchMenudata = async () => {
  47. try {
  48. const res = await fetch(url, { method: "GET" });
  49. const data = await res.json();
  50. return data;
  51. } catch (error) {
  52. console.log(`Error: ${error}`);
  53. }
  54. };
  55. fetchMenudata().then((data) => {
  56. // adding menu data into html
  57. addDataToMenu(data);
  58. });
  59. function addDataToMenu(data) {
  60. if (data) {
  61. const menuItem = document.querySelectorAll(`.${parentClass} .menu-item`);
  62. menuItem.forEach((item) => {
  63. const targetData = data.find((data) =>
  64. item.innerHTML
  65. .toLowerCase()
  66. .includes(data.parent_navigation_label.toLowerCase())
  67. );
  68. const menuTitle = item.querySelector(".menu_title");
  69. const menuDesc = item.querySelector(".menu_description");
  70. const menuFeatureImage = item.querySelector(".menu_feature_image");
  71. if (targetData && menuFeatureImage) {
  72. menuFeatureImage.src = targetData.menu_feature_image;
  73. }
  74. if (targetData && menuTitle) {
  75. menuTitle.innerHTML = targetData.menu_title;
  76. }
  77. if (targetData && menuDesc) {
  78. menuDesc.innerHTML = targetData.menu_description;
  79. }
  80. });
  81. }
  82. }
  83. };
  84. // add content in global menu
  85. addMenuFeature("/wp-json/options/menu/global-header", "uiu-global-header-menu");
  86. // add content in departmentalmenu menu
  87. addMenuFeature(
  88. "/wp-json/options/menu/departmental-header",
  89. "uiu-departmental-header-menu"
  90. );
  91. // fetch submenu extra item data end
  92. //******************************* Accordion **************************************/
  93. const accordionAll = document.querySelectorAll("#accordion");
  94. const accordionBodyAll = document.querySelectorAll(".accordion-body");
  95. if (accordionAll) {
  96. accordionAll.forEach((accordion) => {
  97. const accordionBtn = accordion.querySelector(".accordion-btn");
  98. const accordionBody = accordion.querySelector(".accordion-body");
  99. accordionBtn.addEventListener("click", () => {
  100. accordionBody.classList.toggle("show");
  101. accordionBodyAll.forEach((accordion) => {
  102. if (accordionBody !== accordion) {
  103. accordion.classList.remove("show");
  104. }
  105. });
  106. });
  107. });
  108. }
  109. // const buttons = document.querySelectorAll("[data-carousel-button]")
  110. // ******************************** Custom Banner Slider ******************************/
  111. document.querySelectorAll("[data-banner-slider-button]").forEach((button) => {
  112. button.addEventListener("click", () => {
  113. const offset = button.dataset.carouselButton === "next" ? 1 : -1;
  114. const slides = button
  115. .closest("[data-banner-slider]")
  116. .querySelector("[data-slides]");
  117. const activeSlide = slides.querySelector("[data-active]");
  118. let newIndex = [...slides.children].indexOf(activeSlide) + offset;
  119. if (newIndex < 0) newIndex = slides.children.length - 1;
  120. if (newIndex >= slides.children.length) newIndex = 0;
  121. slides.children[newIndex].dataset.active = true;
  122. delete activeSlide.dataset.active;
  123. });
  124. });
  125. setInterval(function () {
  126. if (document.querySelector(".carousel-button.next"))
  127. document.querySelector(".carousel-button.next").click();
  128. }, 5000);
  129. //****************************** Custom Faculty Carousel - home page ********************/
  130. let totalDivs = document.querySelectorAll(
  131. "#faculty-carousel > .profile-carousel > .car-item"
  132. ).length;
  133. let screenWidth = Math.max(
  134. document.documentElement.clientWidth || 0,
  135. window.innerWidth || 0
  136. );
  137. let totalWidth = totalDivs * 340;
  138. let extraWidth = screenWidth - totalWidth;
  139. let scrolled = 0;
  140. function scrollToNext() {
  141. scrolled -= 345;
  142. let moveX = "";
  143. if (scrolled <= extraWidth - 400) {
  144. scrolled = 0;
  145. }
  146. moveX = scrolled.toString() + "px";
  147. //console.log(moveX, (-1*extraWidth), screenWidth, totalWidth, totalDivs)
  148. document.querySelectorAll(
  149. "#faculty-carousel > .profile-carousel"
  150. )[0].style.left = moveX;
  151. }
  152. function scrollToPrev() {
  153. scrolled = scrolled + 345;
  154. let moveX = "";
  155. if (scrolled > 340) {
  156. scrolled = extraWidth - 50;
  157. }
  158. moveX = scrolled.toString() + "px";
  159. //console.log(scrolled, moveX, (extraWidth), screenWidth, totalWidth, totalDivs)
  160. document.querySelectorAll(
  161. "#faculty-carousel > .profile-carousel"
  162. )[0].style.left = moveX;
  163. }
  164. //************************** Custom Alumni Carousel - home page ***********************/
  165. let totalDivsAl = document.querySelectorAll(
  166. "#alumni-carousel > .profile-carousel > .car-item"
  167. ).length;
  168. let screenWidthAl = Math.max(
  169. document.documentElement.clientWidth || 0,
  170. window.innerWidth || 0
  171. );
  172. let totalWidthAl = totalDivsAl * 340;
  173. let extraWidthAl = screenWidthAl - totalWidthAl;
  174. let scrolledAl = 0;
  175. function scrollToNextAl() {
  176. scrolledAl -= 340;
  177. let moveXAl = "";
  178. if (scrolledAl <= extraWidthAl - 400) {
  179. scrolledAl = 0;
  180. }
  181. moveXAl = scrolledAl.toString() + "px";
  182. document.querySelectorAll(
  183. "#alumni-carousel > .profile-carousel"
  184. )[0].style.left = moveXAl;
  185. }
  186. function scrollToPrevAl() {
  187. scrolledAl = scrolledAl + 340;
  188. let moveXAl = "";
  189. if (scrolledAl > 340) {
  190. scrolledAl = extraWidthAl - 50;
  191. }
  192. moveXAl = scrolledAl.toString() + "px";
  193. document.querySelectorAll(
  194. "#alumni-carousel > .profile-carousel"
  195. )[0].style.left = moveXAl;
  196. }
  197. //*********************** Faculty Members Slider - home page *************************/
  198. var swiper = new Swiper(".facultyMembersSlider", {
  199. slidesPerView: 4,
  200. spaceBetween: 30,
  201. breakpoints: {
  202. 0: {
  203. slidesPerView: 1,
  204. },
  205. 576: {
  206. slidesPerView: 2,
  207. },
  208. 992: {
  209. slidesPerView: 5,
  210. },
  211. },
  212. navigation: {
  213. nextEl: ".faculty-btn-next",
  214. prevEl: ".faculty-btn-prev",
  215. },
  216. });
  217. //***************************** Hero slider - home page *******************************/
  218. var swiper = new Swiper(".heroSlider", {
  219. spaceBetween: 0,
  220. effect: "fade",
  221. centeredSlides: true,
  222. loop: true,
  223. autoplay: {
  224. delay: 2500,
  225. disableOnInteraction: false,
  226. },
  227. navigation: {
  228. nextEl: ".swiper-button-next",
  229. prevEl: ".swiper-button-prev",
  230. },
  231. });
  232. //************************* Recognition Slider - home page ***************************/
  233. const recognitionSlider = new Swiper(".recognitionSlider", {
  234. loop: true,
  235. slidesPerView: 1,
  236. spaceBetween: 50,
  237. autoplay: {
  238. delay: 2400,
  239. disableOnInteraction: false,
  240. },
  241. breakpoints: {
  242. 0: {
  243. slidesPerView: 1,
  244. },
  245. 576: {
  246. slidesPerView: 2,
  247. },
  248. 992: {
  249. slidesPerView: 4,
  250. },
  251. 1200: {
  252. slidesPerView: 4,
  253. },
  254. },
  255. navigation: {
  256. nextEl: ".recognitionSlider-button-next",
  257. prevEl: ".recognitionSlider-button-prev",
  258. },
  259. });
  260. //************************** Departmental News Slider - home page ***********************/
  261. var swiper = new Swiper(".departmentalNews", {
  262. direction: "vertical",
  263. slidesPerView: 2,
  264. spaceBetween: 30,
  265. loop: true,
  266. autoplay: true,
  267. autoplay: {
  268. delay: 3500,
  269. disableOnInteraction: false,
  270. },
  271. // breakpoints: {
  272. // 0: {
  273. // slidesPerView: 1,
  274. // },
  275. // 576: {
  276. // slidesPerView: 3,
  277. // },
  278. // 992: {
  279. // slidesPerView: 4,
  280. // },
  281. // },
  282. navigation: {
  283. nextEl: ".news-btn-next",
  284. prevEl: ".news-btn-prev",
  285. },
  286. });
  287. //*************************** Faculty Profile - faculty single page *****************************/
  288. const facultyProfile = document.querySelector("body.single-faculty");
  289. if (facultyProfile) {
  290. window.addEventListener("resize", showSidebarOptions);
  291. const biosTitle = document.querySelectorAll("h2.m-text");
  292. const list = document.querySelector("ul.profile-choices");
  293. const bios = document.querySelectorAll(".desc-block");
  294. if (window.innerWidth < 600) {
  295. bios.forEach((el) => el.classList.remove(".desc-block-hidden"));
  296. } else {
  297. biosTitle.forEach((el, index) => {
  298. console.log(el.textContent);
  299. let text =
  300. '<li onclick="displaydetails(' +
  301. index +
  302. ')"><a >' +
  303. el.textContent +
  304. "</a></li>";
  305. list.insertAdjacentHTML("beforeend", text);
  306. });
  307. bios.forEach((el) => el.classList.add("desc-block-hidden"));
  308. bios[0].classList.remove("desc-block-hidden");
  309. let listItem = document.querySelectorAll("ul.profile-choices>li");
  310. listItem[0].classList.add("desc-active");
  311. }
  312. function displaydetails(i) {
  313. bios.forEach((el) => el.classList.add("desc-block-hidden"));
  314. bios[i].classList.remove("desc-block-hidden");
  315. let listItem = document.querySelectorAll("ul.profile-choices>li");
  316. listItem.forEach((el) => el.classList.remove("desc-active"));
  317. listItem[i].classList.add("desc-active");
  318. }
  319. function showSidebarOptions() {
  320. console.log(window.innerWidth);
  321. let windowX = window.matchMedia("(max-width: 600px)");
  322. if (windowX.matches) {
  323. bios.forEach((el) => el.classList.remove(".desc-block-hidden"));
  324. } else {
  325. bios.forEach((el) => el.classList.add("desc-block-hidden"));
  326. bios[0].classList.remove("desc-block-hidden");
  327. }
  328. }
  329. }
  330. //************************************ Utilities ****************************/
  331. // Color Picker
  332. const colorPicker = document.querySelector(".pickers");
  333. if (colorPicker) {
  334. const pickr = Pickr.create({
  335. el: ".color-picker",
  336. theme: "nano",
  337. swatches: [
  338. "rgba(244, 67, 54, 1)",
  339. "rgba(233, 30, 99, 0.95)",
  340. "rgba(156, 39, 176, 0.9)",
  341. "rgba(103, 58, 183, 0.85)",
  342. "rgba(63, 81, 181, 0.8)",
  343. "rgba(33, 150, 243, 0.75)",
  344. "rgba(3, 169, 244, 0.7)",
  345. "rgba(0, 188, 212, 0.7)",
  346. "rgba(0, 150, 136, 0.75)",
  347. "rgba(76, 175, 80, 0.8)",
  348. "rgba(139, 195, 74, 0.85)",
  349. "rgba(205, 220, 57, 0.9)",
  350. "rgba(255, 235, 59, 0.95)",
  351. "rgba(255, 193, 7, 1)",
  352. ],
  353. components: {
  354. // Main components
  355. preview: true,
  356. opacity: true,
  357. hue: true,
  358. // Input / output Options
  359. interaction: {
  360. hex: true,
  361. rgba: false,
  362. hsla: false,
  363. hsva: false,
  364. cmyk: false,
  365. input: true,
  366. clear: true,
  367. save: true,
  368. },
  369. },
  370. });
  371. pickr.on("change", (...args) => {
  372. let color = args[0].toHEXA();
  373. console.log(args);
  374. console.log(color.toString());
  375. const buttons = document.getElementsByClassName("primary-c");
  376. for (let i = 0; i < buttons.length; i++) {
  377. buttons[i].style.backgroundColor = color.toString();
  378. buttons[i].addEventListener("mouseenter", (e) => {
  379. buttons[i].style.backgroundColor = "#F68B1F";
  380. });
  381. buttons[i].addEventListener("mouseleave", (e) => {
  382. buttons[i].style.backgroundColor = color.toString();
  383. });
  384. }
  385. });
  386. }
  387. // scroll responsive
  388. window.onscroll = function () {
  389. let navbar = document.querySelector("#navbar");
  390. if (window.scrollY > 300) {
  391. if (navbar) navbar.classList.add("scroll");
  392. } else {
  393. if (navbar) navbar.classList.remove("scroll");
  394. }
  395. };
  396. //for NAV
  397. function openNav() {
  398. document.getElementById("myNav").style.height = "100%";
  399. }
  400. /* Close when someone clicks on the "x" symbol inside the overlay */
  401. function closeNav() {
  402. document.getElementById("myNav").style.height = "0%";
  403. }
  404. function openSearch() {
  405. document.getElementById("search-modal").style.height = "100%";
  406. console.log("search opened");
  407. }
  408. /* Close when someone clicks on the "x" symbol inside the overlay */
  409. function closeSearch() {
  410. document.getElementById("search-modal").style.height = "0%";
  411. }