theme-settings.js 11 KB

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