Blame view

frontend/web/js/script.js 12 KB
6c8e3423   Yarik   Fast buy
1
2
3
4
  $(function() {
      var basket = new ArtboxBasket({
          'cartSelector': '#cart'
      });
ca6ee397   Eugeny Galkovskiy   Скролл на миниатюрах
5
  
6c8e3423   Yarik   Fast buy
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
      /**
       * 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
28
                  }
6c8e3423   Yarik   Fast buy
29
30
31
32
33
              });
          })
          .on('submit', '#feedback-form', function(e) {
              e.preventDefault();
          });
657a0f05   Alexey Boroda   -Button up
34
  
6c8e3423   Yarik   Fast buy
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
      /**
       * 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
52
  
83309611   Alexey Boroda   -Map in process
53
                  }
6c8e3423   Yarik   Fast buy
54
55
56
57
58
              });
          })
          .on('submit', '#contact-form', function(e) {
              e.preventDefault();
          });
4bf9edb7   Yarik   Order
59
  
6c8e3423   Yarik   Fast buy
60
61
62
63
64
65
66
67
68
69
70
      /**
       * 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   уведомление о доб...
71
                  } else {
6c8e3423   Yarik   Fast buy
72
73
                      $('#back-to-top')
                          .removeClass('show');
7f57ad53   Eugeny Galkovskiy   уведомление о доб...
74
                  }
6c8e3423   Yarik   Fast buy
75
76
77
78
79
              };
          backToTop();
          $(window)
              .on('scroll', function() {
                  backToTop();
4bf9edb7   Yarik   Order
80
              });
6c8e3423   Yarik   Fast buy
81
82
          $('#back-to-top')
              .on('click', function(e) {
4bf9edb7   Yarik   Order
83
                  e.preventDefault();
6c8e3423   Yarik   Fast buy
84
85
86
87
                  $('html,body')
                      .animate({
                          scrollTop: 0
                      }, 700);
4bf9edb7   Yarik   Order
88
              });
6c8e3423   Yarik   Fast buy
89
90
91
92
93
94
95
      }
  
      $(document)
          .on('click', '.add-to-basket', function(e) {
              e.preventDefault();
              var id = $(this)
                  .data('id');
fc66ded4   Yarik   Artbox great prep...
96
97
98
99
100
101
102
103
              var xhr = basket.add(id, 1);
              xhr.done(function() {
                  $.pjax.reload({
                      container: '#basket-modal',
                      fragment: '#basket-modal',
                      timeout: 5000
                  });
              });
6c8e3423   Yarik   Fast buy
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
              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
122
  
6c8e3423   Yarik   Fast buy
123
124
125
126
127
128
129
130
131
132
133
134
135
      $(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
136
                  });
6c8e3423   Yarik   Fast buy
137
138
              })
          });
4bf9edb7   Yarik   Order
139
  
6c8e3423   Yarik   Fast buy
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');
fc66ded4   Yarik   Artbox great prep...
146
              showLoader('#basket-modal');
6c8e3423   Yarik   Fast buy
147
148
149
              var xhr = basket.set(id, $(this)
                  .val());
              xhr.done(function() {
fc66ded4   Yarik   Artbox great prep...
150
151
152
153
154
155
156
                  if ($('#basket').length) {
                      $.pjax.reload({
                          container: '#basket',
                          fragment: '#basket',
                          timeout: 5000
                      });
                  }
6c8e3423   Yarik   Fast buy
157
                  $.pjax.reload({
fc66ded4   Yarik   Artbox great prep...
158
159
                      container: '#basket-modal',
                      fragment: '#basket-modal',
6c8e3423   Yarik   Fast buy
160
161
                      timeout: 5000
                  });
4bf9edb7   Yarik   Order
162
              });
6c8e3423   Yarik   Fast buy
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
          });
  
      $(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
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
      $(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'
                                      }
                                  );
                              }
                          }
                      }
                  );
              }
          );
7ea39d3b   Eugeny Galkovskiy   Сортировка
251
      $(document).on('click', '.sort-cat>a', function(e){
b3c01813   Eugeny Galkovskiy   Вёрстка сортировк...
252
253
254
255
256
257
258
259
260
          $(this).parent().toggleClass("active");
          return false;
      });
      $(document).on('click', '.sorter li a', function(e){
          var sortclick   =   $(this).text();
              parentsort  =   $(".sort-cat a span");
              pstext      =   $(parentsort).text();
              mainlink    =   $(".sort-cat a").attr('href');
              newmainlink =   $(this).attr('href');
b31541f7   Eugeny Galkovskiy   Сортировка
261
  
b3c01813   Eugeny Galkovskiy   Вёрстка сортировк...
262
          $(parentsort).text(sortclick);
b31541f7   Eugeny Galkovskiy   Сортировка
263
          $(".sort-cat>a").attr('href', newmainlink);
b3c01813   Eugeny Galkovskiy   Вёрстка сортировк...
264
265
          $(this).text(pstext);
          $(this).attr('href', mainlink);
7ea39d3b   Eugeny Galkovskiy   Сортировка
266
          $(".sort-cat>a").click();
b31541f7   Eugeny Galkovskiy   Сортировка
267
268
269
  
          $(location).attr('href',newmainlink);
          return false;
b3c01813   Eugeny Galkovskiy   Вёрстка сортировк...
270
      });
ac6e2c67   Alexey Boroda   -Cabinet ready
271
  
de8261de   Yarik   Price filter
272
273
274
275
276
277
278
      // Price slider
      $('.price-inputs input')
          .keypress(function(key) {
              if (key.charCode < 48 || key.charCode > 57) {
                  return false;
              }
          });
5a24921e   Eugeny Galkovskiy   Бегунок цены
279
  
de8261de   Yarik   Price filter
280
281
282
283
284
285
286
287
288
      var priceSlider = $(".price_slider input");
      var pricemin = priceSlider.data("pricemin");
      var pricemax = priceSlider.data("pricemax");
      var currentMin = priceSlider.data("currentmin");
      var currentMax = priceSlider.data("currentmax");
      $(".price-inputs #price-min")
          .val(currentMin);
      $(".price-inputs #price-max")
          .val(currentMax);
dc92126e   Eugeny Galkovskiy   Бегунок цены
289
  
de8261de   Yarik   Price filter
290
291
292
293
294
295
296
297
298
299
300
301
302
303
      $("#price_interval")
          .ionRangeSlider({
              type: "double",
              min: pricemin,
              max: pricemax,
              from: currentMin,
              to: currentMax,
              onChange: function(data) {
                  $(".price-inputs #price-min")
                      .val(data.from);
                  $(".price-inputs #price-max")
                      .val(data.to);
              }
          });
dc92126e   Eugeny Galkovskiy   Бегунок цены
304
  
de8261de   Yarik   Price filter
305
306
      var slider = $("#price_interval")
          .data("ionRangeSlider");
dc92126e   Eugeny Galkovskiy   Бегунок цены
307
  
de8261de   Yarik   Price filter
308
309
310
311
312
313
314
      $(document)
          .on('change', '.price-inputs #price-min', function() {
              var newmin = $(this)
                  .val();
              currentmax = $(".price-inputs #price-max")
                  .val();
              if (newmin > currentmax) {
5a24921e   Eugeny Galkovskiy   Бегунок цены
315
                  newmin = currentmax;
de8261de   Yarik   Price filter
316
317
318
                  $('.price-inputs #price-min')
                      .val(currentmax);
              } else if (newmin > pricemax) {
5a24921e   Eugeny Galkovskiy   Бегунок цены
319
                  newmin = pricemax;
de8261de   Yarik   Price filter
320
321
                  $('.price-inputs #price-min')
                      .val(pricemax);
5a24921e   Eugeny Galkovskiy   Бегунок цены
322
              }
de8261de   Yarik   Price filter
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
              slider.update({from: newmin});
          });
      $(document)
          .on('change', '.price-inputs #price-max', function() {
              var newmax = $(this)
                  .val();
              currentmin = $(".price-inputs #price-min")
                  .val();
              if (newmax < currentmin) {
                  newmax = currentmin;
                  $('.price-inputs #price-max')
                      .val(currentmin);
              } else if (newmax > pricemax) {
                  newmax = pricemax;
                  $('.price-inputs #price-max')
                      .val(pricemax);
              }
              slider.update({to: newmax});
          });
      $(document)
          .on('click', '.price-apply', function() {
              var max = $('#price-max')
                  .val();
              var min = $('#price-min')
                  .val();
              console.log(max, min);
              var href = window.location.href;
54f69b92   Yarik   Price filter fix
350
351
352
353
354
              var question = href.indexOf('?');
              if (question !== -1) {
                  var queryString = href.substr(question);
                  href = href.substr(0, question);
              }
de8261de   Yarik   Price filter
355
356
357
358
359
360
              var count = 0;
              var pos = -1;
              while ((pos = href.indexOf('/', pos + 1)) !== -1) {
                  count++;
              }
              if (count === 5) {
54f69b92   Yarik   Price filter fix
361
                  window.location.href = href + '/price-' + min + '-' + max + queryString;
de8261de   Yarik   Price filter
362
              } else {
54f69b92   Yarik   Price filter fix
363
                  var result = href.match(/\/[^\/]*price-(\d+)-(\d+)$/);
de8261de   Yarik   Price filter
364
                  if (result) {
54f69b92   Yarik   Price filter fix
365
                      window.location.href = href.replace(/(\/[^\/]*)price-\d+-\d+$/, '$1price-' + min + '-' + max) + queryString;
de8261de   Yarik   Price filter
366
367
368
369
370
371
372
373
                  }
              }
          });
      // End of price slider
  
      $('.vcovers')
          .perfectScrollbar({wheelSpeed: 0.5});
  
dc92126e   Eugeny Galkovskiy   Бегунок цены
374
  });
de8261de   Yarik   Price filter
375
376
377
378
  function showLoader(container) {
      $(container)
          .prepend('<div class="loader-wrapper"><div class="loader"></div></div>');
  }