1/** 2 * 2007-2020 PrestaShop and Contributors 3 * 4 * NOTICE OF LICENSE 5 * 6 * This source file is subject to the Academic Free License 3.0 (AFL-3.0) 7 * that is bundled with this package in the file LICENSE.txt. 8 * It is also available through the world-wide-web at this URL: 9 * https://opensource.org/licenses/AFL-3.0 10 * If you did not receive a copy of the license and are unable to 11 * obtain it through the world-wide-web, please send an email 12 * to [email protected] so we can send you a copy immediately. 13 * 14 * @author PrestaShop SA <[email protected]> 15 * @copyright 2007-2020 PrestaShop SA and Contributors 16 * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) 17 * International Registered Trademark & Property of PrestaShop SA 18 */ 19 20/** 21 * This module exposes an extension point through `showModal` function. 22 * 23 * If you want to customize the way the modal window is displayed, you need to do: 24 * 25 * prestashop.blockcart = prestashop.blockcart || {}; 26 * prestashop.blockcart.showModal = function myOwnShowModal (modalHTML) { 27 * // your own code 28 * // please not that it is your responsibility to handle the modal "close" behavior 29 * }; 30 * 31 * Warning: your custom JavaScript needs to be included **before** this file. 32 * The safest way to do so is to place your "override" inside the theme main JavaScript file. 33 * 34 */ 35 36let alert_success_add_to_cart_timeout = null; 37 38$(document).ready(function () { 39 prestashop.blockcart = prestashop.blockcart || {}; 40 41 var showModal = prestashop.blockcart.showModal || function (modal) { 42 var $body = $('body'); 43 $body.append(modal); 44 $body.one('click', '#blockcart-modal', function (event) { 45 if (event.target.id === 'blockcart-modal') { 46 $(event.target).remove(); 47 } 48 }); 49 }; 50 51 prestashop.on( 52 'updateCart', 53 function (event) { 54 var refreshURL = $('.blockcart').data('refresh-url'); 55 var requestData = {}; 56 if (event && event.reason && typeof event.resp !== 'undefined' && !event.resp.hasError) { 57 requestData = { 58 id_customization: event.reason.idCustomization, 59 id_product_attribute: event.reason.idProductAttribute, 60 id_product: event.reason.idProduct, 61 action: event.reason.linkAction 62 }; 63 } 64 if (event && event.resp && event.resp.hasError) { 65 prestashop.emit('showErrorNextToAddtoCartButton', {errorMessage: event.resp.errors.join('<br/>')}); 66 } 67 $.post(refreshURL, requestData).then(function (resp) { 68 var html = $('<div />').append($.parseHTML(resp.preview)); 69 $('.blockcart').replaceWith($(resp.preview).find('.blockcart')); 70 71 window.handleCartHover(); 72 73 const product_page = $('body').hasClass('page-product'); 74 75 if(product_page) { 76 if (alert_success_add_to_cart_timeout) 77 clearTimeout(alert_success_add_to_cart_timeout); 78 79 const alert = $('.alert-success-add-to-cart'); 80 if(alert) { 81 const display_duration = alert.data('display-duration') ?? 3000; 82 alert.addClass('open'); 83 84 const header_cart_dropdown = $('#header #_desktop_cart .dropdown'); 85 if(header_cart_dropdown) { 86 87 setTimeout(() => { 88 header_cart_dropdown.addClass('open'); 89 90 setTimeout(() => { 91 header_cart_dropdown.removeClass('open'); 92 }, 2500); 93 }, 1000) 94 } 95 96 alert_success_add_to_cart_timeout = setTimeout(() => { 97 alert.removeClass('open'); 98 }, display_duration); 99 } 100 } else { 101 if (resp.modal) { 102 showModal(resp.modal); 103 } 104 } 105 }).fail(function (resp) { 106 prestashop.emit('handleError', {eventType: 'updateShoppingCart', resp: resp}); 107 }); 108 } 109 ); 110});
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.