From 7d58328dfaa049e795287c4f34efee28c0f0121f Mon Sep 17 00:00:00 2001 From: Aurélio A. Heckert Date: Mon, 25 Mar 2013 14:35:34 -0300 Subject: [PATCH] ShoppingCartPlugin do not worry about page unload --- plugins/shopping_cart/public/cart.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/plugins/shopping_cart/public/cart.js b/plugins/shopping_cart/public/cart.js index 0016215..b6ae075 100644 --- a/plugins/shopping_cart/public/cart.js +++ b/plugins/shopping_cart/public/cart.js @@ -307,6 +307,11 @@ function Cart(config) { $.colorbox.close(); } + $(window).bind('beforeunload', function(){ + log('Page unload.'); + Cart.unloadingPage = true; + }); + $(function(){ $.ajax({ @@ -318,10 +323,18 @@ function Cart(config) { }, cache: false, error: function(ajax, status, errorThrown) { - log.error('Error getting shopping cart - HTTP '+status, errorThrown); - if ( confirm(shoppingCartPluginL10n.getProblemConfirmReload) ) { - document.location.reload(); - } + // Give some time to register page unload. + setTimeout(function() { + // page unload is not our problem. + if (Cart.unloadingPage) { + log('Page unload before cart load.'); + } else { + log.error('Error getting shopping cart - HTTP '+status, errorThrown); + if ( confirm(shoppingCartPluginL10n.getProblemConfirmReload) ) { + document.location.reload(); + } + } + }, 100); } }); }); -- libgit2 0.21.2