Commit 7d58328dfaa049e795287c4f34efee28c0f0121f
1 parent
dd593502
Exists in
staging
and in
42 other branches
ShoppingCartPlugin do not worry about page unload
Showing
1 changed file
with
17 additions
and
4 deletions
Show diff stats
plugins/shopping_cart/public/cart.js
| ... | ... | @@ -307,6 +307,11 @@ function Cart(config) { |
| 307 | 307 | $.colorbox.close(); |
| 308 | 308 | } |
| 309 | 309 | |
| 310 | + $(window).bind('beforeunload', function(){ | |
| 311 | + log('Page unload.'); | |
| 312 | + Cart.unloadingPage = true; | |
| 313 | + }); | |
| 314 | + | |
| 310 | 315 | $(function(){ |
| 311 | 316 | |
| 312 | 317 | $.ajax({ |
| ... | ... | @@ -318,10 +323,18 @@ function Cart(config) { |
| 318 | 323 | }, |
| 319 | 324 | cache: false, |
| 320 | 325 | error: function(ajax, status, errorThrown) { |
| 321 | - log.error('Error getting shopping cart - HTTP '+status, errorThrown); | |
| 322 | - if ( confirm(shoppingCartPluginL10n.getProblemConfirmReload) ) { | |
| 323 | - document.location.reload(); | |
| 324 | - } | |
| 326 | + // Give some time to register page unload. | |
| 327 | + setTimeout(function() { | |
| 328 | + // page unload is not our problem. | |
| 329 | + if (Cart.unloadingPage) { | |
| 330 | + log('Page unload before cart load.'); | |
| 331 | + } else { | |
| 332 | + log.error('Error getting shopping cart - HTTP '+status, errorThrown); | |
| 333 | + if ( confirm(shoppingCartPluginL10n.getProblemConfirmReload) ) { | |
| 334 | + document.location.reload(); | |
| 335 | + } | |
| 336 | + } | |
| 337 | + }, 100); | |
| 325 | 338 | } |
| 326 | 339 | }); |
| 327 | 340 | }); | ... | ... |