| @@ -6,61 +6,19 @@ | ||
| 6 | 6 | * @package Visualizer |
| 7 | 7 | */ |
| 8 | 8 | /* jshint unused:false */ |
| 9 | 9 | jQuery(function ($) { |
| 10 | - | |
| 11 | - /** | |
| 12 | - * Check if the user is in live preview mode. | |
| 13 | - * Live Preview is used in WordPress Playground to test the plugin. | |
| 14 | - * Use this check to deactivate any process that does not showcase the plugin features (e.g. subscription to the newsletter, etc.) | |
| 15 | - * | |
| 16 | - * @type {boolean} | |
| 17 | - */ | |
| 18 | - const isLivePreview = window.location.search.includes('env=preview'); | |
| 19 | - | |
| 20 | - /** | |
| 21 | - * Redirect to draft page after subscribe (optional). | |
| 22 | - * | |
| 23 | - * @param {Object} postData - Post data. | |
| 24 | - */ | |
| 25 | - const goToDraftPage = function ( postData = {} ) { | |
| 26 | - postData ??= {}; | |
| 27 | - postData.action ??= 'visualizer_wizard_step_process'; | |
| 28 | - postData.security ??= visualizerSetupWizardData.ajax.security; | |
| 29 | - postData.step ??= 'step_subscribe'; | |
| 30 | - | |
| 31 | - // Subscribe the user using the email if provided. Redirect to the draft page. | |
| 32 | - $.post(visualizerSetupWizardData.ajax.url, postData, function (res) { | |
| 33 | - | |
| 34 | - // Toggle the redirect popup. | |
| 35 | - $('.redirect-popup').find('h3.popup-title').html(res.message); | |
| 36 | - $('.redirect-popup').show(); | |
| 37 | - | |
| 38 | - if (1 === res.status) { | |
| 39 | - setTimeout(function () { | |
| 40 | - window.location.href = res.redirect_to; | |
| 41 | - }, 5000); | |
| 42 | - } else { | |
| 43 | - $('.redirect-popup').hide(); | |
| 44 | - } | |
| 45 | - currentStep.find('.spinner').removeClass('is-active'); | |
| 46 | - }).fail(function () { | |
| 47 | - $('.redirect-popup').hide(); | |
| 48 | - currentStep.find('.spinner').removeClass('is-active'); | |
| 49 | - }); | |
| 50 | - } | |
| 51 | - | |
| 52 | 10 | var provideContent = function(id, stepDirection, stepPosition, selStep, callback) { |
| 53 | 11 | // Import chart data. |
| 54 | 12 | if ( 1 == id ) { |
| 55 | 13 | var chartType = $(".vz-radio-btn:checked").val(); |
| 56 | - var percentBarWidth = 0; | |
| 14 | + var percentBarWidth = 100; | |
| 57 | 15 | var loaderDelay; |
| 58 | 16 | $.ajax( { |
| 59 | 17 | beforeSend: function() { |
| 60 | 18 | loaderDelay = setInterval(function () { |
| 61 | 19 | $('.vz-progress-bar').css({ |
| 62 | - width: percentBarWidth++ + '%' | |
| 20 | + width: percentBarWidth-- + '%' | |
| 63 | 21 | }); |
| 64 | 22 | }, 1000); |
| 65 | 23 | }, |
| 66 | 24 | type: 'POST', |
| @@ -75,11 +33,11 @@ | ||
| 75 | 33 | success: function (data) { |
| 76 | 34 | clearInterval( loaderDelay ); |
| 77 | 35 | loaderDelay = setInterval(function () { |
| 78 | 36 | $('.vz-progress-bar').css({ |
| 79 | - width: percentBarWidth++ + '%' | |
| 37 | + width: percentBarWidth-- + '%' | |
| 80 | 38 | }); |
| 81 | - if ( percentBarWidth >= 100 ) { | |
| 39 | + if ( percentBarWidth <= 0 ) { | |
| 82 | 40 | if ( 1 === data.success ) { |
| 83 | 41 | var importMessage = jQuery('[data-import_message]'); |
| 84 | 42 | importMessage |
| 85 | 43 | .html( importMessage.data('import_message') ) |
| @@ -94,16 +52,13 @@ | ||
| 94 | 52 | } else { |
| 95 | 53 | $('#smartwizard').smartWizard('reset'); |
| 96 | 54 | } |
| 97 | 55 | $('.vz-progress-bar').css({ |
| 98 | - width: 100 + '%' | |
| 56 | + width: 0 | |
| 99 | 57 | }); |
| 100 | - $('.vz-progress').css({ | |
| 101 | - visibility: 'hidden' | |
| 102 | - }); | |
| 103 | 58 | clearInterval( loaderDelay ); |
| 104 | 59 | } |
| 105 | - }, 36 ); | |
| 60 | + }, 100 ); | |
| 106 | 61 | }, |
| 107 | 62 | error: function() { |
| 108 | 63 | $('#step-2').find('.vz-progress-bar').animate({ width: '0' }); |
| 109 | 64 | } |
| @@ -163,9 +118,8 @@ | ||
| 163 | 118 | "click", |
| 164 | 119 | ".btn-primary:not(.next-btn,.vz-create-page,.vz-subscribe)", |
| 165 | 120 | function (e) { |
| 166 | 121 | var stepNumber = $(this).data("step_number"); |
| 167 | - | |
| 168 | 122 | switch (stepNumber) { |
| 169 | 123 | case 1: |
| 170 | 124 | if ($(".vz-radio-btn").is(":checked")) { |
| 171 | 125 | $('#smartwizard').smartWizard('next'); |
| @@ -171,16 +125,12 @@ | ||
| 171 | 125 | $('#smartwizard').smartWizard('next'); |
| 172 | 126 | } |
| 173 | 127 | break; |
| 174 | 128 | case 3: |
| 175 | - if ( isLivePreview ) { | |
| 176 | - $('#smartwizard').smartWizard('next'); | |
| 177 | - } else { | |
| 178 | - var urlParams = new URLSearchParams(window.location.search); | |
| 179 | - urlParams.set('preview_chart', Date.now()); | |
| 180 | - window.location.hash = "#step-3"; | |
| 181 | - window.location.search = urlParams; | |
| 182 | - } | |
| 129 | + var urlParams = new URLSearchParams(window.location.search); | |
| 130 | + urlParams.set('preview_chart', Date.now()); | |
| 131 | + window.location.hash = "#step-3"; | |
| 132 | + window.location.search = urlParams; | |
| 183 | 133 | break; |
| 184 | 134 | case 4: |
| 185 | 135 | $('#step-4').find('.spinner').addClass('is-active'); |
| 186 | 136 | $('#step-4').find('.vz-error-notice').addClass('hidden'); |
| @@ -230,13 +180,9 @@ | ||
| 230 | 180 | add_basic_shortcode: $("#insert_shortcode").is(":checked"), |
| 231 | 181 | }, |
| 232 | 182 | function (res) { |
| 233 | 183 | if (res.status > 0) { |
| 234 | - if ( isLivePreview ) { | |
| 235 | - goToDraftPage(); | |
| 236 | - } else { | |
| 237 | - $("#smartwizard").smartWizard("next"); | |
| 238 | - } | |
| 184 | + $("#smartwizard").smartWizard("next"); | |
| 239 | 185 | } |
| 240 | 186 | _this.next(".spinner").removeClass("is-active"); |
| 241 | 187 | } |
| 242 | 188 | ).fail(function () { |
| @@ -288,9 +234,23 @@ | ||
| 288 | 234 | } |
| 289 | 235 | var currentStep = $( '.vz-wizard-wrap .tab-pane:last-child' ); |
| 290 | 236 | currentStep.find(".spinner").addClass("is-active"); |
| 291 | 237 | |
| 292 | - goToDraftPage( postData ); | |
| 238 | + $.post(visualizerSetupWizardData.ajax.url, postData, function (res) { | |
| 239 | + $('.redirect-popup').find('h3.popup-title').html(res.message); | |
| 240 | + $('.redirect-popup').show(); | |
| 241 | + if (1 === res.status) { | |
| 242 | + setTimeout(function () { | |
| 243 | + window.location.href = res.redirect_to; | |
| 244 | + }, 5000); | |
| 245 | + } else { | |
| 246 | + $('.redirect-popup').hide(); | |
| 247 | + } | |
| 248 | + currentStep.find('.spinner').removeClass('is-active'); | |
| 249 | + }).fail(function () { | |
| 250 | + $('.redirect-popup').hide(); | |
| 251 | + currentStep.find('.spinner').removeClass('is-active'); | |
| 252 | + }); | |
| 293 | 253 | e.preventDefault(); |
| 294 | 254 | }); |
| 295 | 255 | |
| 296 | 256 | // Click to copy. |