$(function () { $('form.shipping').on('submit', function () { dataLayer.push({ 'event': 'shipping', 'ecommerce': { 'checkout': { 'actionField': { 'step': 2, 'option': $('input[name=shipping_rate]:checked', 'form.shipping').parent().find('label').text() } } } }); }); $('form.billing').on('submit', function () { dataLayer.push({ 'event': 'billing', 'ecommerce': { 'checkout': { 'actionField': { 'step': 3, 'option': $('input[name=payment_method]:checked', 'form.billing').val() } } } }); }); // Force reload for Safari back button $(window).bind("pageshow", function (event) { if (event.originalEvent.persisted) { window.location.reload() } }); if (typeof(Cart) !== "undefined" && Cart.settings._init == false) { var settings = {}; if ($('body').is('.wishlist')) { settings['form'] = '#wishlist'; } myCart = _.extend(Cart, {}); myCart.init(settings); } if (typeof(Crementor) !== "undefined" && Crementor.settings._init == false) { myCrementor = _.extend(Crementor, {}); myCrementor.init({}); } // (Optional) Cart login check toggle` $("body").on("click", "[data-check=login]", function () { var cartLogin = $("#cart-login"), container = ($(this).closest('.side-wrap').length > 0) ? $(".side-wrap") : $("body, html"); $('[data-check=login]').prop('disabled', true); cartLogin.slideDown(); $('html').addClass('cart-login--active'); container.animate({ scrollTop: cartLogin.offset().top }, 300); }); // Formaction support for IE < 10 // (does the same as it already should do for non-retard browsers) $('button[formaction]').on('click', function () { form = $(this).closest('form'); form.attr('action', $(this).attr('formaction')); form.submit(); return false; }); // Enter key intercept to differentiate between promo and login forms $('body').on('keypress', '#cart input', function (e) { if (e.which == 13) { e.preventDefault(); if (!$(this).parents('.promotions, #promotions').length) $("#cart_checkout_login").click(); else $(this).next().click(); } }); // Prevent multiple form submits $('body').on('submit', '#cart', function (e) { var form = $(this); if (form.data('submitted') === true) { return false; } // Mark form as submitted form.data('submitted', true); // Reset form setTimeout(function () { form.data('submitted', false) }, 1000); }); // Empty cart $('.btn-empty-cart').click(function(e) { e.preventDefault(); if(!window.confirm("Are you sure you want to empty your cart?")) return $.post('/cart/empty/', function(data) { if(!data.success) window.alert('Unable to clear cart!'); window.location.reload(); }); }) });