Igor150195

Кол-во с работающей кратностью

May 4th, 2020
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function amountInit() {
  2.     $(".cart-products__item, .shop2-product-item, .shop2-product, .kind-item, .popup-product").each(function() {
  3.         var $this       = $(this);
  4.         var $amountWrap = $this.find(".shop2-product-amount");
  5.         var $input      = $amountWrap.find('input[type="text"]');
  6.         var $buttons    = $amountWrap.find("button");
  7.         var $minus      = $amountWrap.find("button.amount-minus");
  8.         var $plus       = $amountWrap.find("button.amount-plus");
  9.         var min         = $amountWrap.find('input').data('min');
  10.         var inputVal    = +$input.val();
  11.        
  12.  
  13.         if (inputVal<=min) {
  14.             $minus.attr("disabled", "disabled");
  15.         }
  16.        
  17.         $buttons.on("click", function(){
  18.             var parent = $(this).parent();
  19.             var input  = parent.find("input");
  20.  
  21.             setTimeout(function(){
  22.                 var inputVal = +input.val();
  23.                
  24.                 if (inputVal<=min) {
  25.                     $minus.attr("disabled", "disabled");
  26.                 } else {
  27.                     $minus.removeAttr("disabled");
  28.                 }
  29.             }, 100);
  30.         });
  31.        
  32.         $input.on("change", function(e) {
  33.             var curVal = +$(this).val();
  34.            
  35.             if (curVal < min) {
  36.                 $(this).val(min);
  37.             } else if (curVal == min) {
  38.                 $minus.attr("disabled", "disabled");
  39.             } else if (curVal > min) {
  40.                 $minus.removeAttr("disabled");
  41.             }
  42.         });
  43.     });
  44. };
Add Comment
Please, Sign In to add comment