app.js 11 KB

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