Blame view

frontend/web/js/script.js 7.48 KB
6c8e3423   Yarik   Fast buy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
  $(function() {
      var basket = new ArtboxBasket({
          'cartSelector': '#cart'
      });
      /**
       * Modal form submit code
       */
      $(document)
          .on('beforeSubmit', '#feedback-form', function(e) {
              var f = this;
              var form = $(this);
              var formData = form.serialize();
              $.ajax({
                  url: form.attr("action"),
                  type: form.attr("method"),
                  data: formData,
                  success: function(data) {
                      f.reset();
                      $('#feedback-modal')
                          .modal('hide');
                      $('#success-modal')
                          .modal('show');
                  },
                  error: function() {
                      $('#feedback-modal')
                          .modal('hide');
6748c345   Alexey Boroda   -Forms almost ready
27
                  }
6c8e3423   Yarik   Fast buy
28
29
30
31
32
              });
          })
          .on('submit', '#feedback-form', function(e) {
              e.preventDefault();
          });
657a0f05   Alexey Boroda   -Button up
33
  
6c8e3423   Yarik   Fast buy
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
      /**
       * Contact form submitting
       */
      $(document)
          .on('beforeSubmit', '#contact-form', function(e) {
              var f = this;
              var form = $(this);
              var formData = form.serialize();
              $.ajax({
                  url: form.attr("action"),
                  type: form.attr("method"),
                  data: formData,
                  success: function(data) {
                      f.reset();
                      form.replaceWith(data.alert);
                  },
                  error: function() {
83309611   Alexey Boroda   -Map in process
51
  
83309611   Alexey Boroda   -Map in process
52
                  }
6c8e3423   Yarik   Fast buy
53
54
55
56
57
              });
          })
          .on('submit', '#contact-form', function(e) {
              e.preventDefault();
          });
4bf9edb7   Yarik   Order
58
  
6c8e3423   Yarik   Fast buy
59
60
61
62
63
64
65
66
67
68
69
      /**
       * Button UP code
       */
      if ($('#back-to-top').length) {
          var scrollTrigger = 100, // px
              backToTop = function() {
                  var scrollTop = $(window)
                      .scrollTop();
                  if (scrollTop > scrollTrigger) {
                      $('#back-to-top')
                          .addClass('show');
7f57ad53   Eugeny Galkovskiy   уведомление о доб...
70
                  } else {
6c8e3423   Yarik   Fast buy
71
72
                      $('#back-to-top')
                          .removeClass('show');
7f57ad53   Eugeny Galkovskiy   уведомление о доб...
73
                  }
6c8e3423   Yarik   Fast buy
74
75
76
77
78
              };
          backToTop();
          $(window)
              .on('scroll', function() {
                  backToTop();
4bf9edb7   Yarik   Order
79
              });
6c8e3423   Yarik   Fast buy
80
81
          $('#back-to-top')
              .on('click', function(e) {
4bf9edb7   Yarik   Order
82
                  e.preventDefault();
6c8e3423   Yarik   Fast buy
83
84
85
86
                  $('html,body')
                      .animate({
                          scrollTop: 0
                      }, 700);
4bf9edb7   Yarik   Order
87
              });
6c8e3423   Yarik   Fast buy
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
      }
  
      $(document)
          .on('click', '.add-to-basket', function(e) {
              e.preventDefault();
              var id = $(this)
                  .data('id');
              basket.add(id, 1);
              if ($('.alert-cart').length > 0) {
              } else {
                  $('body')
                      .prepend($("<div class='alert-cart alert alert-success alert-dismissible'>Товар добавлен в корзину.</div>"));
                  setTimeout(function() {
                      $(".alert-cart")
                          .addClass("active");
                  }, 100);
                  setTimeout(function() {
                      $(".alert-cart")
                          .removeClass("active");
                  }, 3500);
                  setTimeout(function() {
                      $(".alert-cart")
                          .remove();
                  }, 3600);
              }
          });
4bf9edb7   Yarik   Order
114
  
6c8e3423   Yarik   Fast buy
115
116
117
118
119
120
121
122
123
124
125
126
127
      $(document)
          .on('click', '.remove-product-cart', function(e) {
              e.preventDefault();
              var id = $(this)
                  .parents('.product-row-basket')
                  .data('id');
              showLoader('#basket');
              var xhr = basket.remove(id);
              xhr.done(function() {
                  $.pjax.reload({
                      container: '#basket',
                      fragment: '#basket',
                      timeout: 5000
4bf9edb7   Yarik   Order
128
                  });
6c8e3423   Yarik   Fast buy
129
130
              })
          });
4bf9edb7   Yarik   Order
131
  
6c8e3423   Yarik   Fast buy
132
133
134
135
136
137
138
139
140
141
142
143
144
145
      $(document)
          .on('change', '.increase-product-basket', function(e) {
              var id = $(this)
                  .parents('.product-row-basket')
                  .data('id');
              showLoader('#basket');
              var xhr = basket.set(id, $(this)
                  .val());
              xhr.done(function() {
                  $.pjax.reload({
                      container: '#basket',
                      fragment: '#basket',
                      timeout: 5000
                  });
4bf9edb7   Yarik   Order
146
              });
6c8e3423   Yarik   Fast buy
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
          });
  
      $(document)
          .on('click', 'li.disabled a', function(e) {
              e.preventDefault();
          });
  
      $(document)
          .on('submit', '#fast-buy-form', function(e) {
              e.preventDefault();
          });
  
      $(document)
          .on('afterValidate', '#fast-buy-form', function(e, m, errors) {
              if (!errors.length) {
                  var form = $(e.target);
                  var action = form.attr('action');
                  $.post(action, form.serialize(), function(data) {
                      if (data.success) {
                          $('#oneclick-modal')
                              .find('.modal-body')
                              .text(data.msg);
                      }
                  });
              }
          }.bind(this));
  
ac6e2c67   Alexey Boroda   -Cabinet ready
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
      $(document)
          .on(
              'click', '.wishlist-rm, .wishlist-add', function() {
                  var button = $(this);
                  $.ajax(
                      {
                          url: button.data('url'),
                          type: "POST",
                          data: {
                              'variant': button.data('variant'),
                              'product': button.data('product'),
                              'user': button.data('user')
                          },
                          success: function(data) {
                              button.replaceWith(data.button);
                              new PNotify(
                                  {
                                      title: 'Info',
                                      text: data.message,
                                      type: 'info',
                                      styling: 'fontawesome'
                                  }
                              );
  
                          }
                      }
                  )
              }
          );
  
      $(document)
          .on(
              'click', '.wishlist-delete', function(e) {
                  e.preventDefault();
                  var button = $(this);
                  $.ajax(
                      {
                          url: button.data('url'),
                          type: "POST",
                          data: {
                              'product': button.data('product'),
                              'variant': button.data('variant'),
                              'user': button.data('user')
                          },
                          success: function(data) {
                              if (data.success) {
                                  $.pjax.reload({container: '#wishlist-products'});
                                  new PNotify(
                                      {
                                          title: 'Info',
                                          text: data.message,
                                          type: 'info',
                                          styling: 'fontawesome'
                                      }
                                  );
                              }
                          }
                      }
                  );
              }
          );
  
6c8e3423   Yarik   Fast buy
236
  });
4bf9edb7   Yarik   Order
237
238
239
240
  function showLoader(container) {
      $(container)
          .prepend('<div class="loader-wrapper"><div class="loader"></div></div>');
  }