Blame view

frontend/web/js/script.js 12.4 KB
6c8e3423   Yarik   Fast buy
1
2
3
4
  $(function() {
      var basket = new ArtboxBasket({
          'cartSelector': '#cart'
      });
6c8e3423   Yarik   Fast buy
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
      /**
       * 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
      }
  
      $(document)
          .on('click', '.add-to-basket', function(e) {
              e.preventDefault();
              var id = $(this)
                  .data('id');
fc66ded4   Yarik   Artbox great prep...
95
96
97
98
99
100
101
102
              var xhr = basket.add(id, 1);
              xhr.done(function() {
                  $.pjax.reload({
                      container: '#basket-modal',
                      fragment: '#basket-modal',
                      timeout: 5000
                  });
              });
6c8e3423   Yarik   Fast buy
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
              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
121
  
6c8e3423   Yarik   Fast buy
122
123
124
125
126
127
128
129
130
131
132
133
134
      $(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
135
                  });
6c8e3423   Yarik   Fast buy
136
137
              })
          });
4bf9edb7   Yarik   Order
138
  
6c8e3423   Yarik   Fast buy
139
140
141
142
143
144
      $(document)
          .on('change', '.increase-product-basket', function(e) {
              var id = $(this)
                  .parents('.product-row-basket')
                  .data('id');
              showLoader('#basket');
fc66ded4   Yarik   Artbox great prep...
145
              showLoader('#basket-modal');
6c8e3423   Yarik   Fast buy
146
147
148
              var xhr = basket.set(id, $(this)
                  .val());
              xhr.done(function() {
fc66ded4   Yarik   Artbox great prep...
149
150
151
152
153
154
155
                  if ($('#basket').length) {
                      $.pjax.reload({
                          container: '#basket',
                          fragment: '#basket',
                          timeout: 5000
                      });
                  }
6c8e3423   Yarik   Fast buy
156
                  $.pjax.reload({
fc66ded4   Yarik   Artbox great prep...
157
158
                      container: '#basket-modal',
                      fragment: '#basket-modal',
6c8e3423   Yarik   Fast buy
159
160
                      timeout: 5000
                  });
4bf9edb7   Yarik   Order
161
              });
6c8e3423   Yarik   Fast buy
162
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
          });
  
      $(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
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
      $(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   Сортировка
250
      $(document).on('click', '.sort-cat>a', function(e){
b3c01813   Eugeny Galkovskiy   Вёрстка сортировк...
251
252
253
254
255
256
257
258
259
          $(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   Сортировка
260
  
b3c01813   Eugeny Galkovskiy   Вёрстка сортировк...
261
          $(parentsort).text(sortclick);
b31541f7   Eugeny Galkovskiy   Сортировка
262
          $(".sort-cat>a").attr('href', newmainlink);
b3c01813   Eugeny Galkovskiy   Вёрстка сортировк...
263
264
          $(this).text(pstext);
          $(this).attr('href', mainlink);
7ea39d3b   Eugeny Galkovskiy   Сортировка
265
          $(".sort-cat>a").click();
b31541f7   Eugeny Galkovskiy   Сортировка
266
267
268
  
          $(location).attr('href',newmainlink);
          return false;
b3c01813   Eugeny Galkovskiy   Вёрстка сортировк...
269
      });
ac6e2c67   Alexey Boroda   -Cabinet ready
270
  
de8261de   Yarik   Price filter
271
272
273
274
275
276
277
      // Price slider
      $('.price-inputs input')
          .keypress(function(key) {
              if (key.charCode < 48 || key.charCode > 57) {
                  return false;
              }
          });
5a24921e   Eugeny Galkovskiy   Бегунок цены
278
  
de8261de   Yarik   Price filter
279
280
281
282
283
284
285
286
287
      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   Бегунок цены
288
  
de8261de   Yarik   Price filter
289
290
291
292
293
294
295
296
297
298
299
300
301
302
      $("#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   Бегунок цены
303
  
de8261de   Yarik   Price filter
304
305
      var slider = $("#price_interval")
          .data("ionRangeSlider");
dc92126e   Eugeny Galkovskiy   Бегунок цены
306
  
de8261de   Yarik   Price filter
307
308
309
310
311
312
313
      $(document)
          .on('change', '.price-inputs #price-min', function() {
              var newmin = $(this)
                  .val();
              currentmax = $(".price-inputs #price-max")
                  .val();
              if (newmin > currentmax) {
5a24921e   Eugeny Galkovskiy   Бегунок цены
314
                  newmin = currentmax;
de8261de   Yarik   Price filter
315
316
317
                  $('.price-inputs #price-min')
                      .val(currentmax);
              } else if (newmin > pricemax) {
5a24921e   Eugeny Galkovskiy   Бегунок цены
318
                  newmin = pricemax;
de8261de   Yarik   Price filter
319
320
                  $('.price-inputs #price-min')
                      .val(pricemax);
5a24921e   Eugeny Galkovskiy   Бегунок цены
321
              }
de8261de   Yarik   Price filter
322
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
              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
349
              var question = href.indexOf('?');
040c92b7   Yarik   Price filter fix
350
              var queryString = '';
54f69b92   Yarik   Price filter fix
351
              if (question !== -1) {
040c92b7   Yarik   Price filter fix
352
                  queryString = href.substr(question);
54f69b92   Yarik   Price filter fix
353
354
                  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});
  
a227a1f0   Eugeny Galkovskiy   Скрытые фильтры в...
374
375
376
377
378
379
380
381
      $(document).on('click', '.sidebar-menu .form-group .hiddens-button a.btn', function(){
          $(this).parent().parent().find(".hiddens").toggleClass("active");
          $(this).text(function(i, text){
              return text === "Ещё" ? "Скрыть" : "Ещё";
          });
          return false;
      });
  
dc92126e   Eugeny Galkovskiy   Бегунок цены
382
  });
de8261de   Yarik   Price filter
383
384
385
386
  function showLoader(container) {
      $(container)
          .prepend('<div class="loader-wrapper"><div class="loader"></div></div>');
  }