');
$redirect.prop("required", true);
});
});
$("#user_registration_login_options_prevent_core_login").on(
"change",
function () {
var $url = $("#user_registration_login_options_prevent_core_login");
$(".single_select_page").toggle();
$("#user_registration_login_options_login_redirect_url").prop(
"required",
function () {
return "checked" === $url.prop("checked") ? true : false;
}
);
}
);
// Display the sync profile picture settings when the disable profile picture is checked and advanced fields is active.
$("#user_registration_disable_profile_picture").on("change", function () {
var is_advanced_fields_active = parseInt(
user_registration_settings_params.is_advanced_field_active
);
if ($(this).prop("checked") && is_advanced_fields_active === 1) {
$("#user_registration_sync_profile_picture")
.closest(".user-registration-global-settings")
.css("display", "flex");
} else {
$("#user_registration_sync_profile_picture").prop("checked", false);
$("#user_registration_sync_profile_picture")
.closest(".user-registration-global-settings")
.css("display", "none");
}
});
// If not checked on load hide the sync profile picture settings.
$("#user_registration_sync_profile_picture").ready(function () {
$this = $("#user_registration_sync_profile_picture");
if ($this.prop("checked")) {
$this
.closest(".user-registration-global-settings")
.css("display", "flex");
} else if (
$("#user_registration_disable_profile_picture").prop("checked") &&
parseInt(
user_registration_settings_params.is_advanced_field_active
) === 1
) {
$this
.closest(".user-registration-global-settings")
.css("display", "flex");
} else {
$this
.closest(".user-registration-global-settings")
.css("display", "none");
}
});
// Change span with file name when user selects a file.
$(".user-registration-custom-file__input").on("change", function () {
var file = $(".user-registration-custom-file__input").prop("files")[0];
$(".user-registration-custom-selected-file").html(file.name);
});
$(".ur-image-uploader").on("click", function (e) {
ur_uploader = $(this);
e.preventDefault();
var image = wp
.media({
library: {
type: ["image"]
},
title: ur_uploader.upload_file,
// multiple: true if you want to upload multiple files at once
multiple: false
})
.open()
.on("select", function (e) {
// This will return the selected image from the Media Uploader, the result is an object
var uploaded_image = image.state().get("selection").first();
// We convert uploaded_image to a JSON object to make accessing it easier
var image_url = uploaded_image.toJSON().url;
// Let's assign the url value to the input field
ur_uploader.attr("src", image_url);
if (ur_uploader.hasClass("ur-button")) {
ur_uploader.siblings("img").show();
ur_uploader.siblings("img").attr("src", image_url);
ur_uploader
.siblings("#user_registration_pdf_logo_image")
.val(image_url);
ur_uploader.hide();
ur_uploader.siblings(".ur-image-remover").show();
} else {
ur_uploader.attr("src", image_url);
ur_uploader
.siblings("#user_registration_pdf_logo_image")
.val(image_url);
}
});
});
$(".ur-image-remover").on("click", function (e) {
var ur_remover = $(this);
e.preventDefault();
ur_remover.siblings("img").attr("src", "");
ur_remover.siblings("#user_registration_pdf_logo_image").val("");
ur_remover.siblings(".ur-image-uploader").show();
ur_remover.hide();
ur_remover.siblings("img").hide();
});
// Handles radio images option click.
$(".radio-image")
.find("input")
.each(function () {
var $option_selector = $(this);
$option_selector.on("click", function () {
$(this).closest("ul").find("label").removeClass("selected");
$(this).closest("label").addClass("selected");
});
});
$(".user-registration #mainform").on("keyup keypress", function (e) {
var keyCode = e.keyCode || e.which;
if (keyCode === 13) {
e.preventDefault();
return false;
}
});
// Set up the autocomplete feature
$(".user-registration #ur-search-settings").autocomplete({
source: function (request, response) {
// Make an AJAX call to the PHP script with the search query as data
var search_string = request.term;
var form_data = new FormData();
form_data.append("search_string", search_string);
form_data.append(
"action",
"user_registration_search_global_settings"
);
form_data.append(
"security",
user_registration_settings_params.user_registration_search_global_settings_nonce
);
$(".user-registration-search-icon").hide();
$.ajax({
url: user_registration_settings_params.ajax_url,
dataType: "json", // what to expect back from the PHP script, if anything
cache: false,
contentType: false,
processData: false,
data: form_data,
type: "post",
complete: function (responsed) {
if (responsed.responseJSON.success === true) {
var results = responsed.responseJSON.data.results;
response(results);
}
$(".user-registration-search-icon").show();
}
});
},
classes: {
"ui-autocomplete": "user-registration-ui-autocomplete"
},
minLength: 3, // Minimum characters required to trigger autocomplete
focus: function (event, ui) {
$(".user-registration-ui-autocomplete > li").attr(
"title",
ui.item.desc
);
$("#ur-search-settings").val(ui.item.label);
return false;
},
select: function (event, ui) {
// Update the input field value with the selected value
if ("no_result_found" !== ui.item.value) {
$(".user-registration #ur-search-settings").val(ui.item.label);
// Redirect the user to the selected URL
window.location.href = ui.item.value;
}
return false; // Prevent the default behavior of the widget
}
});
// Display error when page with our my account or login shortcode is not selected
$(
"#user_registration_myaccount_page_id"
).on("change", function () {
var $this = $(this),
data = {
action: "user_registration_my_account_selection_validator",
security:
user_registration_settings_params.user_registration_my_account_selection_validator_nonce
};
data.user_registration_selected_my_account_page = $this.val();
$this.prop("disabled", true);
$this.css("border", "1px solid #e1e1e1");
$this
.closest(".user-registration-global-settings--field")
.find(".error.inline")
.remove();
$this
.closest(".user-registration-global-settings")
.append('');
$.ajax({
url: user_registration_settings_params.ajax_url,
data: data,
type: "POST",
complete: function (response) {
if (response.responseJSON.success === false) {
$this
.closest(".user-registration-global-settings--field")
.append(
"
" +
response.responseJSON.data.message +
"
"
);
$this.css("border", "1px solid red");
$this
.closest("form")
.find("input[name='save']")
.prop("disabled", true);
} else {
$this
.closest("form")
.find("input[name='save']")
.prop("disabled", false);
$this
.closest(".user-registration-global-settings").find('.error inline')
.remove();
}
$this.prop("disabled", false);
$this
.closest(".user-registration-global-settings")
.find(".ur-spinner")
.remove();
}
});
});
// Display error when page with our lost password shortcode is not selected.
$("#user_registration_lost_password_page_id").on("change", function () {
var $this = $(this),
data = {
action: "user_registration_lost_password_selection_validator",
security: ur_login_form_params.user_registration_lost_password_selection_validator_nonce
};
data.user_registration_selected_lost_password_page = $this.val();
$this.prop("disabled", true);
$this.css("border", "1px solid #e1e1e1");
$this.closest(".user-registration-global-settings--field").find(".error.inline").remove();
$.ajax({
url: ur_login_form_params.ajax_url,
data: data,
type: "POST",
complete: function (response) {
if (response.responseJSON.success === false) {
if ($this.closest(".user-registration-login-form-global-settings").find(".error.inline").length === 0) {
$this.closest(".user-registration-login-form-global-settings").append(
"
" +
response.responseJSON.data.message +
"
"
);
}
$this.css("border", "1px solid red");
var login_form = $this.closest('.user-registration-login-form-container');
$(login_form).closest('#wpbody-content').find('#ur-lists-page-topnav').find('button[name="save_login_form"]').prop("disabled", true);
} else {
var login_form = $this.closest('.user-registration-login-form-container');
$(login_form).closest('#wpbody-content').find('#ur-lists-page-topnav').find('button[name="save_login_form"]').prop("disabled", false);
$this.closest(".user-registration-login-form-global-settings").find(".error.inline").remove();
}
$this.prop("disabled", false);
}
});
});
// Set localStorage with expiry
function setStorageValue(key, value) {
var current = new Date();
var data = {
value: value,
expiry: current.getTime() + 86400000 // 1day of expiry time
};
localStorage.setItem(key, JSON.stringify(data));
}
// Get localStorage with expiry
function getStorageValue(key) {
var item = localStorage.getItem(key);
if (!item) {
return false;
}
var data = JSON.parse(item);
var current = new Date();
if (current.getTime() > data.expiry) {
localStorage.removeItem(key);
return false;
}
return true;
}
// Handles collapse of side menu.
$("#ur-settings-collapse").on("click", function (e) {
e.preventDefault();
if ($(this).hasClass("close")) {
$(this).closest("header").addClass("collapsed");
$(this).removeClass("close").addClass("open");
setStorageValue("ur-settings-navCollapsed", true); // set to localStorage
} else {
$(this).closest("header").removeClass("collapsed");
$(this).removeClass("open").addClass("close");
localStorage.removeItem("ur-settings-navCollapsed"); // remove from localStorage
}
});
// Persist the collapsable state through page reload
var isNavCollapsed =
getStorageValue("ur-settings-navCollapsed") === true
? "collapsed"
: "not-collapsed";
if (isNavCollapsed == "collapsed") {
$(".user-registration-header").addClass("collapsed");
$("#ur-settings-collapse").removeClass("close").addClass("open");
} else {
$(".user-registration-header").removeClass("collapsed");
$("#ur-settings-collapse").removeClass("open").addClass("close");
}
$(".ur-nav-premium").each(function () {
$(this).hover(
function (e) {
$(this).find(".ur-tooltip").show();
},
function (e) {
$(this).find(".ur-tooltip").hide();
}
);
});
/**
* Open collapsed menu on search input clicked.
*/
$(".ur-search-input").on("click", function () {
if (
$(this).closest(".user-registration-header").hasClass("collapsed")
) {
$(this)
.closest(".user-registration-header")
.removeClass("collapsed");
$(this)
.closest(".user-registration-header")
.find("#ur-settings-collapse")
.addClass("close");
$(this).find("#ur-search-settings").focus();
}
});
if (
typeof getUrlVars()["searched_option"] != "undefined" ||
getUrlVars()["searched_option"] != null
) {
var $searched_id = $("#" + getUrlVars()["searched_option"]);
var wrapper_div = $searched_id.closest(
".user-registration-global-settings"
);
wrapper_div.addClass("ur-searched-settings-focus");
var offset = $(".ur-searched-settings-focus").offset().top;
window.scrollTo({
top: offset - 300,
behavior: "smooth"
});
setTimeout(function () {
wrapper_div.removeClass("ur-searched-settings-focus");
}, 2000);
}
/**
* Get Query String.
*
* @returns
*/
function getUrlVars() {
var vars = [],
hash;
var hashes = window.location.href
.slice(window.location.href.indexOf("?") + 1)
.split("&");
for (var i = 0; i < hashes.length; i++) {
hash = hashes[i].split("=");
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
/**
* Display the upgrade message for the top addons.
*/
$("body").on("click", ".user-registration-inactive-addon", function (e) {
$this = $(this);
e.preventDefault();
var video_id = $this.data("video");
var plugin_title = $this.data("title");
var available_in = $(this).data("available-in");
var video = "";
if (video_id !== "") {
video =
' ';
}
var icon =
'';
var message =
video + user_registration_settings_params.i18n.upgrade_message;
message = message
.replace("%title%", plugin_title)
.replace("%plan%", available_in);
var title =
icon +
'' +
plugin_title +
" " +
user_registration_settings_params.i18n.pro_feature_title;
("");
Swal.fire({
title: title,
html: message,
customClass:
"user-registration-swal2-modal user-registration-swal2-modal--centered user-registration-locked-field",
showCloseButton: true,
showConfirmButton: true,
allowOutsideClick: true,
heightAuto: false,
width: "575px",
confirmButtonText:
user_registration_settings_params.i18n.upgrade_plan
}).then(function (result) {
if (result.isConfirmed) {
window.open(
user_registration_settings_params.i18n.upgrade_link,
"_blank"
);
}
});
});
$(document)
.find(".user-registration-global-settings--field")
.find(".ur-radio-group-list--item")
.each(function () {
$(this).on("click", function () {
$(this)
.closest(".ur-radio-group-list")
.find(".active")
.find("input")
.prop("checked", false);
$(this)
.closest(".ur-radio-group-list")
.find(".active")
.removeClass("active");
$(this).addClass("active");
$(this).find("input").prop("checked", true);
});
});
// Function to handle changes in the premium sidebar.
$(document).ready(function () {
function handleSettingsSidebar(node) {
var isCheckboxChecked = $(node).is(":checked");
localStorage.setItem("isSidebarEnabled", isCheckboxChecked);
document.cookie =
"isSidebarEnabled=" + isCheckboxChecked + "; path=/;";
if (isCheckboxChecked) {
$("body")
.removeClass("ur-settings-sidebar-hidden")
.addClass("ur-settings-sidebar-show");
$(node)
.closest(".user-registration-options-header--top__right")
.find(".user-registration-toggle-text")
.text("Sidebar");
} else {
$("body")
.removeClass("ur-settings-sidebar-show")
.addClass("ur-settings-sidebar-hidden");
$(node)
.closest(".user-registration-options-header--top__right")
.find(".user-registration-toggle-text")
.text("Sidebar");
}
}
$(document).on(
"change",
"#user_registration_hide_show_sidebar",
function (e) {
handleSettingsSidebar($(this));
}
);
disableFormChangeModal();
init_accordion_settings();
});
/**
* Initialize accordion_settings elements.
*/
function init_accordion_settings() {
var acc = document.getElementsByClassName("accordion");
var i;
for (i = 0; i < acc.length; i++) {
var panel = acc[i].nextElementSibling;
panel.style.display = "none";
acc[i].addEventListener("click", function () {
/* Toggle between adding and removing the "active" class,
to highlight the button that controls the panel */
this.classList.toggle("active");
/* Toggle between hiding and showing the active panel */
var panel = this.nextElementSibling;
if (panel.style.display === "block") {
panel.style.display = "none";
} else {
panel.style.display = "block";
}
});
}
$.each($(".ur-captcha-settings"), function () {
var is_enabled = $(this)
.find(".ur-captcha-settings-body .ur-captcha-enable")
.is(":checked");
if (is_enabled) {
$(this)
.find(".ur-captcha-settings-header .integration-status")
.addClass("ur-integration-account-connected");
}
});
}
/**
* Disable leave page before saving changes modal when hid/show sidebar is clicked.
*/
function disableFormChangeModal() {
var form = $(".user-registration").find("form")[0];
var formChanged = false;
$(form).on("change", function (event) {
if (event.target.name !== "user_registration_enable_sidebar") {
formChanged = true;
}
});
var skipBeforeUnloadPopup = false;
$(form).on("submit", function () {
skipBeforeUnloadPopup = true;
});
$(form)
.find(".ur-nav__link")
.on("click", function () {
skipBeforeUnloadPopup = true;
});
$(window).on("beforeunload", function (event) {
if (formChanged && !skipBeforeUnloadPopup) {
event.preventDefault();
event.returnValue = "";
} else {
event.stopImmediatePropagation();
}
});
}
$(document)
.find(".wp-list-table")
.wrap("");
$('#user_registration_member_registration_page_id, #user_registration_thank_you_page_id').on('change', function () {
var $this = $(this),
type = $this.attr('id'),
val = $(this).val();
// $this.prop("disabled", true);
$this.closest(".user-registration-global-settings--field").find('#select2-' + type + '-container').css('border', '1px solid #e1e1e1');
$this
.closest(".user-registration-global-settings--field")
.find(".error.inline")
.remove();
$this
.closest('.user-registration-global-settings')
.find('.ur-spinner')
.remove();
$this.closest('.user-registration-global-settings').append('');
$.ajax({
url: user_registration_settings_params.ajax_url,
data: {
action: 'user_registration_membership_verify_pages',
type: type,
value: val,
security: user_registration_settings_params.user_registration_membership_pages_selection_validator_nonce
},
type: "POST",
complete: function (response) {
if (response.responseJSON.status === false) {
$this
.closest(".user-registration-global-settings--field")
.append(
"