theme-settings.js 11 KB

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