Blame view

frontend/web/js/script.js 12.3 KB
6ba3c88a   Alex Savenko   all
1
  $(function() {
3077487c   Виталий   New changelist2
2
      
38a9a9a6   Виталий   q
3
4
5
      clickMenuButton();
      openMobMenu();
      closeMobMenu();
535b9a3c   Виталий   q2
6
      addArrowMobMenuAndOpen();
51b67c0d   Виталий   commit2
7
      searchMob();
38a9a9a6   Виталий   q
8
9
10
11
12
13
  
      function clickMenuButton() {
          var menuButtonParent = $('.main-nav-item')
          menuButtonParent.find('.btn-like').click(function (e) {
              if(menuButtonParent.hasClass('home-page-menu')) {
                  e.preventDefault;
535b9a3c   Виталий   q2
14
                  $('body, html').animate({scrollTop:$('.dropdown-menu.sidebar').offset().top + 2},500)
38a9a9a6   Виталий   q
15
              } else {
535b9a3c   Виталий   q2
16
17
18
19
20
21
  
                  $('body').append('<div class="catalog-overlay"></div>')
                  $('.catalog-menu-wrapper-start').addClass('opened');
                  setTimeout(function () {
                      $('.catalog-menu-wrapper-start').addClass('visible_catalog')
                  },10)
38a9a9a6   Виталий   q
22
23
              }
          })
535b9a3c   Виталий   q2
24
25
26
27
28
29
  
          $('body').on('click','.catalog-overlay',function () {
             $(this).remove();
              $('.main-nav-item').removeClass('open');
              $('.catalog-menu-wrapper-start').removeClass('visible_catalog opened')
          })
38a9a9a6   Виталий   q
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
      }
  
  
  
      function mobOverlayAdd() {
          $('body').append('<div class="mob-overlay visible-xs visible-sm"></div>')
      }
      function mobOverlayRemove() {
          $('.mob-overlay').remove()
      }
  
      function openMobMenu() {
          $('.menu_mob').click(function () {
              mobOverlayAdd()
              $('body').addClass('off-scroll')
              $('#menu-mob-hidden').addClass('opens')
              setTimeout(function () {
                  $('#menu-mob-hidden').addClass('visible')
              },10)
          })
      }
  
      function closeMobMenu() {
          $('body').on('click','.mob-overlay',function () {
              mobOverlayRemove()
              if($('#menu-mob-hidden').hasClass('visible')) {
                  $('#menu-mob-hidden').removeClass('visible')
                  setTimeout(function () {
                      $('#menu-mob-hidden').removeClass('opens')
                  },200)
                  $('body').removeClass('off-scroll')
              }
              if($('.btn_call').hasClass('close')) {
                  $('.btn_call').removeClass('close')
                  closeCallMobileHide()
              }
  
          })
          $('.close-menu-mob .close_mob').click(function () {
              mobOverlayRemove()
              $('#menu-mob-hidden').removeClass('visible')
              setTimeout(function () {
                  $('#menu-mob-hidden').removeClass('opens')
              },200)
              $('body').removeClass('off-scroll')
              $('#menu-mob-hidden ul li.has_ul').removeClass('open')
          })
      }
  
      function closeCallMobileHide() {
          $('.call-mobile-wr').removeClass('visible')
          setTimeout(function () {
              $('.call-mobile-wr').removeClass('open')
          },200)
      }
  
535b9a3c   Виталий   q2
86
87
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
114
115
116
117
      function addArrowMobMenuAndOpen() {
          $('#menu-mob-hidden ul li').each(function () {
              if($(this).find('ul').length>0){
                  $(this).addClass('has_ul')
                  $(this).parent().addClass('sub_m')
                  $('#menu-mob-hidden>ul').removeClass('sub_m').addClass('sub_m-first');
              }
          })
  
  
  
          $('body').on('click','#menu-mob-hidden ul li.has_ul a',function () {
              if($(this).parent().parent().hasClass('sub_m')){  //если li элемент вложженый
                  if($(this).parent().hasClass('open')){
                      $(this).parent().removeClass('open')
                  } else {
                      $('.sub_m').find('.has_ul').removeClass('open')
                      $(this).parent().addClass('open')
                  }
              }
  
              if($(this).parent().parent().hasClass('sub_m-first')) {  //если ли родительский открываем/закрываем
                  if($(this).parent().hasClass('open')) {
                      $(this).parent().removeClass('open')
                      $(this).parent().find('.open').removeClass('open')
                  } else {
                      $(this).parent().addClass('open')
                  }
  
              }
  
          })
51b67c0d   Виталий   commit2
118
119
120
121
122
123
124
125
126
      }
      
      function searchMob() {
          $('.search_ico .fa').click(function () {
              $('.search-block').addClass('show_search');
          })
          $('.close_search_ico').click(function () {
              $('.search-block').removeClass('show_search');
          })
535b9a3c   Виталий   q2
127
      }
38a9a9a6   Виталий   q
128
129
130
131
132
133
134
135
  
  
  
  
  
  
  
  
6ba3c88a   Alex Savenko   all
136
137
138
139
140
141
142
143
144
145
146
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
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
      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');
                  }
              });
          })
          .on('submit', '#feedback-form', function(e) {
              e.preventDefault();
          });
  
      /**
       * 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() {
  
                  }
              });
          })
          .on('submit', '#contact-form', function(e) {
              e.preventDefault();
          });
  
      /**
       * 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');
                  } else {
                      $('#back-to-top')
                          .removeClass('show');
                  }
              };
          backToTop();
          $(window)
              .on('scroll', function() {
                  backToTop();
              });
          $('#back-to-top')
              .on('click', function(e) {
                  e.preventDefault();
                  $('html,body')
                      .animate({
                          scrollTop: 0
                      }, 700);
              });
      }
  
      $(document)
          .on('click', '.add-to-basket', function(e) {
              e.preventDefault();
              var id = $(this)
                  .data('id');
              var xhr = basket.add(id, 1);
              xhr.done(function() {
                  $.pjax.reload({
                      container: '#basket-modal',
                      fragment: '#basket-modal',
                      timeout: 5000
                  });
              });
              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);
              }
          });
  
      $(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
                  });
              })
          });
  
      $(document)
          .on('change', '.increase-product-basket', function(e) {
              var id = $(this)
                  .parents('.product-row-basket')
                  .data('id');
              showLoader('#basket');
              showLoader('#basket-modal');
              var xhr = basket.set(id, $(this)
                  .val());
              xhr.done(function() {
                  if ($('#basket').length) {
                      $.pjax.reload({
                          container: '#basket',
                          fragment: '#basket',
                          timeout: 5000
                      });
                  }
                  $.pjax.reload({
                      container: '#basket-modal',
                      fragment: '#basket-modal',
                      timeout: 5000
                  });
              });
          });
  
      $(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));
  
      $(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'
                                      }
                                  );
                              }
                          }
                      }
                  );
              }
          );
  
  });
  function showLoader(container) {
      $(container)
          .prepend('<div class="loader-wrapper"><div class="loader"></div></div>');
  }
  
  $(document).ready(function ($) {
      $('.vcovers').perfectScrollbar({wheelSpeed: 0.5});
  });