Igor150195

amount 2.2.87

May 13th, 2020
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. shop2.queue.amount = function() {
  2.  
  3. var $document = $(document);
  4.  
  5. function validate(input) {
  6. var kind = input.data('kind'),
  7. max = input.data('max'),
  8. val = Number(input.val()),
  9. amount = 0,
  10. available;
  11.  
  12. if (kind && max > 0) {
  13. $('input[data-kind=' + kind + ']').each(function() {
  14. amount += Number(this.value);
  15. });
  16.  
  17. if (amount > max) {
  18. available = max - amount + val;
  19. input.val(available);
  20. shop2.msg(_s3Lang.JS_AVAILABLE_ONLY + ' ' + available, input);
  21. }
  22. }
  23. }
  24.  
  25. $document.on('click', '.amount-minus', function() {
  26. var $this = $(this),
  27. text = $this.parents('.shop2-product-amount').find('input:text'),
  28. value = text.getVal();
  29.  
  30. if (value) {
  31. value = value[0];
  32. }
  33. value -= shop2.options.amountDefaultInc;
  34. value = value.toFixed(5) - 0;
  35.  
  36. if (value <= shop2.options.amountDefaultValue) {
  37. value = shop2.options.amountDefaultValue;
  38. }
  39.  
  40. text.val(value);
  41. text.trigger('keyup');
  42. });
  43.  
  44. $document.on('click', '.amount-plus', function() {
  45.  
  46. var $this = $(this),
  47. text = $this.parents('.shop2-product-amount').find('input:text'),
  48. value = text.getVal();
  49.  
  50. if (value) {
  51. value = value[0];
  52. }
  53.  
  54. value += shop2.options.amountDefaultInc;
  55. value = value.toFixed(5) - 0;
  56.  
  57. text.val(value);
  58. text.trigger('keyup');
  59. });
  60.  
  61. $document.on('keyup', '.shop2-product-amount input:text', function() {
  62. var $this = $(this);
  63. validate($this);
  64. });
  65.  
  66. $document.keyFilter('.shop2-product-amount input:text', {
  67. type: shop2.options.amountType
  68. });
  69. },
Add Comment
Please, Sign In to add comment