You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
911 B

5 years ago
  1. window.initPlusMinusBox = function () {
  2. /*----------------------------
  3. Cart Plus Minus Button
  4. ------------------------------ */
  5. var CartPlusMinus = $('.cart-plus-minus');
  6. CartPlusMinus.prepend('<div class="dec qtybutton">-</div>');
  7. CartPlusMinus.append('<div class="inc qtybutton">+</div>');
  8. $(".qtybutton").on("click", function () {
  9. var newVal;
  10. var $button = $(this);
  11. var oldValue = $button.parent().find("input").val();
  12. if ($button.text() === "+") {
  13. newVal = parseFloat(oldValue) + 1;
  14. } else {
  15. // Don't allow decrementing below zero
  16. if (oldValue > 0) {
  17. newVal = parseFloat(oldValue) - 1;
  18. } else {
  19. newVal = 1;
  20. }
  21. }
  22. $button.parent().find("input").val(newVal).request();
  23. });
  24. };
  25. (function ($) {
  26. initPlusMinusBox();
  27. })(jQuery);