`;
if (distance < 0) {
clearInterval(x);
document.getElementById("lr-countdown").innerHTML = `
Get the code again
`;
}
}, 1000);
}
// Password visibility toggle for Bakala theme - inline version
function togglePasswordVisibility(inputId, iconId) {
var input = document.getElementById(inputId);
var icon = document.getElementById(iconId);
if (!input || !icon) return;
icon.addEventListener('click', function() {
if (input.type === 'password') {
input.type = 'text';
icon.classList.remove('icon-eye-closed');
icon.classList.add('icon-eye-open');
} else {
input.type = 'password';
icon.classList.remove('icon-eye-open');
icon.classList.add('icon-eye-closed');
}
});
}
jQuery(document).ready(function($) {
togglePasswordVisibility('pass', 'toggle-pass-eye');
togglePasswordVisibility('password', 'toggle-password-eye');
});
// --- END password toggle ---
function showPass() {
jQuery('#show-pass').fadeOut();
jQuery('#send').fadeOut();
jQuery('#lr-btn').fadeIn();
jQuery('.forget').fadeIn();
jQuery('#show-code').fadeIn();
jQuery('#lr-password-field').fadeIn();
}
function showCode() {
jQuery('#show-code').fadeOut();
jQuery('#send').fadeIn();
jQuery('#lr-btn').fadeOut();
jQuery('#show-pass').fadeIn();
jQuery('.forget').fadeOut();
jQuery('#lr-password-field').fadeOut();
}
jQuery('#show-pass').click(function() {
showPass();
jQuery('#pass').focus();
});
jQuery('#show-code').click(function() {
showCode();
jQuery('#phone').focus();
});
jQuery('#pass').focus(function() {
jQuery(document).keypress(function(e) {
if (e.which == '13') {
e.preventDefault();
jQuery('#lr-btn').click();
}
});
});
function getCookie(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
function getEmail(email) {
jQuery('#lr-send-form').fadeOut();
jQuery('#error-phone').fadeOut();
jQuery('#lr-password-form').fadeIn();
jQuery('#lr-submit-form').fadeOut();
jQuery.ajax({
url: "https://oxostyle.com/wp-admin/admin-ajax.php",
type: 'GET',
data: {
action: 'get_latest_posts_by_category',
email: email
},
beforeSend: function() {
jQuery('.lr-loader').show();
},
success: function(data) {
if (data == "yes") {
jQuery('.lr-loader').hide();
jQuery('.mobile-number').text(getCookie('phone'));
} else {
jQuery('.lr-loader').hide();
}
}
});
}
function getphn() {
jQuery('#lr-submit-form').show();
jQuery('#lr-send-form').hide();
jQuery('#error-phone').fadeOut();
bakalaCountdown();
jQuery('.lr_loader').remove();
jQuery('#login-register .lr-box').removeClass('lr_loading');
jQuery('span.lr-phone-number').text(getCookie('phone'));
jQuery('input.lr-phone-number').val(getCookie('phone'));
}
var digits = jQuery('input#autofill-input').val();
var codeCookie = getCookie('opt_code');
jQuery('#lr-send-form').on('submit', function(e) {
e.preventDefault();
var nonce = jQuery('meta[name="csrf-token"]').attr('content');
jQuery.ajaxSetup({
headers: {
'X-CSRF-TOKEN': nonce
}
});
var loaderTimeout;
if (jQuery('#pass').length < 1) {
if (jQuery('#phone').val().length > 0) {
jQuery.ajax({
url: "https://oxostyle.com/bakala/ajax/send_code/",
type: 'POST',
dataType: "json",
data: {
action: "bakala_send_code",
phone_email: jQuery('#phone').val(),
},
beforeSend: function() {
jQuery('#login-register .lr-box').append('
');
jQuery('#login-register .lr-box').addClass('lr_loading');
loaderTimeout = setTimeout(function() {
jQuery('.lr_loader').remove();
jQuery('#login-register .lr-box').removeClass('lr_loading');
}, 10000);
},
success: function(response) {
if (response.status_code == 200) {
if (phone_pattern.test(jQuery('#phone').val())) {
getphn();
jQuery('#autofill-input').focus();
} else if (validateEmail(jQuery('#phone').val())) {
jQuery('.lr_loader').remove();
jQuery('#login-register .lr-box').removeClass('lr_loading');
getEmail(jQuery('#phone').val());
} else {
jQuery('#error-phone').fadeIn();
}
} else {
const Toast = Swal.mixin({
toast: true,
position: 'center',
showConfirmButton: false,
timer: 3000,
timerProgressBar: true,
didOpen: (toast) => {
toast.addEventListener('mouseenter', Swal.stopTimer);
toast.addEventListener('mouseleave', Swal.resumeTimer);
}
});
Toast.fire({
title: response.message,
icon: 'error',
});
navigator.vibrate(600);
jQuery('#phone').addClass('animated shake');
}
},
complete: function() {
jQuery('.lr_loader').remove();
jQuery('#login-register .lr-box').removeClass('lr_loading');
},
});
} else {
navigator.vibrate(600);
jQuery('#phone').addClass('animated shake');
jQuery('#error-phone').text("\u0634\u0645\u0627\u0631\u0647 \u0645\u0648\u0628\u0627\u06cc\u0644 \u062e\u0648\u062f \u0631\u0627 \u0648\u0627\u0631\u062f \u06a9\u0646\u06cc\u062f");
jQuery('#error-phone').fadeIn();
}
} else {
if (phone_pattern.test(jQuery('#phone').val())) {
jQuery.ajax({
url: "https://oxostyle.com/bakala/ajax/send_code/",
type: 'POST',
dataType: "json",
data: {
action: "bakala_send_code",
phone_email: jQuery('#phone').val(),
},
beforeSend: function() {
jQuery('#login-register .lr-box').append('
');
jQuery('#login-register .lr-box').addClass('lr_loading');
loaderTimeout = setTimeout(function() {
jQuery('.lr_loader').remove();
jQuery('#login-register .lr-box').removeClass('lr_loading');
}, 10000);
},
success: function(response) {
if (response.status_code == 200) {
if (phone_pattern.test(jQuery('#phone').val())) {
getphn();
jQuery('#autofill-input').focus();
} else if (validateEmail(jQuery('#phone').val())) {
jQuery('.lr_loader').remove();
jQuery('#login-register .lr-box').removeClass('lr_loading');
getEmail(jQuery('#phone').val());
} else {
jQuery('#error-phone').fadeIn();
}
} else {
const Toast = Swal.mixin({
toast: true,
position: 'center',
showConfirmButton: false,
timer: 3000,
timerProgressBar: true,
didOpen: (toast) => {
toast.addEventListener('mouseenter', Swal.stopTimer);
toast.addEventListener('mouseleave', Swal.resumeTimer);
}
});
Toast.fire({
title: response.message,
icon: 'error',
});
navigator.vibrate(600);
jQuery('#phone').addClass('animated shake');
}
},
complete: function() {
jQuery('.lr_loader').remove();
jQuery('#login-register .lr-box').removeClass('lr_loading');
jQuery('#autofill-input').focus();
},
});
} else {
navigator.vibrate(600);
jQuery('#phone').addClass('animated shake');
jQuery('#error-phone').text("\u0634\u0645\u0627\u0631\u0647 \u0645\u0648\u0628\u0627\u06cc\u0644 \u062e\u0648\u062f \u0631\u0627 \u0648\u0627\u0631\u062f \u06a9\u0646\u06cc\u062f");
jQuery('#error-phone').fadeIn();
}
}
return false;
});
jQuery('#lr-btn').on('click', function() {
var phone_pattern = /^(\+98|0098|98|0)?9\d{9}$/;
var email_pattern = /^[a-zA-Z-' ]*$/;
var urlParams = new URLSearchParams(window.location.search);
var redirect_url = urlParams.get('redirect');
if (jQuery('#phone').val().length > 0 && jQuery('#pass').val().length > 1) {
jQuery.ajax({
url: "https://oxostyle.com/wp-admin/admin-ajax.php",
type: 'POST',
dataType: "json",
data: {
action: "bakala_lr_submit",
phone_email: jQuery('#phone').val(),
password: jQuery('#pass').val()
},
beforeSend: function() {
jQuery('#login-register .lr-box').append('
');
jQuery('#login-register .lr-box').addClass('lr_loading');
},
success: function(response) {
jQuery('.lr_loader').remove();
jQuery('#login-register .lr-box').removeClass('lr_loading');
if (response.status_code == 200) {
const Toast = Swal.mixin({
toast: true,
position: 'center',
showConfirmButton: false,
timer: 1000,
timerProgressBar: true,
didOpen: (toast) => {
toast.addEventListener('mouseenter', Swal.stopTimer);
toast.addEventListener('mouseleave', Swal.resumeTimer);
}
});
Toast.fire({
title: response.message,
icon: 'success',
}).then((result) => {
if (redirect_url && redirect_url.length > 0) {
window.location.href = redirect_url;
} else if (response.redirect) {
window.location.href = response.redirect;
} else {
location.reload();
}
});
} else {
const Toast = Swal.mixin({
toast: true,
position: 'center',
showConfirmButton: false,
timer: 1000,
timerProgressBar: true,
didOpen: (toast) => {
toast.addEventListener('mouseenter', Swal.stopTimer);
toast.addEventListener('mouseleave', Swal.resumeTimer);
}
});
Toast.fire({
title: response.message,
icon: 'error',
});
navigator.vibrate(600);
jQuery('#pass').addClass('animated shake');
jQuery('#pass').css('borderColor', '#ee5a66');
jQuery('#error-pass').text(response.message);
jQuery('#error-pass').fadeIn();
}
}
});
}
});
// فقط برای دسکتاپ - در موبایل از event handler جداگانه استفاده میشود
if (!jQuery('body').hasClass('mobile') && !window.matchMedia("(max-width: 768px)").matches) {
jQuery('#lr-submit-form').on('submit', function(e) {
e.preventDefault();
var urlParams = new URLSearchParams(window.location.search);
var redirect_url = urlParams.get('redirect');
var digits = jQuery('input#autofill-input').val();
jQuery.ajax({
url: "https://oxostyle.com/bakala/ajax/submit_code/",
type: 'POST',
dataType: "json",
data: {
action: "bakala_submit_code",
token: digits,
},
beforeSend: function() {
jQuery('#login-register .lr-box').append('
');
jQuery('#login-register .lr-box').addClass('lr_loading');
},
success: function(response) {
jQuery('.lr_loader').remove();
jQuery('#login-register .lr-box').removeClass('lr_loading');
if (response.status_code == 200) {
jQuery('body:not(.bk_myaccount) #bakala_login').modal('toggle');
const Toast = Swal.mixin({
toast: true,
position: 'center',
showConfirmButton: false,
timer: 1000,
timerProgressBar: true,
didOpen: (toast) => {
toast.addEventListener('mouseenter', Swal.stopTimer);
toast.addEventListener('mouseleave', Swal.resumeTimer);
}
});
Toast.fire({
title: response.message,
icon: 'success',
}).then((result) => {
if (redirect_url && redirect_url.length > 0) {
window.location.href = redirect_url;
} else if (response.redirect) {
window.location.href = response.redirect;
} else {
location.reload();
}
});
} else {
const Toast = Swal.mixin({
toast: true,
position: 'center',
showConfirmButton: false,
timer: 100000,
timerProgressBar: true,
didOpen: (toast) => {
toast.addEventListener('mouseenter', Swal.stopTimer);
toast.addEventListener('mouseleave', Swal.resumeTimer);
}
});
Toast.fire({
title: response.message,
icon: 'error',
});
navigator.vibrate(600);
jQuery('#lr-token input').addClass('animated shake');
jQuery('#lr-token input').css('borderColor', '#ee5a66');
jQuery('.token-error').text(response.message);
}
}
});
return false;
});
}
var phone_pattern = /^(\+98|0098|98|0)?9\d{9}$/;
var email_pattern = /^[a-zA-Z-' ]*$/;
jQuery('#phone').keyup(function() {
if (phone_pattern.test(jQuery(this).val()) == false && !Array.isArray(validateEmail(jQuery(this).val()))) {
jQuery(this).parent().css('height', 'auto');
jQuery('#send').attr('disabled', 'disabled');
jQuery(this).css('borderColor', '#ee5a66');
} else {
jQuery(this).parent().css('height', '65px');
jQuery('#send').removeAttr('disabled');
jQuery(this).css('borderColor', 'green');
if (phone_pattern.test(jQuery(this).val())) {
showCode();
} else {
showPass();
}
}
});
jQuery('#lr-password-form').on('submit', function(e) {
e.preventDefault();
var password = jQuery('input#password').val();
jQuery.ajax({
url: "https://oxostyle.com/wp-admin/admin-ajax.php",
type: 'POST',
dataType: "json",
data: {
action: "bakala_submit_password",
password: password,
},
beforeSend: function() {
jQuery('#login-register .lr-box').append('
');
jQuery('#login-register .lr-box').addClass('lr_loading');
},
success: function(response) {
jQuery('.lr_loader').remove();
jQuery('#login-register .lr-box').removeClass('lr_loading');
if (response.status_code == 200) {
jQuery('body:not(.bk_myaccount) #bakala_login').modal('toggle');
const Toast = Swal.mixin({
toast: true,
position: 'center',
showConfirmButton: false,
timer: 1000,
timerProgressBar: true,
didOpen: (toast) => {
toast.addEventListener('mouseenter', Swal.stopTimer);
toast.addEventListener('mouseleave', Swal.resumeTimer);
}
});
Toast.fire({
title: response.message,
icon: 'success',
}).then((result) => {
location.reload();
});
} else {
const Toast = Swal.mixin({
toast: true,
position: 'center',
showConfirmButton: false,
timer: 1000,
timerProgressBar: true,
didOpen: (toast) => {
toast.addEventListener('mouseenter', Swal.stopTimer);
toast.addEventListener('mouseleave', Swal.resumeTimer);
}
});
Toast.fire({
title: response.message,
icon: 'error',
});
navigator.vibrate(600);
jQuery('#pass').addClass('animated shake');
jQuery('#password').css('borderColor', '#ee5a66');
jQuery('.password-error').text(response.message);
}
}
});
return false;
});
function resendCode() {
jQuery.ajax({
url: "https://oxostyle.com/bakala/ajax/send_code/",
type: 'POST',
data: {
action: "bakala_send_code",
phone_email: jQuery('#phone').val(),
},
beforeSend: function() {
jQuery('.lr-loader').show();
},
complete: function() {
jQuery('.lr-loader').hide();
},
success: function(data) {
var pattern = /^(\+98|0098|98|0)?9\d{9}$/;
if (pattern.test(jQuery('#phone').val())) {
bakalaCountdown();
jQuery('#lr-submit-form').fadeIn();
jQuery('#lr-send-form').fadeOut();
jQuery('#error-phone').fadeOut();
} else {
jQuery('#error-phone').fadeIn();
}
}
});
}
jQuery('#edit-phone-number,button.header__button.back-icon').click(function(e) {
e.preventDefault();
jQuery('#lr-submit-form').fadeOut();
jQuery('#lr-send-form').fadeIn();
});
String.prototype.toEnglishDigit = function() {
var find = ["۰", "۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹"];
var replace = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"];
var replaceString = this;
var regex;
for (var i = 0; i < find.length; i++) {
regex = new RegExp(find[i], "g");
replaceString = replaceString.replace(regex, replace[i]);
}
return replaceString;
};
document.querySelectorAll('input').forEach(input => {
input.addEventListener('input', function() {
input.value = input.value.toEnglishDigit();
});
});
jQuery("#lr-token")
.find("input")
.attr("maxlength", 6) // Set maxlength to 4 for the single input field
.on("keyup", function(e) {
e.preventDefault();
// Capture the input value
var inputVal = $(this).val();
// Check if the input length matches the required 4 characters
if (inputVal.length === 6) {
if (jQuery(this).parent().data("autosubmit")) {
jQuery(this).parent().submit(); // Auto-submit the form if needed
}
}
// Allow backspace, left arrow, and right arrow keys
if (e.keyCode === 8 || e.keyCode === 37 || e.keyCode === 39) {
return;
}
// Allow only numeric characters
if (e.which < 48 || e.which > 57) {
e.preventDefault();
}
});
});
// تنظیم maxlength برای input در موبایل
if (typeof jQuery !== 'undefined') {
jQuery(document).ready(function($) {
const autofillInput = $('#autofill-input');
if (autofillInput.length) {
autofillInput.attr('maxlength', 6);
}
});
}