app.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. // header on scroll sticky
  2. window.addEventListener('scroll', function(){
  3. var header = document.querySelector('.header');
  4. header.classList.toggle("sticky", window.scrollY > 400);
  5. })
  6. // header search btn for mobile screen
  7. const searchBar = document.querySelector(".search")
  8. const searchButton = document.querySelector(".search-btn-mobile")
  9. if ( searchBar && searchButton) {
  10. searchButton.addEventListener("click", () => {
  11. searchBar.classList.toggle("active")
  12. })
  13. }
  14. // header mega menu
  15. const megaMenuContainer = document.querySelectorAll(".megamenu-parrent");
  16. const menuItemsAll = document.querySelectorAll(".menu-items");
  17. if(megaMenuContainer) {
  18. megaMenuContainer.forEach(container => {
  19. const megaButton = container.querySelector(".collapse-buton");
  20. const menuItems = container.querySelector(".menu-items")
  21. if(megaButton && menuItems) {
  22. megaButton.addEventListener("click", () => {
  23. menuItems.classList.toggle("active");
  24. menuItemsAll.forEach(item => {
  25. if (item !== menuItems) {
  26. item.classList.remove("active")
  27. }
  28. })
  29. })
  30. }
  31. })
  32. }
  33. // header sub-menu
  34. const megaSubMenu = document.querySelectorAll('.megamenu-submenu .items');
  35. const subMenuItemsAll = document.querySelectorAll('.megamenu-submenu .submenu-items')
  36. megaSubMenu.forEach(menu => {
  37. const subMenuBtn = menu.querySelector('.submenu-buton');
  38. const subMenuItems = menu.querySelector('.submenu-items')
  39. if (subMenuItems && subMenuBtn) {
  40. subMenuBtn.addEventListener('click', () => {
  41. subMenuItems.classList.toggle('active')
  42. subMenuItemsAll.forEach(item => {
  43. if (item !== subMenuItems) {
  44. item.classList.remove("active")
  45. }
  46. })
  47. })
  48. }
  49. })
  50. // burger menu function
  51. const burgerMenu = document.querySelector(".burger-menu");
  52. const burgerMenuClose = document.querySelector(".burger-close-btn");
  53. const mainNav = document.querySelector(".main-nav")
  54. // open menu
  55. if(burgerMenu && mainNav) {
  56. burgerMenu.addEventListener("click", () => {
  57. mainNav.classList.add("active")
  58. })
  59. }
  60. // close menu
  61. if(burgerMenuClose && mainNav) {
  62. burgerMenuClose.addEventListener("click", () => {
  63. mainNav.classList.remove("active")
  64. })
  65. }
  66. // fileter sidebar function
  67. // filter open button
  68. const filterOpenBtn = document.querySelector("#filter-button");
  69. // filter close button
  70. const filterCloseBtn = document.querySelector('.filter-close-btn');
  71. // filter sidebar container
  72. const filterContainer = document.querySelector('.filter');
  73. // filter open open function
  74. if (filterOpenBtn && filterContainer) {
  75. filterOpenBtn.addEventListener("click", () => {
  76. filterContainer.classList.add("active")
  77. });
  78. }
  79. // filter close button
  80. if (filterContainer && filterCloseBtn) {
  81. filterCloseBtn.addEventListener("click", () => {
  82. filterContainer.classList.remove("active")
  83. });
  84. }
  85. // fileter sidebar function end
  86. // checkout sidebar function
  87. // checkout open desktop button
  88. const checkoutProductBtnDesktop = document.querySelector('.checkout-product-btn-desktop')
  89. // checkout open mobile button
  90. const checkoutProductBtnMobile = document.querySelector('.checkout-product-btn-mobile')
  91. // checkout close button
  92. const checkoutContainerCloseBtn = document.querySelector('.cross-btn')
  93. // checkout container
  94. const checkoutContainer = document.querySelector('.checkout-container')
  95. // checkout open function for desktop
  96. if(checkoutProductBtnDesktop && checkoutContainer) {
  97. checkoutProductBtnDesktop.addEventListener('click', () => {
  98. // hide fillter sidebar if open
  99. if (filterContainer) {
  100. filterContainer.classList.remove("active")
  101. }
  102. // open checkout sidebar
  103. checkoutContainer.style.display = "block";
  104. })
  105. };
  106. // checkout open function for mobile
  107. if(checkoutProductBtnMobile && checkoutContainer ) {
  108. checkoutProductBtnMobile.addEventListener('click', () => {
  109. // hide fillter sidebar if open
  110. if (filterContainer) {
  111. filterContainer.classList.remove("active")
  112. }
  113. // open checkout sidebar
  114. checkoutContainer.style.display = "block";
  115. })
  116. };
  117. // checkout close function
  118. if(checkoutContainerCloseBtn && checkoutContainer) {
  119. checkoutContainerCloseBtn.addEventListener('click', () => {
  120. checkoutContainer.style.display = "none"
  121. })
  122. }
  123. // checkout sidebar function end
  124. // all carousel
  125. // homepage hero banner slider home page
  126. const bannerSlider = new Swiper(".bannerSlider", {
  127. spaceBetween: 30,
  128. centeredSlides: true,
  129. autoplay: {
  130. delay: 2500,
  131. disableOnInteraction: false,
  132. }
  133. });
  134. // category slider home page
  135. const categorySlider = new Swiper('.categorySlider', {
  136. loop: false,
  137. slidesPerView: 5,
  138. spaceBetween: 30,
  139. loopedSlides: 1,
  140. breakpoints: {
  141. 0: {
  142. slidesPerView: 5,
  143. spaceBetween: 10,
  144. },
  145. 576: {
  146. slidesPerView: 4,
  147. },
  148. 993: {
  149. slidesPerView: 5,
  150. }
  151. },
  152. navigation: {
  153. nextEl: ".swiper-button-next",
  154. prevEl: ".swiper-button-prev",
  155. },
  156. });
  157. // Feture brand slider home page
  158. const featuredBrands = new Swiper('.featuredBrands', {
  159. loop: false,
  160. slidesPerView: 4,
  161. spaceBetween: 30,
  162. loopedSlides: 1,
  163. navigation: false,
  164. breakpoints: {
  165. 0: {
  166. slidesPerView: 2,
  167. },
  168. 576: {
  169. slidesPerView: 3,
  170. },
  171. 993: {
  172. slidesPerView: 5,
  173. }
  174. },
  175. });
  176. // Feture brand slider home page
  177. const trendingStories = new Swiper('.trendingStories', {
  178. loop: true,
  179. slidesPerView: 3,
  180. spaceBetween: 30,
  181. loopedSlides: 1,
  182. navigation: false,
  183. breakpoints: {
  184. 0: {
  185. slidesPerView: 1,
  186. },
  187. 576: {
  188. slidesPerView: 2,
  189. },
  190. 993: {
  191. slidesPerView: 3,
  192. }
  193. },
  194. navigation: {
  195. nextEl: ".swiper-button-next",
  196. prevEl: ".swiper-button-prev",
  197. },
  198. });
  199. // all product nav slider brand slider all product page
  200. const allProductNav = new Swiper('.all-product-nav-slider', {
  201. loop: false,
  202. slidesPerView: 8,
  203. spaceBetween: 8,
  204. loopedSlides: 1,
  205. navigation: false
  206. });
  207. // // product details page carousel
  208. // thumb carousel
  209. var productThumb = new Swiper('.productThumb', {
  210. loop: true,
  211. loopedSlides: 1,
  212. spaceBetween: 10,
  213. slidesPerView: 2,
  214. direction: 'vertical',
  215. freeMode: true,
  216. breakpoints: {
  217. 0: {
  218. direction: 'horizontal',
  219. spaceBetween: 15,
  220. slidesPerView: 4,
  221. centeredSlides: true,
  222. },
  223. 993: {
  224. direction: 'vertical',
  225. spaceBetween: 15,
  226. slidesPerView: 3,
  227. }
  228. }
  229. });
  230. // productSlider carousel
  231. var productSlider = new Swiper('.productSlider', {
  232. loop: true,
  233. spaceBetween: 10,
  234. loopedSlides: 1,
  235. centeredSlides: true,
  236. freeMode: true,
  237. navigation: {
  238. nextEl: '.swiper-button-next',
  239. prevEl: '.swiper-button-prev',
  240. disabledClass: 'disabled_swiper_button'
  241. },
  242. thumbs: {
  243. swiper: productThumb,
  244. },
  245. });
  246. // all carousel end
  247. // simple light box
  248. let gallery = new SimpleLightbox('.gallery a', {});
  249. if(gallery) {
  250. gallery.on('show.simplelightbox', function () {
  251. // do something…
  252. });
  253. }
  254. // checkout page stepper
  255. const step = document.getElementsByClassName("step");
  256. if (step) {
  257. var currentTab = 0; // Current tab is set to be the first tab (0)
  258. showTab(currentTab); // Display the current tab
  259. function showTab(n) {
  260. // This function will display the specified tab of the form...
  261. var x = document.getElementsByClassName("step");
  262. x[n].style.display = "block";
  263. //... and fix the Previous/Next buttons:
  264. if (n == 0) {
  265. document.getElementById("prevBtn").style.display = "none";
  266. } else {
  267. document.getElementById("prevBtn").style.display = "inline";
  268. }
  269. if (n == (x.length - 1)) {
  270. document.getElementById("nextBtn").innerHTML = "Submit";
  271. } else {
  272. document.getElementById("nextBtn").innerHTML = "Next";
  273. }
  274. //... and run a function that will display the correct step indicator:
  275. fixStepIndicator(n)
  276. }
  277. function nextPrev(n) {
  278. // This function will figure out which tab to display
  279. var x = document.getElementsByClassName("step");
  280. // Exit the function if any field in the current tab is invalid:
  281. if (n == 1 && !validateForm()) return false;
  282. // Hide the current tab:
  283. x[currentTab].style.display = "none";
  284. // Increase or decrease the current tab by 1:
  285. currentTab = currentTab + n;
  286. // if you have reached the end of the form...
  287. if (currentTab >= x.length) {
  288. // ... the form gets submitted:
  289. document.getElementById("checkoutForm").submit();
  290. return false;
  291. }
  292. // Otherwise, display the correct tab:
  293. showTab(currentTab);
  294. }
  295. function validateForm() {
  296. // This function deals with validation of the form fields
  297. var x, y, z, w, i, valid = true;
  298. x = document.getElementsByClassName("step");
  299. y = x[currentTab].getElementsByTagName("input");
  300. z = x[currentTab].getElementsByTagName("select");
  301. w = x[currentTab].getElementsByTagName("textarea");
  302. // A loop that checks every input field in the current tab:
  303. for (i = 0; i < y.length; i++) {
  304. // If a field is empty...
  305. if (y[i].value == "") {
  306. // add an "invalid" class to the field:
  307. y[i].className += " invalid";
  308. // and set the current valid status to false
  309. valid = false;
  310. }
  311. }
  312. for (i = 0; i < z.length; i++) {
  313. // If a field is empty...
  314. if (z[i].value == "") {
  315. // add an "invalid" class to the field:
  316. z[i].className += " invalid";
  317. // and set the current valid status to false
  318. valid = false;
  319. }
  320. }
  321. for (i = 0; i < w.length; i++) {
  322. // If a field is empty...
  323. if (w[i].value == "") {
  324. // add an "invalid" class to the field:
  325. w[i].className += " invalid";
  326. // and set the current valid status to false
  327. valid = false;
  328. }
  329. }
  330. // If the valid status is true, mark the step as finished and valid:
  331. if (valid) {
  332. document.getElementsByClassName("stepIndicator")[currentTab].className += " finish";
  333. }
  334. return valid; // return the valid status
  335. }
  336. function fixStepIndicator(n) {
  337. // This function removes the "active" class of all steps...
  338. var i, x = document.getElementsByClassName("stepIndicator");
  339. for (i = 0; i < x.length; i++) {
  340. x[i].className = x[i].className.replace(" active", "");
  341. }
  342. //... and adds the "active" class on the current step:
  343. x[n].className += " active";
  344. }
  345. }