1/* 2** nopCommerce ajax cart implementation 3*/ 4 5 6var AjaxCart = { 7 loadWaiting: false, 8 usepopupnotifications: false, 9 topcartselector: '', 10 topwishlistselector: '', 11 flyoutcartselector: '', 12 13 init: function (usepopupnotifications, topcartselector, topwishlistselector, flyoutcartselector) { 14 this.loadWaiting = false; 15 this.usepopupnotifications = usepopupnotifications; 16 this.topcartselector = topcartselector; 17 this.topwishlistselector = topwishlistselector; 18 this.flyoutcartselector = flyoutcartselector; 19 }, 20 21 setLoadWaiting: function (display) { 22 displayAjaxLoading(display); 23 this.loadWaiting = display; 24 }, 25 26 //add a product to the cart/wishlist from the catalog pages 27 addproducttocart_catalog: function (urladd) { 28 if (this.loadWaiting != false) { 29 return; 30 } 31 this.setLoadWaiting(true); 32 33 $.ajax({ 34 cache: false, 35 url: urladd, 36 type: 'post', 37 success: this.success_process, 38 complete: this.resetLoadWaiting, 39 error: this.ajaxFailure 40 }); 41 }, 42 43 //add a product to the cart/wishlist from the product details page 44 addproducttocart_details: function (urladd, formselector) { 45 if (this.loadWaiting != false) { 46 return; 47 } 48 this.setLoadWaiting(true); 49 50 $.ajax({
51 cache: false, 52 url: urladd, 53 data: $(formselector).serialize(), 54 type: 'post', 55 success: this.success_process, 56 complete: this.resetLoadWaiting, 57 error: this.ajaxFailure 58 }); 59 }, 60 61 //add a product to compare list 62 addproducttocomparelist: function (urladd) { 63 if (this.loadWaiting != false) { 64 return; 65 } 66 this.setLoadWaiting(true); 67 68 $.ajax({ 69 cache: false, 70 url: urladd, 71 type: 'post', 72 success: this.success_process, 73 complete: this.resetLoadWaiting, 74 error: this.ajaxFailure 75 }); 76 }, 77 78 success_process: function (response) { 79 if (response.updatetopcartsectionhtml) { 80 $(AjaxCart.topcartselector).html(response.updatetopcartsectionhtml); 81 } 82 if (response.updatetopwishlistsectionhtml) { 83 $(AjaxCart.topwishlistselector).html(response.updatetopwishlistsectionhtml); 84 } 85 if (response.updateflyoutcartsectionhtml) { 86 $(AjaxCart.flyoutcartselector).replaceWith(response.updateflyoutcartsectionhtml); 87 } 88 if (response.message) { 89 //display notification 90 if (response.success == true) { 91 //success 92 if (AjaxCart.usepopupnotifications == true) { 93 displayPopupNotification(response.message, 'success', true); 94 } 95 else { 96 //specify timeout for success messages 97 displayBarNotification(response.message, 'success', 3500); 98 } 99 } 100 else { 101 //error 102 if (AjaxCart.usepopupnotifications == true) { 103 displayPopupNotification(response.message, 'error', true); 104 } 105 else { 106 //no timeout for errors 107 displayBarNotification(response.message, 'error', 0); 108 } 109 } 110 return false; 111 } 112 if (response.redirect) { 113 location.href = response.redirect; 114 return true; 115 } 116 return false; 117 }, 118 119 resetLoadWaiting: function () { 120 AjaxCart.setLoadWaiting(false); 121 }, 122 123 ajaxFailure: function () { 124 alert('Failed to add the product. Please refresh the page and try one more time.'); 125 } 126};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.