app.js 12 KB

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