/** * Copyright since 2007 PrestaShop SA and Contributors * PrestaShop is an International Registered Trademark & Property of PrestaShop SA * * NOTICE OF LICENSE * * This source file is subject to the Academic Free License version 3.0 * that is bundled with this package in the file LICENSE.md. * It is also available through the world-wide-web at this URL: * https://opensource.org/licenses/AFL-3.0 * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to license@prestashop.com so we can send you a copy immediately. * * @author PrestaShop SA and Contributors * @copyright Since 2007 PrestaShop SA and Contributors * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 */ window.recaptchaResponse = ''; var callbackRecaptcha = function(response) { return new Promise(function(resolve, reject) { window.recaptchaResponse = escape(response); resolve(); }); }; var checkRecaptchaCompletion = function (event) { if (window.recaptchaResponse.length <= 0 && window.recaptchaResponse == '') { event.preventDefault(); if (! $('.g-recaptcha .alert-danger').length > 0) { $('.g-recaptcha').append("

Please make sure you complete reCaptcha above.

"); } } }; var checkUserCurrentTab17 = function (event) { let currentTabSelected = $(event.currentTarget).attr('aria-controls'); if (currentTabSelected === "checkout-guest-form") { // Remove reCaptcha from One Page Checkout Login Tab, only if it exits if (recaptchaLoginForm == "1" && $('#recaptchaOnePageCheckoutLoginForm').length > 0) { $('div').remove('.g-recaptcha'); } // Display reCaptcha if (recaptchaRegistrationForm == "1" && $('#checkout').length > 0) { handleCaptchaError('#checkout #checkout-personal-information-step .content #customer-form '); $('#checkout #checkout-personal-information-step .content #customer-form ').first().append(elementRecaptcha); $('#checkout #checkout-personal-information-step .content #customer-form .g-recaptcha') .first() .attr('id', 'recaptchaOnePageCheckoutGuestForm') .css({ "margin-top": "10px", "margin-bottom": "20px", "text-align": "-webkit-center" }); $("#checkout #checkout-personal-information-step .content #customer-form .form-footer").on('click', checkRecaptchaCompletion); grecaptcha.render('recaptchaOnePageCheckoutGuestForm'); } } else if (currentTabSelected === "checkout-login-form") { // Remove reCaptcha from One Page Checkout Guest Tab, only if it exits if (recaptchaRegistrationForm == "1" && $('#recaptchaOnePageCheckoutGuestForm').length > 0) { $('div').remove('.g-recaptcha'); } // Display reCaptcha if (recaptchaLoginForm == "1" && $('#checkout').length > 0 ) { handleCaptchaError('#checkout #checkout-personal-information-step .forgot-password'); $('#checkout #checkout-personal-information-step .forgot-password').first().append(elementRecaptcha); $('#checkout #checkout-personal-information-step .forgot-password .g-recaptcha') .first() .attr('id', 'recaptchaOnePageCheckoutLoginForm') .css({ "margin-left": "-225px", "margin-top": "15px", "margin-bottom": "20px", "text-align": "-webkit-center" }); $("#checkout #checkout-personal-information-step .forgot-password").on('click', checkRecaptchaCompletion); grecaptcha.render('recaptchaOnePageCheckoutLoginForm'); } } } var handleCaptchaError = function(targetSelector) { let urlParams = new URLSearchParams(window.location.search); if (urlParams.has('captchaErrorMsg')) { $(targetSelector).append('
'+ urlParams.get('captchaErrorMsg') +'
') } }; var initPsRecaptchaPresta17 = function() { let urlParams = new URLSearchParams(window.location.search); let currentOnePageCheckoutStep = $(this).attr('id'); // Login if (recaptchaLoginForm == "1" && $('#authentication').length > 0 && !urlParams.has('create_account') ) { handleCaptchaError('#authentication #login-form .forgot-password'); $('#authentication #login-form .forgot-password').first().append(elementRecaptcha); $('#authentication #login-form .forgot-password .g-recaptcha') .first() .attr('id', 'recaptchaLoginForm') .css({"margin-top": "15px"}); $("#authentication").on('submit', '#login-form', checkRecaptchaCompletion); grecaptcha.render('recaptchaLoginForm'); } // Registration if (recaptchaRegistrationForm == "1" && $('#authentication').length > 0 && urlParams.has('create_account') ) { handleCaptchaError('#authentication #customer-form'); $('#authentication #customer-form ').first().append(elementRecaptcha); $('#authentication #customer-form .g-recaptcha') .first() .attr('id', 'recaptchaRegistrationForm') .css({ "margin-top": "10px", "margin-bottom": "20px", }); $("#authentication").on('submit', 'form#customer-form', checkRecaptchaCompletion); grecaptcha.render('recaptchaRegistrationForm'); } // Registration in PS 8 if (recaptchaRegistrationForm == "1" && $('#registration').length > 0 && isPsVersion8 ) { handleCaptchaError('#registration #customer-form'); $('#registration #customer-form ').first().append(elementRecaptcha); $('#registration #customer-form .g-recaptcha') .first() .attr('id', 'recaptchaRegistrationForm') .css({ "margin-top": "10px", "margin-bottom": "20px", }); $("#authentication").on('submit', 'form#customer-form', checkRecaptchaCompletion); grecaptcha.render('recaptchaRegistrationForm'); } // Contact if (recaptchaContactForm == "1" && $('#contact').length > 0 && !$('#contact .alert.alert-success').length > 0 ) { handleCaptchaError('#contact .contact-form form'); $('#contact .contact-form .form-fields').first().append(elementRecaptcha); $('#contact .contact-form .form-fields .g-recaptcha') .first() .attr('id', 'recaptchaContactForm') .css({ "margin-left": "-43px", "margin-bottom": "20px", }); $("#contact form .form-footer").on('click', checkRecaptchaCompletion); grecaptcha.render('recaptchaContactForm'); } // One Page Checkout - Registration Form (Guest) if (recaptchaRegistrationForm == "1" && $('#checkout').length > 0) { $("#checkout #checkout-personal-information-step .nav-link").on('click', checkUserCurrentTab17); handleCaptchaError('#checkout #checkout-personal-information-step .content #customer-form '); $('#checkout #checkout-personal-information-step .content #customer-form ') .first() .append(elementRecaptcha); $('#checkout #checkout-personal-information-step .content #customer-form .g-recaptcha') .first() .attr('id', 'recaptchaOnePageCheckoutGuestForm') .css({ "margin-top": "10px", "margin-bottom": "20px", }); $("#checkout #checkout-personal-information-step .content #customer-form .form-footer") .on('click', checkRecaptchaCompletion); grecaptcha.render('recaptchaOnePageCheckoutGuestForm'); } // One Page Checkout - Login Form if (recaptchaLoginForm == "1" && $('#checkout').length > 0 ) { handleCaptchaError('#checkout #checkout-personal-information-step .forgot-password'); $('#checkout #checkout-personal-information-step .forgot-password').first().append(elementRecaptcha); $('#checkout #checkout-personal-information-step .forgot-password .g-recaptcha') .first() .attr('id', 'recaptchaOnePageCheckoutLoginForm') .css({ "margin-left": "-225px", "margin-top": "15px", "margin-bottom": "20px", }); $("#checkout #checkout-personal-information-step .forgot-password").on('click', checkRecaptchaCompletion); grecaptcha.render('recaptchaOnePageCheckoutLoginForm'); } }; var initPsRecaptchaPresta16 = function() { // Login if (recaptchaLoginForm == "1" && $('#authentication').length > 0) { handleCaptchaError('#authentication #login_form .lost_password'); $('#authentication #login_form .lost_password').first().append(elementRecaptcha); $('#authentication #login_form .lost_password .g-recaptcha') .first() .attr('id', 'recaptchaLoginForm') .css({ "margin-top": "15px", "display": "inherit !important", }); $("#authentication").on('submit', '#login_form', checkRecaptchaCompletion); grecaptcha.render('recaptchaLoginForm'); } // Registration if (recaptchaRegistrationForm == "1" && $('#authentication').length > 0) { handleCaptchaError('#authentication #create-account_form'); $('#authentication #create-account_form #SubmitCreate').on('click', function() { let checkFormAccountCreationExist = setInterval(function() { if ($('form#account-creation_form').length) { clearInterval(checkFormAccountCreationExist); $('#authentication #account-creation_form .account_creation').on('click', '#submitAccount', checkRecaptchaCompletion); $('#authentication #account-creation_form .account_creation').first().append(elementRecaptcha); $('#authentication #account-creation_form .account_creation .g-recaptcha') .first() .attr('id', 'recaptchaRegistrationForm') .css({ "margin-bottom": "15px", "display": "inherit !important", }); grecaptcha.render('recaptchaRegistrationForm'); }; }, 300); }); } // Contact if (recaptchaContactForm == "1" && $('#contact').length > 0) { handleCaptchaError('#contact .contact-form-box .submit'); $('#contact .contact-form-box .submit').first().prepend(elementRecaptcha); $('#contact .contact-form-box .submit').on('click', '#submitMessage', checkRecaptchaCompletion); $('#contact .contact-form-box .submit .g-recaptcha').first() .attr('id', 'recaptchaContactForm') .css({ "margin-top": "5px", "margin-bottom": "20px", "display": "inherit !important", }); grecaptcha.render('recaptchaContactForm'); } // One Page Checkout is not supported in PrestaShop 1.6 due to submit ajax // who can't get g-recaptcha-response from google. }; $(document).ready(function() { // js concurrency is broken so i make sure grecaptcha is properly defined let checkGRecaptchaRenderExist = setInterval(function() { if (typeof grecaptcha.render == "function") { clearInterval(checkGRecaptchaRenderExist); if (isPsVersion17 == "1") { initPsRecaptchaPresta17(); } else { initPsRecaptchaPresta16(); } } }, 300); });