1/* 2** nopCommerce ajax cart implementation 3*/ 4 5 6var AjaxCart = { 7 loadWaiting: false, 8 usepopupnotifications: false, 9 topcartselector: '', 10 topwishlistselector: '', 11 flyoutcartselector: '', 12 localized_data: false, 13 14 init: function (usepopupnotifications, topcartselector, topwishlistselector, flyoutcartselector, localized_data) { 15 this.loadWaiting = false; 16 this.usepopupnotifications = usepopupnotifications; 17 this.topcartselector = topcartselector; 18 this.topwishlistselector = topwishlistselector; 19 this.flyoutcartselector = flyoutcartselector; 20 this.localized_data = localized_data; 21 }, 22 23 setLoadWaiting: function (display) { 24 displayAjaxLoading(display); 25 this.loadWaiting = display; 26 }, 27 28 //move a shopping cart item to the custom wishlist 29 moveToCustomWishlist: function (urlmove, itemId, wishlistId) { 30 if (this.loadWaiting !== false) { 31 return; 32 } 33 this.setLoadWaiting(true); 34 35 var postData = { 36 shoppingCartItemId: itemId, 37 customWishlistId: wishlistId 38 }; 39 addAntiForgeryToken(postData); 40 41 this.send_ajax(urlmove, postData); 42 }, 43 44 //create custom wishlist 45 createCustomWishlist: function (urlcreate, wishlistName, productId) { 46 if (this.loadWaiting !== false) { 47 return; 48 } 49 this.setLoadWaiting(true); 50 51 var postData = { 52 name: wishlistName, 53 productId: productId 54 }; 55 addAntiForgeryToken(postData); 56 57 this.send_ajax(urlcreate, postData); 58 }, 59 60 //delete custom wishlist 61 deleteCustomWishlist: function (urldelete) { 62 if (this.loadWaiting !== false) { 63 return; 64 } 65 this.setLoadWaiting(true); 66 67 var postData = {}; 68 addAntiForgeryToken(postData); 69 70 this.send_ajax(urldelete, postData); 71 }, 72 73 //move a product to the custom wishlist from the default wishlist 74 moveproducttowishlist: function (urlmove, wishlistid) { 75 if (this.loadWaiting !== false) { 76 return; 77 } 78 this.setLoadWaiting(true); 79 var postData = { 80 wishlistId: wishlistid 81 }; 82 addAntiForgeryToken(postData); 83 84 this.send_ajax(urlmove, postData); 85 }, 86 87 //add a product to the cart/wishlist from the catalog pages 88 addproducttocart_catalog: function (urladd) { 89 if (this.loadWaiting !== false) { 90 return; 91 } 92 this.setLoadWaiting(true); 93 94 var postData = {}; 95 addAntiForgeryToken(postData); 96 97 this.send_ajax(urladd, postData); 98 }, 99 100 //add a product to the cart/wishlist from the product details page 101 addproducttocart_details: function (urladd, formselector) { 102 if (this.loadWaiting !== false) { 103 return; 104 } 105 this.setLoadWaiting(true); 106 107 this.send_ajax(urladd, $(formselector).serialize()); 108 }, 109 110 //add a product to compare list 111 addproducttocomparelist: function (urladd) { 112 if (this.loadWaiting !== false) { 113 return; 114 } 115 this.setLoadWaiting(true); 116 117 var postData = {}; 118 addAntiForgeryToken(postData); 119 120 this.send_ajax(urladd, postData); 121 }, 122 123 send_ajax: function (requestUrl, postData) { 124 $.ajax({
125 cache: false, 126 url: requestUrl, 127 type: "POST", 128 data: postData, 129 success: this.success_process, 130 complete: this.resetLoadWaiting, 131 error: this.ajaxFailure 132 }); 133 }, 134 135 success_process: function (response) { 136 if (response.updatetopcartsectionhtml) { 137 $(AjaxCart.topcartselector).html(response.updatetopcartsectionhtml); 138 } 139 if (response.updatetopwishlistsectionhtml) { 140 $(AjaxCart.topwishlistselector).html(response.updatetopwishlistsectionhtml); 141 } 142 if (response.updateflyoutcartsectionhtml) { 143 $(AjaxCart.flyoutcartselector).replaceWith(response.updateflyoutcartsectionhtml); 144 } 145 if (response.message) { 146 //display notification 147 if (response.success === true) { 148 //success 149 if (AjaxCart.usepopupnotifications === true) { 150 displayPopupNotification(response.message, 'success', true); 151 } 152 else { 153 //specify timeout for success messages 154 displayBarNotification(response.message, 'success', 3500); 155 } 156 } 157 else { 158 //error 159 if (AjaxCart.usepopupnotifications === true) { 160 displayPopupNotification(response.message, 'error', true); 161 } 162 else { 163 //no timeout for errors 164 displayBarNotification(response.message, 'error', 0); 165 } 166 } 167 return false; 168 } 169 if (response.redirect) { 170 location.href = response.redirect; 171 return true; 172 } 173 return false; 174 }, 175 176 resetLoadWaiting: function () { 177 AjaxCart.setLoadWaiting(false); 178 }, 179 180 ajaxFailure: function () { 181 alert(this.localized_data.AjaxCartFailure); 182 } 183};
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.