theme-settings.js 11 KB

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