theme-settings.js 11 KB

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