// ! If input label click
$('.input-label').click(function () {
$(this).children('input').trigger('focus');
});
$(document).ready(function () {
if ($('html').attr("lang") === "ar") {
signupHtml = "
تم إرسال رابط لتفعيل الحساب إلى صندوق الوارد الخاص بك.
"
resetH1 = "إعادة تعيين كلمة المرور"
resetHtml = "إذا كان الحساب موجودًا ، فسنرسل إليك تعليمات عبر البريد الإلكتروني لتعيين كلمة المرور.
إذا لم تتلق بريدًا إلكترونيًا، فيرجى التأكد من إدخال العنوان الذي سجلت به، وتحقق من مجلد الرسائل غير المرغوب فيها."
successSignUp = "تم انشاء الحساب"
} else {
signupHtml = "Account successfully created.
Verification link has been sent to your inbox.
"
resetH1 = "Password reset"
resetHtml = "If the account exists we will email you instructions for setting your password shortly.
If you don’t receive an email, please make sure you’ve entered the address you registered with, and check your spam folder."
successSignUp = "Account created"
}
reloadRecaptcha("login");
$(".login_slide a").click(function () {
$(".img_box").animate({
left: "50%"
}, "slow", "swing");
$('.login_form').fadeOut(500, function () {
$('.signup_form').fadeIn(500);
$("#id_first_name").focus();
});
reloadRecaptcha("signup");
})
$(".signup_slide a").click(function () {
$(".img_box").animate({
left: "0"
}, "slow", "swing");
$(".loading").animate({
left: "50%"
}, "slow", "swing");
$('.signup_form').fadeOut(500, function () {
$('.login_form').fadeIn(500);
$("#login_form #login_email").focus();
});
reloadRecaptcha("login");
})
$(".forgot-password").click(function () {
$(".login_form").fadeOut(500, function () {
$(".reset_container").fadeIn(500);
$(".reset_container #reset_form #reset_email").focus();
});
reloadRecaptcha("reset_password");
})
$(".reset_container i").click(function () {
$(".reset_container").fadeOut(500, function () {
$(".login_form").fadeIn(500);
$("#login_form #login_email").focus();
});
reloadRecaptcha("login");
})
// {# Login Form Ajax #}
const $loginForm = $("#login_form")
$loginForm.submit(function (event) {
event.preventDefault()
const $loginForm_data = $(this).serialize()
// {# Remove repeated icon and text #}
$("#submit_login").attr("disabled", true).append('').css("background", "rgb(39 159 115)");
$("#login_form .error").remove();
$("#login_form .success").remove();
$('input').css("border", "");
$.ajax({
method: "POST",
url: $(this).attr("action"),
data: $loginForm_data,
dataType: 'json',
success: function (data) {
$('#submit_login .fa-spin').remove()
$("#submit_login").css(
"background", "").attr("disabled", false);
if (data.message == 'Success') {
location.href = path + "account/";
} else {
let json;
$.each(data, function (key, item) {
json = $.parseJSON(item);
});
if (json.hasOwnProperty('__all__')) {
$('.forgot-password').after(
"* " + json
.__all__[0]
.message +
"");
}
if (json.hasOwnProperty('email')) {
$('.login_form .input-label:eq(0) .label-inside')
.after(
"* " + json
.email[
0]
.message +
"");
$('.login_form .input-label:eq(0) input').css(
"border", "1px solid red");
}
if (json.hasOwnProperty('password')) {
$('.login_form .input-label:eq(1) .label-inside')
.after(
"* " + json
.password[0]
.message +
"");
$('.login_form .input-label:eq(1) input').css(
"border", "1px solid red");
}
if (json.hasOwnProperty('login_recaptcha')) {
$('.forgot-password').after(
"* " + json
.login_recaptcha[0]
.message +
"");
}
// {# Reinitialize recaptcha #}
reloadRecaptcha("login");
}
}
})
})
// {# Signup Form Ajax #}
const $signupForm = $(".signup_form")
$signupForm.submit(function (event) {
event.preventDefault()
const $signupForm_data = $(this).serialize()
// {# Remove repeated icon and text #}
$("#submit_signup").attr("disabled", true).append('').css("background", "rgb(39 159 115)");
$(".signup_form .error").remove();
$('input').css("border", "");
$.ajax({
method: "POST",
url: $(this).attr("action"),
data: $signupForm_data,
dataType: 'json',
success: function (data) {
$('#submit_signup .fa-spin').remove()
$("#submit_signup").css("background", "").attr("disabled", false);
if (data.message == 'Success') {
setTimeout(function () {
// {# Fade out form and show success message #}
$(".signup_form").fadeOut(500, function () {
$(".signup_form .input-label")
.remove();
$(".signup_form hr:last")
.remove();
$(".signup_form .check-terms")
.remove();
$('#submit_signup').remove();
$(".signup_form h1").text(
successSignUp);
$('.signup_form .signup_slide ')
.before(
signupHtml
);
$(".signup_form").fadeIn(500);
});
}, 1000)
} else {
let json;
$.each(data, function (key, item) {
json = $.parseJSON(item);
});
if (json.hasOwnProperty('first_name')) {
$('.signup_form .input-label:eq(0) .label-inside')
.after(
"* " + json
.first_name[0]
.message +
"");
$('.signup_form .input-label:eq(0) input').css(
"border", "1px solid red");
}
if (json.hasOwnProperty('last_name')) {
$('.signup_form .input-label:eq(1) .label-inside')
.after(
"* " + json
.last_name[0]
.message +
"");
$('.signup_form .input-label:eq(1) input').css(
"border", "1px solid red");
}
if (json.hasOwnProperty('email')) {
$('.signup_form .input-label:eq(2) .label-inside')
.after(
"* " + json
.email[
0]
.message +
"");
$('.signup_form .input-label:eq(2) input').css(
"border", "1px solid red");
}
if (json.hasOwnProperty('password1')) {
$('.signup_form .input-label:eq(3) .label-inside')
.after(
"* " + json
.password1[0]
.message +
"");
$('.signup_form .input-label:eq(3) input').css(
"border", "1px solid red");
}
if (json.hasOwnProperty('password2')) {
$('.signup_form .input-label:eq(4) .label-inside')
.after(
"* " + json
.password2[0]
.message +
"");
$('.signup_form .input-label:eq(4) input').css(
"border", "1px solid red");
}
if (json.hasOwnProperty('signup_terms_agreement')) {
$('.signup_form .check-terms').before(
"* " + json
.signup_terms_agreement[0]
.message +
"");
}
if (json.hasOwnProperty('signup_recaptcha')) {
$('.signup_form .check-terms').after(
"* " + json
.signup_recaptcha[0]
.message +
"");
}
// {# Reinitialize recaptcha #}
reloadRecaptcha("signup");
}
}
})
})
// {# Reset Password Form Ajax #}
const $resetForm = $("#reset_form")
$resetForm.submit(function (event) {
event.preventDefault()
const $resetForm_data = $(this).serialize()
// {# Remove repeated icon and text #}
$("#submit_reset").attr("disabled", true).append('').css("background", "rgb(39 159 115)");
$("#reset_form .error").remove();
$('input').css("border", "");
$.ajax({
method: "POST",
url: $(this).attr("action"),
data: $resetForm_data,
dataType: 'json',
success: function (data) {
$('#submit_reset .fa-spin').remove()
$("#submit_reset").css(
"background", "").attr("disabled", false);
if (data.message == 'Success') {
setTimeout(function () {
$(".reset_container").fadeOut(500,
function () {
$("#reset_form .input-label")
.remove();
$("#reset_form h1").text(
resetH1);
$("#reset_form span:first")
.html(
resetHtml
);
$("#submit_reset").remove()
$(".reset_container").fadeIn(
500);
});
}, 1000)
} else {
let json;
$.each(data, function (key, item) {
json = $.parseJSON(item);
});
if (json.hasOwnProperty('email')) {
$('#reset_form .input-label .label-inside').after(
"* " + json
.email[0]
.message +
"");
$('#reset_form .input-label:eq(0) input').css(
"border", "1px solid red");
}
if (json.hasOwnProperty('reset_recaptcha')) {
$('#reset_form .input-label').after(
"* " + json
.reset_recaptcha[0]
.message +
"");
}
// {# Reinitialize recaptcha #}
reloadRecaptcha("reset_password");
}
}
})
})
})