theme-settings.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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. // accordion
  42. const accordionAll = document.querySelectorAll("#accordion");
  43. const accordionBodyAll = document.querySelectorAll(".accordion-body");
  44. if (accordionAll) {
  45. accordionAll.forEach((accordion) => {
  46. const accordionBtn = accordion.querySelector(".accordion-btn");
  47. const accordionBody = accordion.querySelector(".accordion-body");
  48. accordionBtn.addEventListener("click", () => {
  49. accordionBody.classList.toggle("show");
  50. accordionBodyAll.forEach((accordion) => {
  51. if (accordionBody !== accordion) {
  52. accordion.classList.remove("show");
  53. }
  54. });
  55. });
  56. });
  57. }
  58. // const buttons = document.querySelectorAll("[data-carousel-button]")
  59. document.querySelectorAll("[data-banner-slider-button]").forEach((button) => {
  60. button.addEventListener("click", () => {
  61. const offset = button.dataset.carouselButton === "next" ? 1 : -1;
  62. const slides = button
  63. .closest("[data-banner-slider]")
  64. .querySelector("[data-slides]");
  65. const activeSlide = slides.querySelector("[data-active]");
  66. let newIndex = [...slides.children].indexOf(activeSlide) + offset;
  67. if (newIndex < 0) newIndex = slides.children.length - 1;
  68. if (newIndex >= slides.children.length) newIndex = 0;
  69. slides.children[newIndex].dataset.active = true;
  70. delete activeSlide.dataset.active;
  71. });
  72. });
  73. setInterval(function () {
  74. if (document.querySelector(".carousel-button.next"))
  75. document.querySelector(".carousel-button.next").click();
  76. }, 5000);
  77. function openSearch() {
  78. document.getElementById("search-modal").style.height = "100%";
  79. console.log("search opened");
  80. }
  81. /* Close when someone clicks on the "x" symbol inside the overlay */
  82. function closeSearch() {
  83. document.getElementById("search-modal").style.height = "0%";
  84. }
  85. let totalDivs = document.querySelectorAll(
  86. "#faculty-carousel > .profile-carousel > .car-item"
  87. ).length;
  88. let screenWidth = Math.max(
  89. document.documentElement.clientWidth || 0,
  90. window.innerWidth || 0
  91. );
  92. let totalWidth = totalDivs * 340;
  93. let extraWidth = screenWidth - totalWidth;
  94. let scrolled = 0;
  95. function scrollToNext() {
  96. scrolled -= 345;
  97. let moveX = "";
  98. if (scrolled <= extraWidth - 400) {
  99. scrolled = 0;
  100. }
  101. moveX = scrolled.toString() + "px";
  102. //console.log(moveX, (-1*extraWidth), screenWidth, totalWidth, totalDivs)
  103. document.querySelectorAll(
  104. "#faculty-carousel > .profile-carousel"
  105. )[0].style.left = moveX;
  106. }
  107. function scrollToPrev() {
  108. scrolled = scrolled + 345;
  109. let moveX = "";
  110. if (scrolled > 340) {
  111. scrolled = extraWidth - 50;
  112. }
  113. moveX = scrolled.toString() + "px";
  114. //console.log(scrolled, moveX, (extraWidth), screenWidth, totalWidth, totalDivs)
  115. document.querySelectorAll(
  116. "#faculty-carousel > .profile-carousel"
  117. )[0].style.left = moveX;
  118. }
  119. let totalDivsAl = document.querySelectorAll(
  120. "#alumni-carousel > .profile-carousel > .car-item"
  121. ).length;
  122. let screenWidthAl = Math.max(
  123. document.documentElement.clientWidth || 0,
  124. window.innerWidth || 0
  125. );
  126. let totalWidthAl = totalDivsAl * 340;
  127. let extraWidthAl = screenWidthAl - totalWidthAl;
  128. let scrolledAl = 0;
  129. function scrollToNextAl() {
  130. scrolledAl -= 340;
  131. let moveXAl = "";
  132. if (scrolledAl <= extraWidthAl - 400) {
  133. scrolledAl = 0;
  134. }
  135. moveXAl = scrolledAl.toString() + "px";
  136. document.querySelectorAll(
  137. "#alumni-carousel > .profile-carousel"
  138. )[0].style.left = moveXAl;
  139. }
  140. function scrollToPrevAl() {
  141. scrolledAl = scrolledAl + 340;
  142. let moveXAl = "";
  143. if (scrolledAl > 340) {
  144. scrolledAl = extraWidthAl - 50;
  145. }
  146. moveXAl = scrolledAl.toString() + "px";
  147. document.querySelectorAll(
  148. "#alumni-carousel > .profile-carousel"
  149. )[0].style.left = moveXAl;
  150. }
  151. //for NAV
  152. function openNav() {
  153. document.getElementById("myNav").style.height = "100%";
  154. }
  155. /* Close when someone clicks on the "x" symbol inside the overlay */
  156. function closeNav() {
  157. document.getElementById("myNav").style.height = "0%";
  158. }
  159. //profile
  160. const facultyProfile = document.querySelector("body.single-faculty");
  161. if (facultyProfile) {
  162. window.addEventListener("resize", showSidebarOptions);
  163. const biosTitle = document.querySelectorAll("h2.m-text");
  164. const list = document.querySelector("ul.profile-choices");
  165. const bios = document.querySelectorAll(".desc-block");
  166. if (window.innerWidth < 600) {
  167. bios.forEach((el) => el.classList.remove(".desc-block-hidden"));
  168. } else {
  169. biosTitle.forEach((el, index) => {
  170. console.log(el.textContent);
  171. let text =
  172. '<li onclick="displaydetails(' +
  173. index +
  174. ')"><a >' +
  175. el.textContent +
  176. "</a></li>";
  177. list.insertAdjacentHTML("beforeend", text);
  178. });
  179. bios.forEach((el) => el.classList.add("desc-block-hidden"));
  180. bios[0].classList.remove("desc-block-hidden");
  181. let listItem = document.querySelectorAll("ul.profile-choices>li");
  182. listItem[0].classList.add("desc-active");
  183. }
  184. function displaydetails(i) {
  185. bios.forEach((el) => el.classList.add("desc-block-hidden"));
  186. bios[i].classList.remove("desc-block-hidden");
  187. let listItem = document.querySelectorAll("ul.profile-choices>li");
  188. listItem.forEach((el) => el.classList.remove("desc-active"));
  189. listItem[i].classList.add("desc-active");
  190. }
  191. function showSidebarOptions() {
  192. console.log(window.innerWidth);
  193. let windowX = window.matchMedia("(max-width: 600px)");
  194. if (windowX.matches) {
  195. bios.forEach((el) => el.classList.remove(".desc-block-hidden"));
  196. } else {
  197. bios.forEach((el) => el.classList.add("desc-block-hidden"));
  198. bios[0].classList.remove("desc-block-hidden");
  199. }
  200. }
  201. }
  202. // Simple example, see optional options for more configuration.
  203. const colorPicker = document.querySelector(".pickers");
  204. if (colorPicker) {
  205. const pickr = Pickr.create({
  206. el: ".color-picker",
  207. theme: "nano",
  208. swatches: [
  209. "rgba(244, 67, 54, 1)",
  210. "rgba(233, 30, 99, 0.95)",
  211. "rgba(156, 39, 176, 0.9)",
  212. "rgba(103, 58, 183, 0.85)",
  213. "rgba(63, 81, 181, 0.8)",
  214. "rgba(33, 150, 243, 0.75)",
  215. "rgba(3, 169, 244, 0.7)",
  216. "rgba(0, 188, 212, 0.7)",
  217. "rgba(0, 150, 136, 0.75)",
  218. "rgba(76, 175, 80, 0.8)",
  219. "rgba(139, 195, 74, 0.85)",
  220. "rgba(205, 220, 57, 0.9)",
  221. "rgba(255, 235, 59, 0.95)",
  222. "rgba(255, 193, 7, 1)",
  223. ],
  224. components: {
  225. // Main components
  226. preview: true,
  227. opacity: true,
  228. hue: true,
  229. // Input / output Options
  230. interaction: {
  231. hex: true,
  232. rgba: false,
  233. hsla: false,
  234. hsva: false,
  235. cmyk: false,
  236. input: true,
  237. clear: true,
  238. save: true,
  239. },
  240. },
  241. });
  242. pickr.on("change", (...args) => {
  243. let color = args[0].toHEXA();
  244. console.log(args);
  245. console.log(color.toString());
  246. const buttons = document.getElementsByClassName("primary-c");
  247. for (let i = 0; i < buttons.length; i++) {
  248. buttons[i].style.backgroundColor = color.toString();
  249. buttons[i].addEventListener("mouseenter", (e) => {
  250. buttons[i].style.backgroundColor = "#F68B1F";
  251. });
  252. buttons[i].addEventListener("mouseleave", (e) => {
  253. buttons[i].style.backgroundColor = color.toString();
  254. });
  255. }
  256. });
  257. }