1/* global $, prestashop */ 2 3/** 4 * This module exposes an extension point in the form of the `showModal` function. 5 * 6 * If you want to override the way the modal window is displayed, simply define: 7 * 8 * prestashop.blockcart = prestashop.blockcart || {}; 9 * prestashop.blockcart.showModal = function myOwnShowModal (modalHTML) { 10 * // your own code 11 * // please not that it is your responsibility to handle closing the modal too 12 * }; 13 * 14 * Attention: your "override" JS needs to be included **before** this file. 15 * The safest way to do so is to place your "override" inside the theme's main JS file. 16 * 17 */ 18 19$(document).ready(function () { 20 21 var promises = []; 22 var abortPreviousRequests = function() { 23 var promise; 24 while (promises.length > 0) { 25 promise = promises.pop(); 26 promise.abort(); 27 } 28 }; 29 30 31 /*prestashop.blockcart = prestashop.blockcart || {}; 32 33 var showModal = prestashop.blockcart.showModal || function (modal, updateornot) { 34 //no need to replace the same code here /_dev/js/block-cart.js 35 };*/ 36 37 $('body').on('click', '.ajax_add_to_cart_button', function (event) { 38 event.preventDefault(); 39 if(!$(this).data('id-product') || $(this).prop('disabled') == 'disabled') 40 return false; 41 if($(this).hasClass('st_maximum_already')) 42 { 43 alert(st_maximum_already_message); 44 return false; 45 } 46 var caller_element = this; 47 var query = 'id_product=' + $(this).data('id-product') + '&add=1&action=update&token='+prestashop.static_token+'&rand=' + new Date().getTime(); 48 var actionURL = prestashop.urls.pages.cart; 49 // 50 $(this).prop('disabled', 'disabled').addClass('active'); 51 52 if($(this).data('id-product-attribute')) 53 query += '&ipa='+$(this).data('id-product-attribute'); 54 // 55 var qty = $(this).data('minimal-quantity') ? $(this).data('minimal-quantity') : 1; 56 var quantity_wanted = $(this).closest('.ajax_block_product').find('input[name=pro_quantity]').val(); 57 if (!quantity_wanted) 58 quantity_wanted = 1; 59 query += '&qty='+(quantity_wanted>qty ? quantity_wanted : qty); 60 // 61 62 $.post(actionURL, query, null, 'json').then(function(resp) { 63 prestashop.emit('stUpdateCart', { 64 reason: { 65 idProduct: resp.id_product, 66 idProductAttribute: resp.id_product_attribute, 67 linkAction: 'add-to-cart', 68 updateornot: false, 69 caller_element: caller_element 70 }, 71 resp: resp 72 }); 73 }).fail(function(resp) { 74 $(caller_element).removeProp('disabled').removeClass('active'); 75 prestashop.emit('handleError', {eventType: 'addProductToCart', resp: resp}); 76 }); 77 return false; 78 }); 79 //Add a active to the add to cart button on the product page. Looking for a better way 80 //to unable to stop the button being clicking for several times. 81 $('body').on( 82 'click', 83 '[data-button-action="add-to-cart"]', 84 function(event) { 85 event.preventDefault(); 86 var _target = $(event.target); 87 if(!_target.hasClass('btn')) 88 _target = _target.closest('.btn'); 89 _target.prop('disabled', 'disabled').addClass('active'); 90 } 91 ); 92 93 prestashop.on( 94 'stUpdateCart', 95 st_update_cart 96 ); 97 //this is for the product page, a updateCart listener in the core/cart.js should not be triggered if not in the shopping cart page. 98 prestashop.on( 99 'updateCart', 100 st_update_cart 101 ); 102 $('body').on( 103 'click', 104 '.ajax_remove_button', 105 function(event){ 106 event.preventDefault(); 107 var cartAction = { 108 url: $(this).attr('href').replace(/^https?:/, ''), 109 type: 'deleteFromCart' // 110 }; 111 var requestData = { 112 ajax: '1', 113 action: 'update' 114 }; 115 116 abortPreviousRequests(); 117 $.ajax({ 118 url: cartAction.url, 119 method: 'POST', 120 data: requestData, 121 dataType: 'json', 122 beforeSend: function (jqXHR) { 123 promises.push(jqXHR); 124 } 125 }).then(function (resp) { 126 // Refresh cart preview
127 prestashop.emit('stUpdateCart', { 128 reason: { 129 idProduct: resp.id_product, 130 idProductAttribute: resp.id_product_attribute, 131 linkAction: 'delete-from-cart', 132 updateornot: false 133 }, 134 resp: resp 135 }); 136 137 if ($('body.product-id-'+resp.id_product).length)//if the removed product is the current page 138 prestashop.emit('updateProduct', { 139 reason: {},eventType: 'updatedProductCombination',event: null 140 }); 141 142 if(typeof(prestashop.page.page_name)!=='undefined' && (prestashop.page.page_name=='cart' || prestashop.page.page_name=='module-steasycheckout-default'))//zai shopping cart page 143 prestashop.emit('updateCart', { 144 reason: { 145 idProduct: resp.id_product, 146 idProductAttribute: resp.id_product_attribute 147 }, 148 resp: resp 149 }); 150 151 }).fail(function(resp) { 152 prestashop.emit('handleError', { 153 eventType: 'updateProductInCart', 154 resp: resp, 155 cartAction: cartAction.type 156 }); 157 }); 158 }); 159 /*$('.cart_quantity').on('touchspin.on.startdownspin', handleCartAction); 160 $('.cart_quantity').on('touchspin.on.startupspin', handleCartAction); 161 $body.on( 162 'focusout', 163 '.cart_quantity', 164 (event) => { 165 updateProductQuantityInCart(event); 166 } 167 ); 168 $body.on( 169 'keyup', 170 '.cart_quantity', 171 (event) => { 172 if (event.keyCode == 13) { 173 updateProductQuantityInCart(event); 174 } 175 } 176 ); 177*/ 178}); 179/* 180 var st_create_spin = function() 181 { 182 $.each($('.cart_quantity'), function (index, spinner) { 183 $(spinner).TouchSpin({ 184 verticalbuttons: !sttheme.is_mobile_device, 185 verticalupclass: 'fto-plus-2', 186 verticaldownclass: 'fto-minus', 187 buttondown_class: 'btn btn-touchspin js-touchspin js-increase-product-quantity', 188 buttonup_class: 'btn btn-touchspin js-touchspin js-decrease-product-quantity', 189 min: parseInt($(spinner).data('minimal-quantity'), 10), 190 max: 1000000 191 }); 192 }); 193 }; 194*/ 195 var st_update_cart = function(event){ 196 var refreshURL = ''; 197 if($('.blockcart').length) 198 refreshURL = $('.blockcart').data('refresh-url'); 199 if(typeof(st_refresh_url)!='undefined' && st_refresh_url) 200 refreshURL = st_refresh_url; 201 if(!refreshURL) 202 return false; 203 var requestData = {}; 204 var updateornot = true; 205 var caller_element = null; 206 207 if (event && event.reason) { 208 //Do nothing if this is a shopping cart page even, like update remove cart items on the shopping cart page. 209 //Why? drop down and side cart blocks on the shopping cart page still need to be updated. 210 /*if(typeof(event.reason.cart_module_ignore)!=='undefined') 211 return false;*/ 212 requestData = { 213 id_product_attribute: event.reason.idProductAttribute, 214 id_product: event.reason.idProduct, 215 action: event.reason.linkAction 216 }; 217 if(typeof(event.reason.updateornot)!=='undefined') 218 updateornot = event.reason.updateornot; 219 if(typeof(event.reason.caller_element)!=='undefined') 220 caller_element = event.reason.caller_element; 221 } 222 223 if(typeof(event.resp)!='undefined' && typeof(event.resp.hasError)!='undefined' && event.resp.hasError && typeof(event.resp.errors)!='undefined' && event.resp.errors){ 224 alert(event.resp.errors.join('<br/>')); 225 if(caller_element) 226 $(caller_element).removeClass('active'); 227 return false; 228 } 229 if(typeof(go_to_shopping_cart)!='undefined' && go_to_shopping_cart){ 230 window.location.href = st_cart_page_url; 231 return false; 232 } 233 if(typeof(sttheme.buy_now)!='undefined' && sttheme.buy_now && $('button[data-button-action="add-to-cart"].benabled.active').length) 234 { 235 window.location.href = st_cart_page_url; 236 return false;
237 } 238 if(caller_element){ 239 $.extend(requestData,{'minimal-quantity': $(caller_element).data('minimal-quantity')}); 240 } 241 $.post(refreshURL, requestData).then(function (resp) { 242 $('.shoppingcart-list').replaceWith(resp.preview); 243 //used to recreate touch spin 244 prestashop.emit('stUpdatedCart', {reason:{}, resp: resp}); 245 246 if(resp.products_count) 247 { 248 if(resp.products_count>9) 249 $('.ajax_cart_quantity').addClass('dozens'); 250 else 251 $('.ajax_cart_quantity').removeClass('dozens'); 252 $('.ajax_cart_quantity').removeClass('lingge').text(resp.products_count); 253 $('.cart_body').removeClass('no_show_empty'); 254 } 255 else 256 { 257 $('.ajax_cart_quantity').removeClass('dozens').addClass('lingge').text(0); 258 hover_display_cp==1 && $('.cart_body').addClass('no_show_empty'); 259 } 260 261 if(resp.total_value) 262 { 263 $('.ajax_cart_total').text(resp.total_value); 264 } 265 if(resp.maximum_already && caller_element) 266 { 267 $(caller_element).addClass('st_maximum_already'); 268 } 269 if(typeof(requestData.action)!=='undefined' && requestData.action=='add-to-cart')//adding or removing 270 { 271 if (addtocart_animation>=1 && addtocart_animation<=3 && resp.flying_image) { 272 var flyed = showFlyimgImage(addtocart_animation, resp.flying_image, caller_element); 273 if(flyed && updateornot) 274 prestashop.emit('updateProduct', {reason:{},eventType: 'updatedProductCombination',event: null}); 275 276 if(!flyed && resp.modal && typeof(prestashop.blockcart)!=='undefined'){ 277 prestashop.blockcart.showModal(resp.modal, updateornot); 278 } 279 }else if(addtocart_animation==4 && $('#st_header .blockcart').length){ 280 $('#st_header .blockcart').addClass('open'); 281 }else if(addtocart_animation==5 && $('.rightbar_cart').length){ 282 if($('.rightbar_cart').length) 283 $('.rightbar_cart .rightbar_tri').trigger('click'); 284 else 285 prestashop.emit('stOpenSidebar', {name: 'side_products_cart', direction: 'open_bar_right'}); 286 }else if(resp.modal && typeof(prestashop.blockcart)!=='undefined'){ 287 prestashop.blockcart.showModal(resp.modal, updateornot); 288 } 289 //to do var users know when adding failed 290 // 291 if(caller_element) 292 $(caller_element).removeProp('disabled').removeClass('active'); 293 } 294 // 295 if($('button[data-button-action="add-to-cart"]').hasClass('active'))//looking for better way to remove the active calssname on the produt page 296 $('button[data-button-action="add-to-cart"]').prop('disabled', false).removeClass('active'); 297 }).fail(function (resp) { 298 prestashop.emit('handleError', {eventType: 'updateShoppingCart', resp: resp}); 299 }); 300 }; 301 var showFlyimgImage = function(addtocart_animation, flying_image, caller_element){ 302 var element = cartBlock = null; 303 if(!caller_element) 304 { 305 if($('.images-container-7,.images-container-8').length){ 306 var pro_gallery_top_dom = $('.st_image_scrolling_wrap', '.quickview'); 307 if(!pro_gallery_top_dom.length) 308 pro_gallery_top_dom = $('.st_image_scrolling_wrap'); 309 if(pro_gallery_top_dom.length){ 310 var items = pro_gallery_top_dom.find('.pro_gallery_item'); 311 $.each(items, function(){ 312 var rect = this.getBoundingClientRect(); 313 if(rect.top >= 0){ 314 element = $(this); 315 return false 316 } 317 }); 318 } 319 }else{ 320 var pro_gallery_top_dom = $('.pro_gallery_top', '.quickview'); //find a better to do tell if is in quick view 321 if(!pro_gallery_top_dom.length) 322 pro_gallery_top_dom = $('.pro_gallery_top'); 323 324 if(pro_gallery_top_dom.length && typeof(pro_gallery_top_dom[0].swiper)!=='undefined') 325 element = $(pro_gallery_top_dom[0].swiper.slides).eq(pro_gallery_top_dom[0].swiper.activeIndex).find('.pro_gallery_item'); 326 } 327 if(!element && $('.product_gallery_no_picture').length) 328 element = $('.product_gallery_no_picture'); 329 }else{ 330 element = $(caller_element).closest('.ajax_block_product').find('.front-image'); 331 if(!element.length) 332 element = $(caller_element).closest('.ajax_block_product').find('.tm_gallery_top .swiper-slide-active .tm_gallery_item'); 333 if(!element.length) 334 element = $('.stcompare_td_'+$(caller_element).data('id-product')+' .product_image img'); 335 } 336 if(!element || !element.length) 337 return false;
338 var pictureOffsetOriginal = element.hasClass('front-image') ? element.parent().offset() : element.offset();//hover image feature scroll front image up so its offset is not correct 339 if(!pictureOffsetOriginal) 340 return false; 341 pictureOffsetOriginal.right = $(window).innerWidth() - pictureOffsetOriginal.left - element.width(); 342 var flying_image_width = element.width(); 343 var flying_image_height = element.height(); 344 345 346 if(addtocart_animation==3) 347 { 348 cartBlock = $('.rightbar_cart:visible'); 349 if(!cartBlock.length) 350 cartBlock = $('.cart_mobile_bar_tri:visible') 351 } 352 353 if(addtocart_animation!=3 || !cartBlock || !cartBlock.length){ 354 cartBlock = $('.st_shopping_cart:visible'); 355 if(!cartBlock.length) 356 cartBlock = $('.cart_mobile_bar_tri:visible') 357 if(!cartBlock.length) 358 cartBlock = $('.rightbar_cart:visible') 359 } 360 if(!cartBlock || !cartBlock.length) 361 return false; 362 var cartBlockOffset = cartBlock.offset(); 363 if(!cartBlockOffset) 364 return false; 365 cartBlockOffset.right = $(window).innerWidth() - cartBlockOffset.left - Math.floor(cartBlock.width()/2); 366 367 368 $('.flying_image').remove(); 369 //using clone one is better, new one would take time to load 370 //$(flying_image) 371 element.clone().addClass('flying_image').on('load', function () { 372 $(this).show().animate({ 373 width: '50px', 374 height: '50px', 375 opacity: 0.5, 376 top: cartBlockOffset.top, 377 right: cartBlockOffset.right-25 378 }, ( (pictureOffsetOriginal.top-cartBlockOffset.top)<1000 ? 1000 : pictureOffsetOriginal.top-cartBlockOffset.top) ) 379 .fadeOut(100, function() { 380 $(this).remove(); 381 }); 382 if(addtocart_animation == 2) 383 { 384 $('body,html').animate({ 385 scrollTop: cartBlockOffset.top 386 }, ( (pictureOffsetOriginal.top-cartBlockOffset.top)<1000 ? 1000 : pictureOffsetOriginal.top-cartBlockOffset.top)); 387 } 388 }).css({ 389 top: pictureOffsetOriginal.top, 390 right: pictureOffsetOriginal.right, 391 width: flying_image_width, 392 height: flying_image_height, 393 display: 'none' 394 }).appendTo($('.st-container')); 395 return true; 396 };
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.