PNG
IHDR ; IDATxܻn0K
)(pA7LeG{ §㻢|ذaÆ
6lذaÆ
6lذaÆ
6lom$^yذag5 bÆ
6lذaÆ
6lذa{
6lذaÆ
`}HFkm,mӪôô!x|'ܢ˟;E:9&ᶒ}{v]n&6
h_tڠ͵-ҫZ;Z$.Pkž)!o>}leQfJTu іچ\X=8Rن4`Vwl>nG^is"ms$ui?wbs[m6K4O.4%/bC%tMז -lG6mrz2s%9s@-k9=)kB5\+͂ZsٲRn~GRCwIcIn7jJhۛNCS|j08yiHKֶۛkɈ+;SzL /F*\Ԕ#"5m2[S=gnaPeғL
lذaÆ
6l^ḵaÆ
6lذaÆ
6lذa;
_ذaÆ
6lذaÆ
6lذaÆ
R IENDB`
var softaculous_temp_data = {};
var softaculous_pro_show_themes_loaded = 0;
var softaculous_image_loading_page = 1;
var softaculous_next_step_loading = false;
var softaculous_pro_onboarding_errors = false;
var softaculous_pro_stop_progress = false;
var softaculous_pro_last_progress_cache = null;
var softaculous_pro_last_req_time = 0;
var softaculous_pro_ajax_progress_var = 0;
const softwp_onboarding_lang = {
conf_data_loss: "Please confirm that you accept data loss since you have already run the onboarding process previously",
select_atleast_one: "Please select atleast one page to import",
downloading_installing_plugins: "Downloading and installing required plugins",
wordpress_require_ftp: "WordPress requires FTP details, without them you won't be able to install a plugin/theme",
downloading_template: "Downloading the template",
buildWebsite: "Building your website...",
checkRequirements: "Checking the requirements ...",
importTemplate: "Importing the template",
setupCompleted: "Your website setup is completed",
congratulations: "Congratulations"
};
jQuery(document).ready(function(){
let url = new URL(window.location.href);
let step = url.searchParams.get('step');
if(step == 'start' || !step){
softaculous_pro_set_mode();
}
// softaculous_pro_onboarding_progress();
if(step === 'import_theme'){
jQuery('.softaculous-pro-wizard-sidebar').addClass('compact');
jQuery('.softaculous-pro-setup-logo').hide();
jQuery('.active_step').find('span').css('min-width', '0');
softaculous_pro_the_themes_window();
}
var feature_holder = jQuery('.softaculous-pro-features');
feature_holder.each(function(){
var feature_checked = jQuery(this).find('input').is(":checked");
if(feature_checked){
jQuery(this).addClass("feature-border");
}
});
feature_holder.click(function(){
var feature_disabled = jQuery(this).find('input').is(":disabled");
if(feature_disabled && !jQuery(this).hasClass("spro-erro")){
var selected_erro = jQuery(this).find('input').attr('spro-erro');
const para = jQuery('
'+selected_erro+'
').css('color', 'red');
jQuery(this).find('.softaculous-pro-features-text').find('p').replaceWith(para);
jQuery(this).addClass("spro-erro");
}
});
if(jQuery('.softaculous-pro-wizard').length > 0){
window.addEventListener('popstate', function(event){
// Get the current URL
let url = new URL(window.location.href);
let step = url.searchParams.get('step');
if(step){
softaculous_pro_set_active_step(step);
}
// When using forward or back button in browser
if(step === 'images'){
// This will ensure that the theme is always loaded when coming from the images
softaculous_pro_show_themes_loaded = 0;
jQuery('.softaculous-switch-template-mode .active_mode').removeClass('active_mode');
if(softaculous_ai_config.suggested_tags.length > 0){
jQuery('.softaculous-search-images').val(softaculous_ai_config.suggested_tags[0]).trigger('input');
}
}
if(step === 'import_theme'){
softaculous_pro_the_themes_window();
}
});
}
// Ensure that it should also work in js
jQuery(".softaculous-pro-wizard-steps a").each(function () {
const stepOrder = ["start", "contact", "features", "images", "import_theme"];
let click_ele = jQuery(this);
click_ele.on("click", function (e) {
let description = jQuery('#softaculous-business-desc').val();
const click_step = click_ele.children("span").data("step");
if (description.length < 300) {
e.preventDefault();
}
});
});
jQuery(document).on('click', '.softaculous-alert-dismissable', function(){
jQuery(this).parent().remove();
})
softaculous_pro_ai_start_handler();
softaculous_pro_ai_image_handler(step);
softaculous_pro_ai_description_handler();
// Onboarding template js
softaculous_pro_templates_fn(jQuery);
if(softaculous_pro_setup_info && softaculous_pro_setup_info.type){
softaculous_pro_setup_info.type = softaculous_pro_setup_info.type.replace("-", "");
jQuery('#cat_button_'+softaculous_pro_setup_info.type).trigger("click");
}
jQuery(window).on('resize', function(){
if( !('is_maunal' in softaculous_pro_setup_info) || softaculous_pro_setup_info['is_maunal'] == false){
softaculous_pro_scaleIframe();
softaculous_pro_scaleSingleTemplate();
}
});
jQuery('.softaculous-switch-template-mode div').on('click', function(){
var ele = jQuery(this);
var mode = ele.data('mode');
if(ele.hasClass('active_mode')){
return;
}
jQuery('.active_mode').removeClass('active_mode');
ele.addClass('active_mode');
if(mode == 'manual'){
jQuery('#softaculous-pro-templates').attr('data-type', 'manual').empty();
softaculous_ai_config.template_mode = 'manual';
}else{
jQuery('#softaculous-pro-templates').attr('data-type', 'ai').empty();
softaculous_ai_config.template_mode = 'ai';
}
jQuery.ajax({
type: 'post',
url: softaculous_pro_ajax_url + 'act=new_ai_site&api=json&action=softaculous_switch_template_mode',
data: {
mode: mode,
}
});
softaculous_pro_the_themes_window();
})
jQuery('.softaculous-pro-add-social').on('click', function(){
var sibl_ele = jQuery(this).siblings('div.softaculous-pro-social-links-profile');
sibl_ele.toggle();
})
softaculous_pro_import_scroll();
});
function softaculous_pro_set_mode(){
var ai_desc = jQuery("#softaculous-ai-description-field");
softaculous_ai_config.template_mode = jQuery('#softaculous-ai-mode').is(':checked') ? 'ai' : 'manual';
if(softaculous_ai_config.template_mode == 'manual'){
ai_desc.hide();
}else{
ai_desc.show();
}
}
function softaculous_pro_the_themes_window(){
if(!softaculous_pro_show_themes_loaded){
if(softaculous_ai_config.template_mode == 'manual'){
//jQuery('.softaculous-switch-template-mode div[data-mode="manual"]').trigger('click');
softaculous_pro_show_manual_themes();
}else{
//jQuery('.softaculous-switch-template-mode div[data-mode="ai"]').trigger('click');
softaculous_pro_show_themes();
}
}
softaculous_pro_import_scroll();
}
function softaculous_pro_set_active_step(step) {
// Active Tab
jQuery('.softaculous-pro-steps-holder ol li').removeClass('active_step');
if(step ==='import_theme'){
jQuery('.softaculous-pro-steps-holder ol li [data-step="'+step+'"]').closest('li').addClass('active_step');
jQuery('.softaculous-pro-wizard-sidebar').addClass('compact');
jQuery('.softaculous-pro-setup-logo').hide();
jQuery('.active_step').find('span').css('min-width', '0');
}else{
jQuery('.softaculous-pro-wizard-sidebar').removeClass('compact');
jQuery('.softaculous-pro-setup-logo').show();
jQuery('.softaculous-pro-steps-holder ol li [data-step="'+step+'"]').closest('li').addClass('active_step');
}
// Active Panel
jQuery('.softaculous-pro-wizard .softaculous-pro-wizard-content').attr('data-active-panel', step);
}
function softaculous_pro_next_handler(element){
jQuery('.softaculous-pro-error-incounter').remove();
softaculous_next_step_loading = true;
jQuery('.next-handler-icon').hide();
jQuery('.softaculous-next-loading').show();
jQuery(element).siblings('.step_prev_btn').css({
'pointer-events': 'none'
})
var ele = jQuery(element);
var nextStep = ele.data('step');
var currentStep = ele.closest('[data-panel]').data('panel');
var post_data = null;
if(softaculous_ai_config.template_mode == 'manual' && nextStep == 'images'){
nextStep = 'import_theme';
}
if(currentStep === 'start'){
if(jQuery("#onboarding_done_confirm").length > 0 && !jQuery("#onboarding_done_confirm").is(":checked")){
jQuery('.softaculous-next-loading').hide();
jQuery('.next-handler-icon').show();
alert(softwp_onboarding_lang.conf_data_loss);
return false;
}
var business_lang = jQuery('.softaculous-content #locale').val();
let { descriptions, desc_active } = softaculous_ai_config;
var description = descriptions[desc_active];
if(softaculous_ai_config.template_mode == 'ai' && description.trim().length < 200){
softaculous_next_step_loading = false;
jQuery('.softaculous-pro-description-error').show();
jQuery('.softaculous-next-loading').hide();
jQuery('.next-handler-icon').show();
jQuery(`[data-panel=${currentStep}]`).find('.step_prev_btn').css({
'pointer-events': 'all'
})
//jQuery(element).attr('disabled', 'disabled');
return;
}
jQuery('.softaculous-pro-description-error').hide();
//jQuery(element).removeAttr('disabled');
post_data = {
protocol: jQuery('#softproto').val(),
domain: jQuery('#softdomain').val(),
subdir: jQuery('#subdir').val(),
business_title: jQuery('#softaculous-site-name').val(),
business_type: jQuery('#softaculous-business-type').val(),
mode: softaculous_ai_config.template_mode,
business_lang: business_lang && business_lang.length === 0 ? 'en' : business_lang,
active_desc: desc_active,
business_description: softaculous_ai_config.template_mode == 'ai' ? descriptions : []
};
}
if(currentStep === 'contact'){
var email = jQuery('#softaculous-site-email').val();
var phone = jQuery('#softaculous-site-phone').val();
var address = jQuery('#softaculous-site-address').val();
// Social links
var socials = ["facebook", "twitter", "instagram", "linkedin", "youtube"];
post_data = {
business_email: email,
business_phone: phone,
business_address: address
};
// Loop through socials
socials.forEach(function(social) {
post_data["business_social_" + social] = jQuery("#softaculous-site-social-" + social).val();
});
}
if(currentStep === 'features'){
var selected_feats = [];
var feature_holder = jQuery('.softaculous-pro-features');
feature_holder.each(function(){
var feature_checked = jQuery(this).find('input').is(":checked");
if(feature_checked){
var selected_feat = jQuery(this).attr('data-slug');
selected_feats.push(selected_feat);
}
});
post_data = {features: selected_feats, step: currentStep};
}
if(currentStep == 'images'){
softaculous_pro_show_themes_loaded = 0
jQuery('.softaculous-switch-template-mode .active_mode').removeClass('active_mode');
post_data = {selected_images : softaculous_ai_config.selected_images, step: currentStep}
}
if(nextStep === 'images'){
var description = jQuery('#softaculous-business-desc').val();
// Do this according to the active_description
if(description.length < 200){
jQuery('.softaculous-ai-warning').show();
return;
}else{
jQuery('.softaculous-ai-warning').hide();
}
softaculous_pro_get_specific_info('image_suggestions');
if(softaculous_ai_config.suggested_tags.length > 0){
jQuery('.softaculous-search-images').val(softaculous_ai_config.suggested_tags[0]).trigger('input');
}
}
if(post_data){
jQuery.ajax({
type: 'post',
url: softaculous_pro_ajax_url + 'act=new_ai_site&api=json&action=softaculous_pro_setup_info',
data: {
step: currentStep,
data: post_data,
},
success: function (response) {
var res = JSON.parse(response);
if('success' in res){
if('setup_info' in res) {
softaculous_save_temparary_data(res.setup_info); // this will flatten and save
}
let currentUrl = window.location.href;
// Get the current URL
let url = new URL(currentUrl);
// Add a query parameter
url.searchParams.set('step', nextStep);
// Replace the current URL without refreshing the page
window.history.pushState({ path: currentUrl }, '', url);
softaculous_pro_set_active_step(nextStep);
jQuery('.softaculous-pro-steps-holder ol li').removeClass('active_step');
jQuery('.softaculous-pro-steps-holder ol li [data-step="'+nextStep+'"]').closest('li').addClass('active_step');
jQuery('.next-handler-icon').show();
jQuery('.softaculous-next-loading').hide();
softaculous_next_step_loading = false;
if(nextStep === 'import_theme'){
if('setup_info' in res){
softaculous_pro_setup_info['theme_pid'] = res['setup_info']['theme_pid'];
}
softaculous_pro_the_themes_window();
}
// Cache the templates: Only hit the URLs
if ('preview_urls' in res.setup_info && typeof res.setup_info.preview_urls === 'object') {
jQuery.ajax({
type: 'post',
url: softaculous_pro_ajax_url + 'act=new_ai_site&api=json&action=softaculous_pro_cache_iframe_urls',
timeout: 5000, // 5 seconds timeout
data: {
urls: res.setup_info.preview_urls,
},
success: function (response) {
console.log('Iframe cache URLs sent successfully');
},
error: function (xhr) {
console.log('AJAX error:', xhr.responseText);
}
});
}
}else{
softaculous_next_step_loading = false;
jQuery('.softaculous-next-loading').hide();
jQuery('.next-handler-icon').show();
jQuery(`[data-panel=${currentStep}]`).find('.step_prev_btn').css({
'pointer-events': 'all'
})
softaculous_pro_error_html(res?.error || undefined , currentStep)
}
},
error:function (response){
softaculous_next_step_loading = false;
jQuery('.softaculous-next-loading').hide();
jQuery('.next-handler-icon').show();
jQuery(`[data-panel=${currentStep}]`).find('.step_prev_btn').css({
'pointer-events': 'all'
})
softaculous_pro_error_html(response?.statusText || undefined , currentStep)
}
});
}
}
var softaculous_pro_cache_stream_iframes = {}
function softaculous_pro_stream_iframes(preview_urls, pid, element) {
if(typeof preview_urls === 'object' && Object.keys(preview_urls).length < 1){
return;
}
const formData = new FormData();
formData.append('action', 'softaculous_pro_stream_iframes');
formData.append('urls', JSON.stringify(preview_urls)); // ensure it's a string
fetch(softaculous_pro_ajax_url + 'act=new_ai_site&api=json&action=softaculous_pro_stream_iframes', {
method: 'POST',
body: formData,
})
.then(response => response.body.getReader())
.then(reader => {
const decoder = new TextDecoder();
let buffer = '';
function processChunk(text) {
buffer += text;
const lines = buffer.split('\n');
buffer = lines.pop(); // keep the last partial line
for (const line of lines) {
if (line.startsWith('DATA::')) {
const data = JSON.parse(line.replace('DATA::', ''));
// console.log(data);
if('error' in data){
console.log('Error Loading demos' + data.error);
return;
}
// console.log(data);
// Create blob for iframe src
const blob = new Blob([data.html], { type: 'text/html' });
const blobUrl = URL.createObjectURL(blob);
const slug = data.slug;
if(!(pid in softaculous_pro_cache_stream_iframes)){
softaculous_pro_cache_stream_iframes[pid] = {};
}
if(!(slug in softaculous_pro_cache_stream_iframes[pid])){
softaculous_pro_cache_stream_iframes[pid][slug] = {};
}
softaculous_pro_cache_stream_iframes[pid][slug][data.page] = blobUrl;
// Also support for pages
var iframe = jQuery(element).find(`iframe[data-slug="${slug}"][data-page="${data.page}"]`);
if(iframe.length < 1){
iframe = jQuery(element).find(`iframe[data-slug="${slug}"]`);
}
iframe.attr('src', blobUrl);
iframe.closest('.softaculous-pro-theme-details').find('a.softaculous-pro-ai-show-demo').attr('href', blobUrl);
}
}
}
function read() {
reader.read().then(({ done, value }) => {
if (done) return;
processChunk(decoder.decode(value, { stream: true }));
read();
});
}
read();
});
}
function softaculous_pro_prev_handler(element) {
var ele = jQuery(element);
var currentStep = ele.closest('[data-panel]').data('panel');
var prevStep = ele.data('step');
let currentUrl = window.location.href;
let url = new URL(currentUrl);
if(!softaculous_next_step_loading) {
jQuery(`[data-panel=${prevStep}]`).find('.step_prev_btn').css({
'pointer-events': 'all'
})
}
url.searchParams.set('step', prevStep);
window.history.pushState({ path: currentUrl }, '', url);
softaculous_pro_set_active_step(prevStep);
jQuery('.softaculous-pro-steps-holder ol li').removeClass('active_step');
jQuery('.softaculous-pro-steps-holder ol li [data-step="'+prevStep+'"]').closest('li').addClass('active_step');
}
function softaculous_pro_selected_features(element) {
var ele_parent = jQuery(element).parent().parent();
if(jQuery(element).is(":checked")){
ele_parent.addClass("feature-border");
}else{
ele_parent.removeClass("feature-border");
}
}
function softaculous_pro_modal(sel, ai_installation = false){
var page_names = [];
jQuery('.softaculous_pro_img_screen').each(function() {
var is_selected = jQuery(this).find('input').is(':checked');
if(is_selected){
var page_name = jQuery(this).attr('page-name');
}
page_names.push(page_name);
});
page_names.forEach(function(value) {
var input = jQuery('').attr('type', 'hidden').attr('name', 'to_import[]').val(value);
jQuery('#softaculous-pro-import-form').append(input);
});
if(page_names.length == 0){
alert(softwp_onboarding_lang.select_atleast_one);
} else{
jQuery(".softaculous-pro-wizard-inner[data-panel='import_theme']").hide();
var modal = jQuery(sel);
modal.show();
modal.find('.softaculous-pro-done').hide();
modal.find('.softaculous-pro-import').show();
var spro_temp_form_data = jQuery('#softaculous-pro-import-form').serialize();
softaculous_pro_handle_templates(spro_temp_form_data, ai_installation);
}
}
function softaculous_pro_handle_templates(spro_temp_form_data, ai_installation = false ){
jQuery('#softaculous-pro-templates-holder').remove();
jQuery('#SproTemplatesModal').hide();
var message = softwp_onboarding_lang.checkRequirements;
// softaculous_pro_create_html(message, 10, true); // Start progress at 1%
softaculous_pro_create_html(message, 1, true);
// softaculous_pro_onboarding_progress();
jQuery.ajax({
url: softaculous_pro_ajax_url + 'act=new_ai_site&api=json&action=softaculous_pro_start_install_template',
type: 'POST',
data: spro_temp_form_data,
success: function(response){
if(!response.success && response.data && response.data.form){
softaculous_handle_ftp_form(response.data.form, spro_temp_form_data);
return;
}
// Install plugin gives too much output, hence match the data
var data = response.match(/(.*?)<\/softaculous\-pro\-xmlwrap>/is);
if(data){
data = data[1];
}
data = JSON.parse(data);
softaculous_pro_download_template(data, spro_temp_form_data, ai_installation);
},
error: function(jqXHR, textStatus, errorThrown){
softaculous_pro_show_error({err: 'AJAX failure ! Status : '+textStatus+' | Error : '+errorThrown});
}
});
}
function softaculous_pro_selected_plugin(data, spro_temp_form_data, ai_installation=false){
if(typeof data === 'object' && 'error' in data){
softaculous_pro_show_error(data['error']);
return false;
}
var message = softwp_onboarding_lang.downloading_installing_plugins;
// softaculous_pro_onboarding_progress();
jQuery.ajax({
url: softaculous_pro_ajax_url+'act=new_ai_site&api=json&action=softaculous_pro_selected_plugin_install',
type: 'POST',
data: {
spro_data : spro_temp_form_data + '&ai_installation='+ ai_installation,
site : JSON.stringify(data['site']),
insid: data['insid']
},
dataType: 'json',
success: function(data){
softaculous_pro_download_template(data, spro_temp_form_data, ai_installation);
},
error: function(jqXHR, textStatus, errorThrown){
softaculous_pro_show_error({err: 'AJAX failure ! Status : '+textStatus+' | Error : '+errorThrown});
}
})
}
function softaculous_pro_download_template(data, spro_temp_form_data, ai_installation=false){
var failed = [];
if(typeof data === 'object' && 'error' in data){
softaculous_pro_show_error(data['error']);
return false;
}
if(typeof data === 'object' && 'failed_plugin' in data){
failed.push(data['failed_plugin']);
}
var message = softwp_onboarding_lang.downloading_template;
// Make the call
jQuery.ajax({
url: softaculous_pro_ajax_url + 'act=new_ai_site&api=json&action=softaculous_pro_download_template',
type: 'POST',
data: {
spro_data : spro_temp_form_data + '&ai_installation='+ ai_installation,
site : JSON.stringify(data['site']),
insid: data['insid']
},
dataType: 'json',
success: function(data){
data.failed_plugin = failed;
softaculous_pro_import_template(data, spro_temp_form_data, ai_installation);
},
error: function(jqXHR, textStatus, errorThrown){
softaculous_pro_show_error({err: 'AJAX failure ! Status : '+textStatus+' | Error : '+errorThrown});
}
});
}
function softaculous_handle_ftp_form(form, form_data){
// Handling FTP Form
jQuery('body').append(form);
var ftp_modal = jQuery('#request-filesystem-credentials-dialog');
ftp_modal.show();
// Handling the close btn of the FTP form.
ftp_modal.find('.cancel-button').on('click', function(event){
event.preventDefault();
ftp_modal.hide();
alert(softwp_onboarding_lang.wordpress_require_ftp);
});
ftp_modal.on('submit', 'form', function(event){
event.preventDefault();
let serialized_data = jQuery(event.target).serialize();
form_data += '&'+serialized_data;
ftp_modal.hide();
softaculous_pro_handle_templates(form_data);
});
}
// Generate post
function softaculous_pro_generate_post(){
var post_data = {
site_name : jQuery('#softaculous-site-name').val(),
description : jQuery('#softaculous-business-desc').val(),
}
jQuery.ajax({
type: 'post',
url: softaculous_pro_ajax_url + 'act=new_ai_site&api=json&action=softaculous_pro_generate_post',
data: {
data: post_data,
},
success: function(response) {
// console.log(response);
}
});
}
// Import template
function softaculous_pro_import_template(data, spro_temp_form_data, ai_installation= false){
if(typeof data === 'object' && 'error' in data){
softaculous_pro_show_error(data['error']);
return false;
}
var message = softwp_onboarding_lang.importTemplate;
// if(ai_installation){
// softaculous_pro_generate_post();
// }
// Make the calls
jQuery.ajax({
url: softaculous_pro_ajax_url + 'act=new_ai_site&api=json&action=softaculous_pro_import_template',
type: 'POST',
data: spro_temp_form_data + '&ai_installation='+ ai_installation + '&key=' + data['key'] + '&insid='+data['insid'],
dataType: 'json',
success: function(data){
var modal = jQuery('.progress-bar');
softaculous_pro_selected_plugin(data, spro_temp_form_data, ai_installation);
if(typeof data === 'object' && 'error' in data){
softaculous_pro_show_error(data['error']);
return false;
}
if(typeof data === 'object' && 'done' in data){
console.log('You are all set');
}
},
error: function(jqXHR, textStatus, errorThrown){
softaculous_pro_show_error({err: 'AJAX failure ! Status : '+textStatus+' | Error : '+errorThrown});
}
});
}
function softaculous_pro_show_error(err){
// Stop the ajax for progress
softaculous_pro_stop_progress_calls();
var html = '
Error
';
for(var x in err){
html += '
'+err[x]+'
';
}
html += '
';
jQuery('.softaculous-pro-wizard-content').append(html);
jQuery('#softaculous-pro-error-template').html(html).show();
jQuery('.spro-progress-bar').hide();
}
function softaculous_pro_create_html(message, finalPercentage, slowAnimation, logs) {
// TODO : Call an AJAX to get the progress
// Check if progress bar already exists
var progressBar = jQuery('.spro-progress-bar');
if (progressBar.length > 0) {
// Update the message and animate the progress
jQuery('.progress-indicator').text(message);
softaculous_pro_animateProgress(progressBar.find('.progress-float-r'), progressBar.find('.setup-progress-counter'), finalPercentage, slowAnimation);
} else {
// Create the progress bar
var html = `
');
});
}
}
var softProAnimProgressInterval = {};
function softaculous_pro_animateProgress($progressText, $progressBar, finalPercentage, slowAnimation) {
var currentPercentage = parseInt($progressText.text());
var increment = 1;
var duration = 10;
if (slowAnimation) {
duration = 100;
}
clearInterval(softProAnimProgressInterval);
softProAnimProgressInterval = setInterval(function() {
if (currentPercentage >= finalPercentage) {
clearInterval(softProAnimProgressInterval);
} else {
currentPercentage += increment;
$progressText.text(currentPercentage + '%');
$progressBar.animate({ width: currentPercentage + '%' }, duration).css('background-color', 'blue');
}
}, duration);
}
// Start step handler
function softaculous_pro_ai_start_handler(){
jQuery('#softaculous-business-type').on('focus', function() {
jQuery('.softaculous-category-holder').show();
var generated_list = jQuery('.softaculous-pro-categories-dropdownlist');
if(jQuery(this).val().trim().length < 1){
jQuery('.softaculous-pro-categories-dropdownlist').html('');
jQuery('.softaculous-pro-categories-default-dropdownlist').show();
}else if(jQuery(this).val().trim().length > 3 && generated_list.is(':empty')){
softaculous_pro_render_autocomplete(jQuery(this).val().trim());
}
});
var typeTimer;
jQuery('#softaculous-business-type').on('keyup', function() {
var search = jQuery(this).val().toLowerCase();
if(search.length > 3){
clearTimeout(typeTimer);
typeTimer = setTimeout(function() {
softaculous_pro_render_autocomplete(search);
}, 200);
jQuery('.clear-btn').show();
jQuery('.softaculous-pro-categories-default-dropdownlist').hide();
}else{
jQuery('.softaculous-pro-categories-dropdownlist').html('');
jQuery('.softaculous-pro-categories-default-dropdownlist').show();
jQuery('.clear-btn').hide();
}
});
jQuery(document).on('click.soft_category_btn', '.softaculous-category_btn', function() {
let selectedText = jQuery(this).text().trim();
jQuery('#softaculous-business-type').val(selectedText);
jQuery('.softaculous-category-holder').hide();
jQuery('.clear-btn').show();
});
jQuery('.clear-btn').on('click', function() {
jQuery('#softaculous-business-type').val('');
jQuery('.clear-btn').hide();
jQuery('.softaculous-category-holder').show();
jQuery('.softaculous-pro-categories-default-dropdownlist').show();
});
jQuery(document).on('click', function(e) {
if (!jQuery(e.target).closest('.softaculous-dropdown').length) {
jQuery('.softaculous-category-holder').hide();
}
});
}
// Image step handler
function softaculous_pro_ai_image_handler(step){
var imgHolder = jQuery('.softaculous-pro-wizard-inner[data-panel="images"]');
if(softaculous_ai_config.suggested_tags.length > 0 && step === 'images'){
let imageInterval = setInterval(() => {
let image_input = jQuery('.softaculous-search-images');
if (image_input.length) {
image_input.val(softaculous_ai_config.suggested_tags[0]).trigger('input');
clearInterval(imageInterval);
}
}, 100);
}
jQuery('.softaculous-ai-images-suggestions button').on('click', function(){
var bEle = jQuery(this);
if(bEle.hasClass('softaculous-upload-image') || bEle.hasClass('active')){
return;
}
bEle.parent().find('.active').removeClass('active');
bEle.addClass('active');
jQuery('.softaculous-ai-images-rows, .softaculous-selected-images-rows').removeClass('softaculous-active-section');
if(bEle.data('slug') === 'selected_image'){
jQuery('.softaculous-selected-images-rows').addClass('softaculous-active-section');
}else{
jQuery('.softaculous-ai-images-rows').addClass('softaculous-active-section');
}
});
imgHolder.on('click', '.softaculous-ai-single-image', function(){
var imgEle = jQuery(this);
var img_id = String(imgEle.data('id')); // Ensure it's a string
var isChecked = imgEle.find('.softaculous-ai-checkbox').prop('checked');
var image_url = imgEle.find('img').attr('src');
if(!isChecked){
imgEle.removeClass('selected');
softaculous_ai_config.selected_images = softaculous_ai_config.selected_images.filter(img => String(img.image_id) !== img_id);
softaculous_pro_update_image_count();
} else {
imgEle.addClass('selected');
var img_obj = { image_id: img_id, image_url: image_url };
softaculous_ai_config.selected_images = softaculous_ai_config.selected_images.filter(img => String(img.image_id) !== img_id);
softaculous_ai_config.selected_images.push(img_obj);
softaculous_pro_update_image_count();
}
softaculous_pro_update_images();
});
// Upload images
jQuery(".softaculous-upload-image").click(function (e) {
var par = jQuery(this).parent();
e.preventDefault();
var mediaUploader = wp.media({
title: "Select Image",
button: {
text: "Use this Image"
},
multiple: false
});
mediaUploader.on("select", function () {
var attachment = mediaUploader.state().get("selection").first().toJSON();
var image_id = String(attachment.id);
var image_url = attachment.url;
var img_obj = {image_id: image_id , image_url: image_url};
softaculous_ai_config.selected_images.push(img_obj);
softaculous_pro_update_images();
softaculous_pro_update_image_count();
jQuery('.softaculous-selected-images-rows').prepend(softaculous_image_upload_message());
jQuery('.softaculous-ai-images-suggestions [data-slug="selected_image"]').click();
setTimeout(function () {
jQuery('.softaculous-pro-image-success').fadeOut(500, function () { jQuery(this).remove(); });
}, 4000);
});
mediaUploader.open();
});
imgHolder.on('click', '.softaculous-remove-selected', function(){
var element = jQuery(this);
var img_element = element.siblings('img');
var image_id = img_element.attr('data-selected-id');
var ai_images = jQuery('.softaculous-ai-images-rows');
softaculous_ai_config.selected_images = softaculous_ai_config.selected_images.filter(function(img) {
return !img.image_id || img.image_id != image_id;
});
softaculous_pro_update_image_count();
element.closest('.softaculous-selected-image').remove();
ai_images.find('label.softaculous-ai-single-image').each(function() {
var element_id = jQuery(this).data('id');
if(element_id == image_id){
jQuery(this).removeClass('selected');
}
});
if (softaculous_ai_config.selected_images.length < 1) {
jQuery('.softaculous-selected-images-rows').html(`
You have not selected any image.
`);
}
});
let debounceTimer;
jQuery('.softaculous-search-images').on('input', function(){
softaculous_image_loading_page = 1;
clearTimeout(debounceTimer);
let search_query = jQuery(this).val();
debounceTimer = setTimeout(function(){
jQuery('.softaculous-ai-images-suggestions [data-slug="suggested_image"]').click();
softaculous_generate_pexel_images(search_query, true);
}, 600);
});
jQuery('.softaculous-search-images').on('click', function(){
// Need to check if the sugesstions empty or not
var parent = jQuery(this).closest('.softaculous-ai-image-search');
if(!parent.hasClass('show_suggestion') && softaculous_ai_config.suggested_tags.length > 0){
parent.addClass('show_suggestion');
parent.find('.softaculous-ai-image-suggestion-list').show();
}
});
jQuery(document).on('click', function(e) {
if (!jQuery(e.target).closest('.softaculous-ai-image-search').length) {
jQuery('.softaculous-ai-image-search').removeClass('show_suggestion');
jQuery('.softaculous-ai-image-suggestion-list').hide();
}
});
imgHolder.on('click', '.softaculous_pro_suggestion', function(){
var element = jQuery(this);
jQuery('.softaculous-search-images').val(element.text()).trigger('input');
});
softaculous_pro_images_scrolled();
}
// Description step handler
function softaculous_pro_ai_description_handler(){
const buildPagination = (action = 'last') => {
let { descriptions, desc_active } = softaculous_ai_config;
// Remove empty entry from the array
if (descriptions[0].length <= 0) {
descriptions.splice(0, 1);
}
let index = action === 'next' ? desc_active + 1 : action === 'prev' ? desc_active - 1 : descriptions.length - 1;
index = Math.max(0, Math.min(index, descriptions.length - 1));
softaculous_ai_config.desc_active = index;
jQuery('#softaculous-business-desc').val(descriptions[index]);
jQuery('.softaculous-ai-pagination .currently_active').text(`${index + 1} / ${descriptions.length}`);
};
jQuery('.softaculous-ai-pagination .active-next-handler, .softaculous-ai-pagination .active-prev-handler').on('click', function () {
buildPagination(jQuery(this).hasClass('active-next-handler') ? 'next' : 'prev');
});
jQuery('#softaculous-business-desc').on('blur', function () {
let { descriptions, desc_active } = softaculous_ai_config;
softaculous_ai_config.descriptions[desc_active] = jQuery(this).val();
});
jQuery('.softaculous-ai-svg').on('click', function(){
var post_data = {
site_name : jQuery('#softaculous-site-name').val(),
site_category : jQuery('#softaculous-business-type').val(),
site_language : jQuery('#locale').val(), // TODO: change name
description : jQuery('#softaculous-business-desc').val(),
}
jQuery.ajax({
type: 'post',
url: softaculous_pro_ajax_url + 'act=new_ai_site&api=json&action=softaculous_pro_ai_description',
data: {
data: post_data,
},
beforeSend: function(){
jQuery(".softaculous-ai-svg").addClass('softaculous-ai-loading');
},
success: function(response) {
var res = JSON.parse(response);
if (res && res.description && res.description.length > 0) {
softaculous_ai_config.descriptions.push(res.description);
buildPagination();
} else {
jQuery('.softaculous-pro-description-error').hide();
softaculous_pro_error_html(res?.error || undefined , 'description')
}
},
error: function(response) {
jQuery('.softaculous-pro-description-error').hide();
softaculous_pro_error_html(response?.statusText || undefined , 'description')
},
complete:function(){
jQuery(".softaculous-ai-svg").removeClass('softaculous-ai-loading');
}
});
});
}
function softaculous_pro_update_images() {
let html = softaculous_ai_config.selected_images.length > 0 ? softaculous_ai_config.selected_images.map(img => {
// var wp_img_url = wp.media.attachment(img.image_id).get('url');
var wp_img_url = false;
if (wp_img_url) {
return `
✖
`;
} else {
return `
✖
`;
}
}).join('')
: `
You have not selected any image.
`;
jQuery('.softaculous-selected-images-rows').html(html);
}
var softaculous_pexel_images_loading = false;
function softaculous_generate_pexel_images(query = '', is_search = false) {
var search_query = query || "software";
var per_page = 40;
if(softaculous_pexel_images_loading) return;
softaculous_pexel_images_loading = true;
if(is_search){
jQuery(".softaculous-ai-images-rows").html('');
}
for (let i = 0; i < per_page; i++) {
jQuery(".softaculous-ai-images-rows").append(
``
);
}
jQuery.ajax({
type: 'GET',
url: softaculous_pro_ajax_url + 'act=new_ai_site&api=json&action=softaculous_pro_search_images',
data: {
query: search_query,
per_page: per_page,
page: softaculous_image_loading_page
},
success: function(response) {
var res = JSON.parse(response);
if('error' in res){
softaculous_pro_error_html(res?.error || undefined , 'images')
return;
}
if(!res.images){
softaculous_pro_error_html("Unable to get the image for some reason, please try again!" , 'images')
return;
}
var images_obj = JSON.parse(res.images);
jQuery(".softaculous-ai-single-image").slice(-per_page).each(function(index) {
var photo = images_obj.photos[index];
if (photo) {
var selected_images = softaculous_ai_config.selected_images.some(img => img.image_id == photo.id);
var selected_class = selected_images ? "selected" : "";
var imageHtml = `
Photo by ${photo.photographer} on Pexels`;
jQuery(this).attr("data-id", photo.id).addClass(selected_class).html(imageHtml);
}
});
softaculous_image_loading_page++;
},
complete: function() {
softaculous_pexel_images_loading = false;
},
error: function(response){
softaculous_pro_error_html(response?.statusText || undefined , 'images')
}
});
}
// We can use this function for getting any ai info option value
function softaculous_pro_get_specific_info(slug = '') {
jQuery.ajax({
type: 'POST',
url: softaculous_pro_ajax_url + 'act=new_ai_site&api=json&action=softaculous_pro_get_setup_info',
data: {
slug: slug,
},
success: function (response) {
if(response){
if(slug === 'image_suggestions'){
var res = JSON.parse(response);
softaculous_pro_render_new_suggestions(res);
if(res.length > 0){
jQuery('.softaculous-search-images').val(res[0]).trigger('input');
softaculous_pro_images_scrolled();
}
}
}
},
error: function (error) {
console.error(error)
}
});
}
function softaculous_pro_render_new_suggestions(data){
// Dump new data to the softaculous_ai_config.suggested_tags varible
softaculous_ai_config.suggested_tags = data
var html = '';
data.forEach(function(item){
html += `${item}`
});
jQuery('.softaculous-ai-image-suggestions').html(html);
}
// Using js Because this is much more faster than php
function softaculous_pro_render_autocomplete(val='') {
val = val || '';
jQuery.ajax({
type: 'POST',
url: softaculous_pro_ajax_url + 'act=new_ai_site&api=json&action=softaculous_pro_ai_autocomplete',
data: {
val: val,
},
success: function (response) {
var result = JSON.parse(response);
var html = '';
if (result && 'tags' in result) {
result['tags'].forEach((item) => {
html += `
${item}
`;
});
jQuery('.softaculous-pro-categories-dropdownlist ').html(html);
} else {
softaculous_pro_error_html(result?.error || undefined , 'start')
}
},
error: function (error) {
softaculous_pro_error_html(error?.statusText || undefined , 'start')
}
});
}
function softaculous_pro_images_scrolled(){
// This is previous code wrap inside the function
setTimeout(()=>{
jQuery("[data-active-panel=images]").on("scroll" ,function() {
var container = jQuery(this);
var scrollTop = container.scrollTop();
var containerHeight = container.innerHeight();
var contentHeight = container[0].scrollHeight;
var total_images = jQuery('.softaculous-ai-images-rows label').length;
if (scrollTop + containerHeight >= contentHeight - 100 && total_images < 320) {
let search_value = jQuery('.softaculous-search-images').val();
softaculous_generate_pexel_images(search_value);
}
if (total_images >= 320 && jQuery('.softaculous-pro-images-end').length === 0) {
var html = '
End of search results...
';
jQuery('.softaculous-ai-images-rows').append(html);
}
});
}, 200);
}
// Error handling need to improve further.
function softaculous_pro_error_html(error = 'There has been an error. Please reinitiate the onboarding process or refresh.', ele) {
jQuery('.softaculous-pro-error-incounter').remove();
softaculous_pro_onboarding_errors = true;
var error_html = `
${error}
`;
jQuery(`[data-panel=${ele}]`).find('.softaculous-pro-wizard-inner-content').append(error_html);
}
function softaculous_image_upload_message(){
var html =`
Image(s) selected successfully
`;
return html;
}
// Onboarding template JS functions
function softaculous_pro_update_cat_input(other_cat){
jQuery('#cat_input').val(other_cat);
}
function softaculous_pro_templates_fn($){
// Back button handler
jQuery('.softaculous-pro-back').click(function(){
if(softaculous_ai_config.template_mode == 'manual'){
softaculous_pro_show_manual_themes(softaculous_pro_setup_info.type !== undefined ? softaculous_pro_setup_info.type.toLowerCase() : '');
}else{
softaculous_pro_show_themes();
}
jQuery("#spro_import_content").hide();
jQuery(".softaculous-pro-back").hide();
softaculous_pro_scaleIframe();
});
jQuery('.softaculous-pro-back-theme').click(function(){
jQuery('#softaculous-pro-templates-holder').show();
jQuery(this).parent().hide();
jQuery('#SproTemplatesModal').hide();
});
jQuery('#cat_input').keyup(function() {
var query = jQuery(this).val().toLowerCase();
var cat_displayed = 0;
jQuery(".category_btn").each(function( index ){
var cslug = jQuery(this).find("input").attr("data-target");
if(cslug.toLowerCase().includes(query)){
jQuery(this).show();
cat_displayed++;
}else{
jQuery(this).hide();
}
if(cat_displayed > 0){
jQuery("#spro_no_cat_results").hide();
}else{
jQuery("#spro_no_cat_results").show();
}
});
});
// Show categories on click
jQuery('.softaculous-pro-categories').on('click', function(){
jQuery('.softaculous-pro-dropdown-content').toggle();
jQuery(document).on('click', function (e) {
if (!jQuery(e.target).closest('.softaculous-pro-categories, .softaculous-pro-dropdown-content').length) {
jQuery('.softaculous-pro-dropdown-content').hide();
}
});
})
// Fill the categories
var chtml = '
All
';
for(var x in categories){
chtml += '
'+categories[x]['en']+'
';
}
jQuery('.softaculous-pro-cat-holder').html(chtml);
jQuery('.softaculous-pro-cat-holder').find('.softaculous-pro-cat').click(function(){
softaculous_pro_show_manual_themes(jQuery(this).data('cat'));
});
jQuery('.softaculous-pro-categories-list').find('.category_btn').click(function(){
var childEle = jQuery(this).children('input');
var jEle_parent = jQuery(this).parent().find(".active_category");
var real_val = jQuery(this).children('input').val();
var val = jQuery(this).children('input').val().toLowerCase();
var inputSection = jQuery(".softaculous-pro-category-input");
if (jQuery(this).hasClass("active_category")) {
jQuery(this).removeClass("active_category");
inputSection.find('input').val('')
return;
}
jEle_parent.removeClass("active_category");
jQuery(this).addClass("active_category");
if(real_val){
inputSection.find('input').val(real_val)
}
softaculous_pro_show_manual_themes(val);
});
// Search Clear
jQuery('.softaculous-pro-sf-empty').click(function(){
jQuery('.softaculous-pro-search-field').val('');
softaculous_pro_the_themes_window();
});
// Search
var softacProThemeTimeout = {};
jQuery('.softaculous-pro-search-field').on('keyup', function(e){
var iEle = jQuery(this);
clearTimeout(softacProThemeTimeout);
softacProThemeTimeout = setTimeout(function(){
if(softaculous_ai_config.template_mode == 'manual'){
softaculous_pro_show_manual_themes('', iEle.val());
}else{
softaculous_pro_show_themes('', iEle.val());
}
}, 300);
});
// Sort themes
jQuery('.softaculous-pro-sortby').change(function(){
softaculous_pro_show_manual_themes(jQuery('.softaculous-pro-current-cat').data('cat'), jQuery('.softaculous-pro-search-field').val());
});
};
// Show the themes
var softaculousAiLoadedPages = [];
function softaculous_pro_show_themes(cat, search, page){
if (jQuery('#softaculous-pro-templates').is(':empty')) {
softaculousAiLoadedPages = [];
softaculous_pro_pending_iframeCount = 0
}
softaculous_pro_show_themes_loaded = 1;
page = page || 1 ;
var sortby = '';
jQuery("#softaculous_pro_search").hide();
jQuery("#softaculous_pro_theme_title").show();
jQuery("#softaculous-pro-suggestion").hide();
jQuery("#softaculous-pro-single-template").hide();
jQuery("#softaculous-pro-templates").show();
jQuery('.softaculous-pro-single-template-header').hide();
jQuery('.softaculous-pro-categories').hide();
jQuery('.softaculous-pro-ai-search').removeClass('manual-mode');
if(search == undefined || search.length < 1){
if (softaculousAiLoadedPages.includes(page)) {
return;
}
softaculousAiLoadedPages.push(page)
}
var search = search || "";
var cat = "";
var num = 12;
var start = num * (page - 1);
var end = num + start;
var i = 0;
var allowed_list = [];
var pid = softaculous_pro_setup_info['theme_pid'] ? softaculous_pro_setup_info['theme_pid']: '';
var html = '';
if(pid.length < 1){
jQuery('#softaculous-pro-templates').html('');
html += `
There has been error loading themes please refresh the page or start onboarding process from start or you can procced with the manual mode.
`
jQuery('#softaculous-pro-templates').append(html);
jQuery('.softaculous-pro-theme-loading').hide();
return;
}
jQuery('.softaculous-pro-wizard-error').remove();
jQuery('.softaculous-pro-theme-loading').show();
if(search.length > 0){
jQuery("#softaculous-pro-templates").html('');
search = search.toLowerCase();
for(var x in softaculous_pro_templates['tags']){
if(x.toLowerCase().indexOf(search) >= 0){
allowed_list = allowed_list.concat(softaculous_pro_templates['tags'][x]);
}
}
}
if(allowed_list.length > 0){
allowed_list = Array.from(new Set(allowed_list));
}
var sorted = {};
var rsorted = {};
themes = softaculous_pro_templates['ai_list'];
var theme_counter = start + 1;
var pid = ('theme_pid' in softaculous_pro_setup_info) ? softaculous_pro_setup_info['theme_pid']: '';
var preview_urls = {};
for(var x in themes){
// Is it a searched item
if(search.length > 0 && themes[x].name.toLowerCase().indexOf(search) === -1 && allowed_list.indexOf(themes[x].thid) === -1){
continue;
}
if(i >= start && i < end){
softaculous_pro_show_theme_tile(themes[x], x, theme_counter);
if(
pid in softaculous_pro_cache_stream_iframes &&
x in softaculous_pro_cache_stream_iframes[pid] &&
'home' in softaculous_pro_cache_stream_iframes[pid][x]
){
var iframe = jQuery('#softaculous-pro-templates').find(`iframe[data-slug="${x}"]`);
var blob = softaculous_pro_cache_stream_iframes[pid][x]['home'];
iframe.attr('src', blob);
iframe.closest('.softaculous-pro-theme-details').find('a.softaculous-pro-ai-show-demo').attr('href', blob);
}else{
preview_urls[x] = x;
}
softaculous_pro_pending_iframeCount++;
theme_counter++;
}
i++;
}
// Stream iframes urls
softaculous_pro_stream_iframes(preview_urls, pid, jQuery('#softaculous-pro-templates'));
jQuery('.softaculous-pro-theme-details').click(function(){
softaculous_pro_scaleIframe();
var jEle = jQuery(this);
if(jEle.find('.softaculous-pro-skeleton-loading').length > 0){
return;
}
softaculous_pro_show_theme_details(jEle.attr('slug'));
// jQuery('#softaculous-pro-single-template').attr('data-slug', jEle.attr('slug'));
//Prevent inside click
jQuery('.softaculous_pro_display_iframe').on('load', function () {
var iframe = jQuery(this).contents();
iframe.on('click', function (e) {
e.preventDefault();
});
});
});
var pages = Math.ceil(i/num);
// Render after 2 sec to let append everything
softaculous_pro_iframe_loadtimeout = setTimeout(() => {
softaculous_pro_pending_iframeCount = 0;
}, 120000); // 2 minutes
setTimeout(() => {
softaculous_pro_scaleIframe();
}, 2000);
}
function softaculous_pro_show_theme_tile(theme, x, theme_counter) {
var html = '