app.js 13 KB

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