app-ecommerce-shop.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*=========================================================================================
  2. File Name: app-ecommerce-shop.js
  3. Description: Ecommerce Shop
  4. ----------------------------------------------------------------------------------------
  5. Item name: Vuexy - Vuejs, HTML & Laravel Admin Dashboard Template
  6. Author: PIXINVENT
  7. Author URL: http://www.themeforest.net/user/pixinvent
  8. ==========================================================================================*/
  9. $(document).ready(function () {
  10. "use strict";
  11. // RTL Support
  12. var direction = 'ltr';
  13. if ($('html').data('textdirection') == 'rtl') {
  14. direction = 'rtl';
  15. }
  16. var sidebarShop = $(".sidebar-shop"),
  17. shopOverlay = $(".shop-content-overlay"),
  18. sidebarToggler = $(".shop-sidebar-toggler"),
  19. priceFilter = $(".price-options"),
  20. gridViewBtn = $(".grid-view-btn"),
  21. listViewBtn = $(".list-view-btn"),
  22. ecommerceProducts = $("#ecommerce-products"),
  23. cart = $(".cart"),
  24. wishlist = $(".wishlist");
  25. // show sidebar
  26. sidebarToggler.on("click", function () {
  27. sidebarShop.toggleClass("show");
  28. shopOverlay.toggleClass("show");
  29. });
  30. // remove sidebar
  31. $(".shop-content-overlay, .sidebar-close-icon").on("click", function () {
  32. sidebarShop.removeClass("show");
  33. shopOverlay.removeClass("show");
  34. })
  35. //price slider
  36. var slider = document.getElementById("price-slider");
  37. if (slider) {
  38. noUiSlider.create(slider, {
  39. start: [51, 5000],
  40. direction: direction,
  41. connect: true,
  42. tooltips: [true, true],
  43. format: wNumb({
  44. decimals: 0,
  45. }),
  46. range: {
  47. "min": 51,
  48. "max": 5000
  49. }
  50. });
  51. }
  52. // for select in ecommerce header
  53. if (priceFilter.length > 0) {
  54. priceFilter.select2({
  55. minimumResultsForSearch: -1,
  56. dropdownAutoWidth: true,
  57. width: 'auto'
  58. });
  59. }
  60. /***** CHANGE VIEW *****/
  61. // Grid View
  62. gridViewBtn.on("click", function () {
  63. ecommerceProducts.removeClass("list-view").addClass("grid-view");
  64. listViewBtn.removeClass("active");
  65. gridViewBtn.addClass("active");
  66. });
  67. // List View
  68. listViewBtn.on("click", function () {
  69. ecommerceProducts.removeClass("grid-view").addClass("list-view");
  70. gridViewBtn.removeClass("active");
  71. listViewBtn.addClass("active");
  72. });
  73. // For View in cart
  74. cart.on("click", function () {
  75. var $this = $(this),
  76. addToCart = $this.find(".add-to-cart"),
  77. viewInCart = $this.find(".view-in-cart");
  78. if (addToCart.is(':visible')) {
  79. addToCart.addClass("d-none");
  80. viewInCart.addClass("d-inline-block");
  81. }
  82. else {
  83. var href = viewInCart.attr('href');
  84. window.location.href = href;
  85. }
  86. });
  87. $(".view-in-cart").on('click', function (e) {
  88. e.preventDefault();
  89. });
  90. // For Wishlist Icon
  91. wishlist.on("click", function () {
  92. var $this = $(this)
  93. $this.find("i").toggleClass("fa-heart-o fa-heart")
  94. $this.toggleClass("added");
  95. })
  96. // Checkout Wizard
  97. var checkoutWizard = $(".checkout-tab-steps"),
  98. checkoutValidation = checkoutWizard.show();
  99. if (checkoutWizard.length > 0) {
  100. $(checkoutWizard).steps({
  101. headerTag: "h6",
  102. bodyTag: "fieldset",
  103. transitionEffect: "fade",
  104. titleTemplate: '<span class="step">#index#</span> #title#',
  105. enablePagination: false,
  106. onStepChanging: function (event, currentIndex, newIndex) {
  107. // allows to go back to previous step if form is
  108. if (currentIndex > newIndex) {
  109. return true;
  110. }
  111. // Needed in some cases if the user went back (clean up)
  112. if (currentIndex < newIndex) {
  113. // To remove error styles
  114. checkoutValidation.find(".body:eq(" + newIndex + ") label.error").remove();
  115. checkoutValidation.find(".body:eq(" + newIndex + ") .error").removeClass("error");
  116. }
  117. // check for valid details and show notification accordingly
  118. if (currentIndex === 1 && Number($(".form-control.required").val().length) < 1) {
  119. toastr.warning('Error', 'Please Enter Valid Details', { "positionClass": "toast-bottom-right" });
  120. }
  121. checkoutValidation.validate().settings.ignore = ":disabled,:hidden";
  122. return checkoutValidation.valid();
  123. },
  124. });
  125. // to move to next step on place order and save address click
  126. $(".place-order, .delivery-address").on("click", function () {
  127. $(".checkout-tab-steps").steps("next", {});
  128. });
  129. // check if user has entered valid cvv
  130. $(".btn-cvv").on("click", function () {
  131. if ($(".input-cvv").val().length == 3) {
  132. toastr.success('Success', 'Payment received Successfully', { "positionClass": "toast-bottom-right" });
  133. }
  134. else {
  135. toastr.warning('Error', 'Please Enter Valid Details', { "positionClass": "toast-bottom-right" });
  136. }
  137. })
  138. }
  139. // checkout quantity counter
  140. var quantityCounter = $(".quantity-counter"),
  141. CounterMin = 1,
  142. CounterMax = 10;
  143. if (quantityCounter.length > 0) {
  144. quantityCounter.TouchSpin({
  145. min: CounterMin,
  146. max: CounterMax
  147. }).on('touchspin.on.startdownspin', function () {
  148. var $this = $(this);
  149. $('.bootstrap-touchspin-up').removeClass("disabled-max-min");
  150. if ($this.val() == 1) {
  151. $(this).siblings().find('.bootstrap-touchspin-down').addClass("disabled-max-min");
  152. }
  153. }).on('touchspin.on.startupspin', function () {
  154. var $this = $(this);
  155. $('.bootstrap-touchspin-down').removeClass("disabled-max-min");
  156. if ($this.val() == 10) {
  157. $(this).siblings().find('.bootstrap-touchspin-up').addClass("disabled-max-min");
  158. }
  159. });
  160. }
  161. // remove items from wishlist page
  162. $(".remove-wishlist , .move-cart").on("click", function () {
  163. $(this).closest(".ecommerce-card").remove();
  164. })
  165. })
  166. // on window resize hide sidebar
  167. $(window).on("resize", function () {
  168. if ($(window).outerWidth() >= 991) {
  169. $(".sidebar-shop").removeClass("show");
  170. $(".shop-content-overlay").removeClass("show");
  171. }
  172. });