function scaleCaptchaWhenReady(containerId) { const container = document.querySelector(`#${containerId}`); if (!container) return;
const checkAndScale = () => { const captcha = container.querySelector('div:first-child'); if (!captcha) { requestAnimationFrame(checkAndScale); return; }
const parentWidth = container.offsetWidth; if (parentWidth === 0) { requestAnimationFrame(checkAndScale); return; }
const captchaWidth = 304; let scale = parentWidth / captchaWidth; if (scale > 1) scale = 1;
captcha.style.transform = `scale(${scale})`; captcha.style.transformOrigin = 'top right';
captcha.classList.add('recaptcha-visible');
container.classList.remove('recaptcha-hidden'); };
checkAndScale(); }
const recaptchaContainers = ['recaptcha-container-1', 'recaptcha-container-2', 'recaptcha-container-3', 'recaptcha-container-4'];
window.addEventListener('load', () => { recaptchaContainers.forEach(scaleCaptchaWhenReady); }); window.addEventListener('resize', () => { recaptchaContainers.forEach(scaleCaptchaWhenReady); });
document.addEventListener('DOMContentLoaded', function() { // دکمه ورود با پسورد var passwordButton = document.querySelector('.woocommerce-form-loginold__submit[name="loginold"]');
// فرمهای مورد نظر var loginForm = document.querySelector('.woocommerce-form-login.login-mamoli'); var verificationForm = document.querySelector('.woocommerce-form-login.verification');
// تابع برای تغییر نمایش فرمها function toggleForms() { if (loginForm && verificationForm) { if (loginForm.style.display === 'none') { loginForm.style.display = 'block'; verificationForm.style.display = 'none'; } else { loginForm.style.display = 'none'; verificationForm.style.display = 'block'; } } }
// افزودن رویداد کلیک به دکمه if (passwordButton) { passwordButton.addEventListener('click', toggleForms); } }); document.addEventListener('DOMContentLoaded', function() { // دکمه ورود با پیامک var smsButton = document.querySelector('.woocommerce-form-loginold__submit-sms');
// فرمهای مورد نظر var loginForm = document.querySelector('.woocommerce-form-login.login-mamoli'); var verificationForm = document.querySelector('.woocommerce-form-login.verification');
// تابع برای تغییر نمایش فرمها function toggleForms() { if (loginForm && verificationForm) { if (loginForm.style.display === 'none') { loginForm.style.display = 'block'; verificationForm.style.display = 'none'; } else { loginForm.style.display = 'none'; verificationForm.style.display = 'block'; } } }
// افزودن رویداد کلیک به لینک
if (smsButton) {
smsButton.addEventListener('click', function(event) {
event.preventDefault(); // جلوگیری از رفتار پیشفرض لینک
toggleForms();
});
}
});
const firstNameInput = document.getElementById('reg_billing_first_name');
if (firstNameInput) { firstNameInput.addEventListener('focus', function() { setTimeout(() => { try { this.scrollIntoView({ behavior: 'smooth', block: 'center' }); } catch (e) { this.scrollIntoView(true); } }, 300); }); }
jQuery(document).ready(function($) { $('#billing_phone').on('input', function() { var value = $(this).val(); var errorMessage = $('#phone_error_message');
// حذف کاراکترهای غیر عددی value = value.replace(/\D/g, '');
// محدود کردن به ۱۰ کاراکتر if (value.length > 11) { value = value.slice(0, 11); }
// بررسی اگر فیلد خالی باشد if (value === '') { errorMessage.hide(); // پنهان کردن پیام خطا } // چک کردن اینکه آیا شماره با صفر شروع میشود else if (value.startsWith('9')) { errorMessage.text('شماره نمیتواند با 9 شروع شود').show(); // نمایش پیام خطا } // چک کردن اینکه آیا شماره با 9 شروع میشود else if (!value.startsWith('0')) { errorMessage.text('شماره باید با 0 شروع شود').show(); // نمایش پیام خطا } // بررسی طول شماره و شرایط دیگر else if (value.length < 11) { errorMessage.text('شماره باید 11 رقم باشد').show(); // نمایش پیام خطا } else { errorMessage.hide(); // مخفی کردن پیام خطا } $(this).val(value); }); }); jQuery(document).ready(function($) { $('#reg_billing_phone').on('input', function() { var value = $(this).val(); var errorMessage = $('#phone_error_messagetwo'); // حذف کاراکترهای غیر عددی value = value.replace(/\D/g, ''); // محدود کردن به ۱۰ کاراکتر if (value.length > 11) { value = value.slice(0, 11); }
// بررسی اگر فیلد خالی باشد if (value === '') { errorMessage.hide(); // پنهان کردن پیام خطا } // چک کردن اینکه آیا شماره با صفر شروع میشود else if (value.startsWith('9')) { errorMessage.text('شماره نمیتواند با 9 شروع شود').show(); // نمایش پیام خطا } // چک کردن اینکه آیا شماره با 9 شروع میشود else if (!value.startsWith('0')) { errorMessage.text('شماره باید با 0 شروع شود').show(); // نمایش پیام خطا } // بررسی طول شماره و شرایط دیگر else if (value.length < 11) { errorMessage.text('شماره موبایل باید 11 رقم باشد').show(); // نمایش پیام خطا } else { errorMessage.hide(); // مخفی کردن پیام خطا } $(this).val(value); }); }); jQuery(document).ready(function($) { $('#reg_billing_phone32').on('input', function() { var value = $(this).val(); var errorMessage = $('#phone_error_messagethree'); // حذف کاراکترهای غیر عددی value = value.replace(/\D/g, ''); // محدود کردن به ۱۰ کاراکتر if (value.length > 11) { value = value.slice(0, 11); }
// بررسی اگر فیلد خالی باشد if (value === '') { errorMessage.hide(); // پنهان کردن پیام خطا } // چک کردن اینکه آیا شماره با صفر شروع میشود else if (value.startsWith('9')) { errorMessage.text('شماره نمیتواند با 9 شروع شود').show(); // نمایش پیام خطا } // چک کردن اینکه آیا شماره با 9 شروع میشود else if (!value.startsWith('0')) { errorMessage.text('شماره باید با 0 شروع شود').show(); // نمایش پیام خطا } // بررسی طول شماره و شرایط دیگر else if (value.length < 11) { errorMessage.text('شماره موبایل باید 11 رقم باشد').show(); // نمایش پیام خطا } else { errorMessage.hide(); // مخفی کردن پیام خطا } $(this).val(value); }); }); jQuery(document).ready(function($) { $('#verification_code').on('input', function() { var value = $(this).val(); // حذف کاراکترهای غیر عددی value = value.replace(/\D/g, ''); // محدود کردن به ۵ کاراکتر if (value.length > 5) { value = value.slice(0, 5); }
$(this).val(value); }); });