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; 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(); } 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: soft_pro_obj.ajax_url, data: { action: 'softaculous_switch_template_mode', mode: mode, softaculous_pro_nonce: softaculous_pro_ajax_nonce, } }); softaculous_pro_the_themes_window(); }) jQuery('.softaculous-pro-add-social').on('click', function(){ jQuery(this).siblings('.softaculous-pro-social-links-profile').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 = { business_title: jQuery('#softaculous-site-name').val(), business_type: jQuery('#softaculous-business-type').val(), mode: softaculous_ai_config.template_mode, 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} } 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'); } } // TODO go to next on success // Save the current URL if(post_data){ jQuery.ajax({ type: 'post', url: soft_pro_obj.ajax_url, data: { action: 'softaculous_pro_setup_info', step: currentStep, softaculous_pro_nonce: softaculous_pro_ajax_nonce, data: post_data, }, success: function (response) { var res = JSON.parse(response); if('success' in res){ 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: soft_pro_obj.ajax_url, timeout: 5000, // 5 seconds timeout data: { action: 'softaculous_pro_cache_iframe_urls', softaculous_pro_nonce: softaculous_pro_ajax_nonce, 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('softaculous_pro_nonce', softaculous_pro_ajax_nonce); formData.append('urls', JSON.stringify(preview_urls)); // ensure it's a string fetch(soft_pro_obj.ajax_url, { 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 = []; var selected_theme = jQuery('#softaculous-pro-import-form [name=theme]').val(); themes = softaculous_pro_templates['list']; if(softaculous_lic_type_is_free && selected_theme in themes && themes[selected_theme].type > 0 ){ alert(softwp_onboarding_lang.pro_template); return; } 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 && !sitepad_is_dev){ 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% jQuery.ajax({ url: softaculous_pro_ajax_url+'action=softaculous_pro_start_install_template', type: 'POST', data: spro_temp_form_data+'&softaculous_pro_nonce='+softaculous_pro_ajax_nonce, 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(/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: soft_pro_obj.ajax_url, data: { action: 'softaculous_pro_ai_description', softaculous_pro_nonce: softaculous_pro_ajax_nonce, 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') if (wp_img_url) { return `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: soft_pro_obj.ajax_url, data: { action: 'softaculous_pro_search_images', softaculous_pro_nonce: softaculous_pro_ajax_nonce, 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; } jQuery(".softaculous-ai-single-image").slice(-per_page).each(function(index) { var photo = res.images.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 = `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}
Image(s) selected successfully
There has been error loading themes please refresh the page or start onboarding process from start or you can procced with the manual mode.
'+
'