'; $('#cartDrawerError').append(errorMsg); $("#CartDrawer .cart-drawer-content").animate({ scrollTop: 0 }); }else{ theme.cartDrawer(data); } $('#CartDrawer #hasCartItem').removeClass('is-loading'); }, error: function(XMLHttpRequest, textStatus) { location.reload(); } }); } function debounce(func, wait, immediate) { var timeout; return function() { var context = this, args = arguments; var later = function() { timeout = null; if (!immediate) func.apply(context, args); }; var callNow = immediate && !timeout; clearTimeout(timeout); timeout = setTimeout(later, wait); if (callNow) func.apply(context, args); }; }; $('body').on("change", '#CartDrawer input.cart__quantity-selector', function (){ theme.updateCartDrawer(); }); $('#updateCartDrawer').click(function() { theme.updateCartDrawer(); }); $('body').on("click", ".btn-qty-adjust", function() { var $button = $(this); var oldValue = $button.parent().find("input.cart__quantity-selector").val(); if ($button.attr('data-adjust') == 1) { var newVal = parseFloat(oldValue) + 1; } else { // Don't allow decrementing below zero if (oldValue > 0) { var newVal = parseFloat(oldValue) - 1; } else { newVal = 0; } } $button.parent().find("input").val(newVal); }); $('body').on("click", ".btn-qty-adjust", debounce(function() { theme.updateCartDrawer(); },350)); $('button.checkout').click(function() { $(this).addClass('btn--loading'); }); function popToast(content) { var x = document.getElementById("toast"), y = document.getElementById("toastContent"); y.innerHTML = content; x.className += " show"; var hideToast = setTimeout(function(){ x.className = x.className.replace(" show", ""); }, 3000); }