const OPACITY_RANGE = [ 'rgba(0,0,0, 0.0)', 'rgba(0,0,0, 0.05)', 'rgba(0,0,0, 0.1)', 'rgba(0,0,0, 0.15)', 'rgba(0,0,0, 0.2)', 'rgba(0,0,0, 0.25)', 'rgba(0,0,0, 0.30)', 'rgba(0,0,0, 0.35)', 'rgba(0,0,0, 0.4)', 'rgba(0,0,0, 0.45)', 'rgba(0,0,0, 0.5)' ]; const OPACITY_GRADES = OPACITY_RANGE.length; const FADEOUT_ANIMATION_TIMEOUT = 25; function ensureWindowCorrectSize() { if (window.innerWidth > 400) { console.log('ensureWindowCorrectSize(): resizing'); // window.innerWidth = 400; // window.innerWidth = 200; window.resizeTo(400, 200); window.stop(); } } function cleanInnerText(theObject) { theObject.innerText = ''; } function scrollToBottom() { window.scrollTo(0,document.body.scrollHeight); } function handleOrientation(event) { // Discard invalid measurements that sometimes come... if ((window.innerWidth == 0) || (window.innerHeight == 0)) { return; } if(isLandscape()) { adaptToLandscape(); } else { adaptToPortrait(); } } function adaptToPortrait() { // handleCCInPortrait(); handleShippingBubbleInPortrait(); } function adaptToLandscape() { // handleCCInLandscape(); handleShippingBubbleInLandscape(); } function handleShippingBubbleInPortrait() { if(iPhone) { //document.getElementById("shippingAddressBubble").style.width = '70vmax'; } else { //document.getElementById("shippingAddressBubble").style.width = '60vmax'; } //document.getElementById("shippingAddressBubble").style.height = '95vmax'; } function handleShippingBubbleInLandscape() { // Conflicts with the slider // document.getElementById("shippingAddressBubble").style.width = '97vmax'; // document.getElementById("shippingAddressBubble").style.height = '40vmax'; } function handleCCInPortrait() { document.getElementById("creditCardLayer").style.position = 'relative'; document.getElementById("creditCardLayer").style.width = '104%'; document.getElementById("creditCardLayer").style.top = '100px'; document.getElementById("creditCardLayer").style.left = '-8px'; document.getElementById("paybutton").style.left = '1px'; } function handleCCInLandscape() { if(iPhone) { document.getElementById("creditCardLayer").style.position = 'relative'; document.getElementById("creditCardLayer").style.width = '102%'; document.getElementById("creditCardLayer").style.top = '20px'; document.getElementById("creditCardLayer").style.left = '-7px'; document.getElementById("paybutton").style.left = '0px'; // document.getElementById("creditCardLayer").style.display = "none"; } else { document.getElementById("creditCardLayer").style.position = 'relative'; document.getElementById("creditCardLayer").style.width = '102%'; document.getElementById("creditCardLayer").style.top = '40px'; document.getElementById("creditCardLayer").style.left = '-7px'; document.getElementById("paybutton").style.left = '1px'; } } function isLandscape(event) { var width = window.innerWidth; var height = window.innerHeight; return width > height; } function setOS(isIPhone) { if (isIPhone == null) { // Desktop return; } iPhone = isIPhone; } function showOverlayOn(currentOpacityIndex) { if(!document.getElementById("overlay")) { return; } //console.log('Opacity grade: ' + currentOpacityIndex + ' and length ' + OPACITY_RANGE.length + ' evaluates to ' + (currentOpacityIndex == OPACITY_RANGE.length)); if (currentOpacityIndex == OPACITY_RANGE.length) { $('.slide-container').slick('slickGoTo', 0, false); return; } else { document.getElementById("overlay").style.display = "block"; aestheticJS(); setTimeout(function() { document.getElementById("overlay").style.backgroundColor = OPACITY_RANGE[currentOpacityIndex]; showOverlayOn(++currentOpacityIndex); }, FADEOUT_ANIMATION_TIMEOUT); } } function invokeOverlayOff() { if (singleProductCheckout) { $('.slide-container').slick('slickGoTo', 0, false); document.getElementById("showOff").style.display = "flex"; document.getElementById("overlay").style.display = "none"; off(OPACITY_RANGE.length); } else { $('.slide-container').slick('slickGoTo', 0, false); //document.getElementById("showOff").style.display = "flex"; document.getElementById("overlay").style.display = "none"; off(OPACITY_RANGE.length); } } function off(currentOpacityIndex) { // console.log('Opacity grade: ' + currentOpacityIndex + ' and length ' + OPACITY_RANGE.length + ' evaluates to ' + (currentOpacityIndex == 0)); if (currentOpacityIndex == 0) { document.getElementById("overlay").style.display = "none"; return; } else { setTimeout(function() { document.getElementById("overlay").style.backgroundColor = OPACITY_RANGE[currentOpacityIndex]; off(--currentOpacityIndex); }, FADEOUT_ANIMATION_TIMEOUT); } } function showCloseWindowAlert() { console.log('showCloseWindowAlert(): showing alert on funnel state ' + latestFunnelState); switch(latestFunnelState) { case FUNNEL_STATES.PAYMENT_WENT_THROUGH: Swal.fire({ type: 'success', title: 'Your order is already in place', text: 'You can close this window.', showConfirmButton: false, timer: 3000 }); break; case FUNNEL_STATES.PAYMENT_INFO_COMPLETE: case FUNNEL_STATES.SHIPPING_ADDRESS_COMPLETED: case FUNNEL_STATES.CANCELED_SHIPPING_OPTIONS: case FUNNEL_STATES.CANCELED_CONFIRMATION_SCREEN: case FUNNEL_STATES.CANCELED_APPOINTMENT_OPTIONS: Swal.fire({ type: 'success', title: 'Purchase cancelled', text: 'You can close this window.', showConfirmButton: false, timer: 3000 }).then(() => { returnToCalatogPage();//maybe change function of shoppig cart But must be use a diferent function when it i only one product. }); break; } } function showPaymentFailedAlert(failReason) { console.log('showPaymentFailedAlert(): showing alert on payment failure ' + failReason); Swal.fire({ type: 'error', title: 'Payment failed!', text: 'You can try another payment method', showConfirmButton: false, timer: 3000 }).then(() => { // returnToCalatogPage(); }); } function showConfirmPODpayment() { console.log('showConfirmPODpayment(): showing alert to confirm POD payment '); return Swal.fire({ title: 'Cash on delivery payment.', text: 'You will pay your order at delivery time using cash.', icon: 'info', buttons: true, showCancelButton: true, // buttons: [ 'Cancel', 'Confirm' ], cancelButtonText: 'Cancelar', confirmButtonText: 'Confirm' }); } function hidePaymentMethods() { $('#paymentMethodsContainer').hide(); $('#paymentMethodsSelector').hide(); } function hideDoneButton() { $('#doneButton').hide(); } function aestheticJS() { setEqualHeight('city', 'country'); setEqualHeight('zipcode', 'state'); } function setEqualHeight(referenceId, objectId) { if ((document.getElementById(referenceId) == null) || (document.getElementById(objectId) == null)) { return; } var referenceHeight = document.getElementById(referenceId).style.height; document.getElementById(objectId).style.height = referenceHeight; } function slideToNext() { $('.slide-container').slick('slickNext'); } function slideToPrevious() { $('.slide-container').slick('slickPrev'); } $(document).ready(function() { var md = new MobileDetect(window.navigator.userAgent); setOS(md.is('iPhone')); $('.Bubble').hide(); }); function setButtonAsLoading(elementId) { console.log('setButtonAsLoading(): invoked with ' + elementId); var button = $('#' + elementId); if (!button.hasClass('button--loading')) { button.toggleClass('button--loading'); } }; function unsetButtonAsLoading(elementId) { console.log('unsetButtonAsLoading(): invoked with ' + elementId); var button = $('#' + elementId); if (button.hasClass('button--loading')) { button.toggleClass('button--loading'); } }; function registerSliderEvents() { $('.slide-container').on('afterChange', function(event, slick, currentSlide, nextSlide) { var slideId = $(slick.$slides.get(currentSlide)).attr('id'); slideSetup(slideId); }); } function slideSetup(slideId) { switch(slideId) { case 'shippingForm': console.log('slideSetup(): tyding ' + slideId + ' up'); enableShippingButton(); break; } } function enableShippingButton() { if ($('#shippingButton').hasClass('button--loading')) { $('#shippingButton').toggleClass('button--loading'); $('#shippingButton').prop("disabled",false); } } function handleError() { var title = null; var text = null; switch(error) { case 404: title = 'Quickoffer not found!'; text = 'The quickoffer you requested does not exist anymore!'; break; case 412: title = 'Out of stock!'; text = 'The product will be available again shortly!'; break; default: title = 'Could not serve your request!'; text = 'Please try again at a later time!'; break; } Swal.fire({ type: 'info', title: title, html: '
' + text + '

', showConfirmButton: false, allowOutsideClick: false }) return; } function contactSellerAboutProduct() { const message = "Hey, I am interested in this product, when will it be available?" + ' 👉 ' + window.location.href; const whatsAppURL = encodeURI('https://wa.me/' + project.label + '?text=' + message); window.open(whatsAppURL, '_blank'); } function ensureProductImageInPlace() { var showoffImage = document.getElementById('productShowOffImage'); var purchaseDoneImage = document.getElementById('purchaseDoneProductImage'); showoffImage.src = imagesToPreLoad.productImage.src; purchaseDoneImage.style.background = 'url(' + imagesToPreLoad.productImage.src + ') center center no-repeat'; purchaseDoneImage.style['background-size'] = '100%'; } function doCorrectiveInitialScroll() { paymentMethodsSlider.slick('slickGoTo', 0, true); } window.addEventListener('deviceorientation', handleOrientation, true);