Blame view

js/new-basket.js 1.99 KB
f4ab266e   Виталий   qwerty
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
27
28
29
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
  $(document).ready(function() {
      modalForms();
      closeForms();
      function modalForms() {
          $('body').on('click', '.modal-link', function (e) {
              e.preventDefault();
  
  
  
              var idForm = $(this).data('form');
              var pos = ($(window).scrollTop()) + 30;
  
              if($(this).hasClass('pos-top')){
                  pos = 30;
              }
  
              $('#overlay').fadeIn(400,
                  function(){
                      $('#'+idForm).css('display', 'block').animate({opacity: 1, top: pos}, 200);
                  }
              );
          })
      }
  
  
      function closeForms() {
          $('#modal_close, #overlay, .close-basket, .basket-close').click( function(){
              $('.forms_, .new-basket-modal').animate({opacity: 0, top: '0'}, 200,function(){
                  $(this).css('display', 'none');
                  $(this).prev("#overlay").css('display', 'none');
                  $('#overlay').fadeOut(400);
              });
              $('#success_form').animate({opacity: 0, top: '0'}, 200,function(){
                  $(this).css('display', 'none');
                  $(this).prev("#overlay").css('display', 'none');
                  $(this).css({top:'50%'});
              });
          });
      }
  
      $(document).on('click', '.quantity-wr span', changeBasket);
      $(document).on('keypress', '.quantity-wr input', setControl);
  
      function changeBasket(e) {
          e.preventDefault();
  
          var input = $(this).parent().parent().find('input');
          var oldVal = input.val();
          console.log(oldVal)
          if ($(this).hasClass('minus')) {
  
              if (oldVal > 1) {
                  oldVal--;
                  input.val(oldVal);
              }
          } else {
              oldVal++;
              input.val(oldVal);
  
          }
      }
      function setControl(e) {
          if (e.which == 13) {
              $(this)
                  .trigger('change');
              return false;
          } else if (!(e.which == 8 || (e.which > 47 && e.which < 58))) {
              return false;
          }
      }
  })