PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.10.7
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.10.7
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 All 149 releases
← All changes | js/setup-wizard.js +147 -283 4.0.33.10.7 View file →
@@ -6,190 +6,67 @@
6 6 * @package Visualizer
7 7 */
8 8 /* jshint unused:false */
9 9 jQuery(function ($) {
10 + var provideContent = function(id, stepDirection, stepPosition, selStep, callback) {
11 + // Import chart data.
12 + if ( 1 == id ) {
13 + var chartType = $(".vz-radio-btn:checked").val();
14 + var percentBarWidth = 100;
15 + var loaderDelay;
16 + $.ajax( {
17 + beforeSend: function() {
18 + loaderDelay = setInterval(function () {
19 + $('.vz-progress-bar').css({
20 + width: percentBarWidth-- + '%'
21 + });
22 + }, 1000);
23 + },
24 + type: 'POST',
25 + url: visualizerSetupWizardData.ajax.url,
26 + dataType: 'json',
27 + data: {
28 + action: 'visualizer_wizard_step_process',
29 + security: visualizerSetupWizardData.ajax.security,
30 + chart_type: chartType,
31 + step: 'step_2',
32 + },
33 + success: function (data) {
34 + clearInterval( loaderDelay );
35 + loaderDelay = setInterval(function () {
36 + $('.vz-progress-bar').css({
37 + width: percentBarWidth-- + '%'
38 + });
39 + if ( percentBarWidth <= 0 ) {
40 + if ( 1 === data.success ) {
41 + var importMessage = jQuery('[data-import_message]');
42 + importMessage
43 + .html( importMessage.data('import_message') )
44 + .addClass('import_message');
10 45
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 - const emailRegex = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
20 -
21 - var showNewsletterError = function ($input, message) {
22 - var $wrap = $input.closest('.vz-option-input');
23 - $wrap.next('.vz-field-error').remove();
24 - if (message) {
25 - $wrap.after('<span class="vz-field-error">' + message + '</span>');
26 - }
27 - };
28 -
29 - /**
30 - * Redirect to draft page after subscribe (optional).
31 - *
32 - * @param {Object} postData - Post data.
33 - */
34 - const goToDraftPage = function ( postData = {} ) {
35 - postData ??= {};
36 - postData.action ??= 'visualizer_wizard_step_process';
37 - postData.security ??= visualizerSetupWizardData.ajax.security;
38 - postData.step ??= 'step_subscribe';
39 -
40 - // Subscribe the user using the email if provided. Redirect to the draft page.
41 - var $currentStep = $('#step-3');
42 -
43 - $.post(visualizerSetupWizardData.ajax.url, postData, function (res) {
44 -
45 - // Toggle the redirect popup.
46 - $('.redirect-popup').find('h3.popup-title').html(res.message);
47 - $('.redirect-popup').show();
48 -
49 - if (1 === res.status) {
50 - setTimeout(function () {
51 - window.location.href = res.redirect_to;
52 - }, 5000);
53 - } else {
54 - $('.redirect-popup').hide();
55 - }
56 - $currentStep.find('.spinner').removeClass('is-active');
57 - }).fail(function () {
58 - $('.redirect-popup').hide();
59 - $currentStep.find('.spinner').removeClass('is-active');
60 - });
61 - }
62 -
63 - var runImport = function () {
64 - var chartType = $(".vz-radio-btn:checked").val();
65 - var percentBarWidth = 0;
66 - var loaderDelay;
67 - var $step = $('#step-1');
68 - var $status = $step.find('.vz-import-status');
69 - var $progress = $status.find('.vz-progress-bar');
70 - var $message = $status.find('[data-import_message]');
71 - var $error = $status.find('.vz-error-notice');
72 - var $spinner = $step.find('.spinner');
73 - var $button = $step.find('[data-step_number="1"]');
74 -
75 - $status.show();
76 - $progress.css({ width: '0' });
77 - if ($message.length) {
78 - $message
79 - .text($message.data('import_initial'))
80 - .removeClass('import_message');
81 - }
82 - $error.addClass('hidden').empty();
83 - $spinner.addClass('is-active');
84 - $button.addClass('disabled');
85 -
86 - loaderDelay = setInterval(function () {
87 - percentBarWidth = Math.min(percentBarWidth + 4, 90);
88 - $progress.css({ width: percentBarWidth + '%' });
89 - }, 120);
90 -
91 - $.ajax({
92 - type: 'POST',
93 - url: visualizerSetupWizardData.ajax.url,
94 - dataType: 'json',
95 - data: {
96 - action: 'visualizer_wizard_step_process',
97 - security: visualizerSetupWizardData.ajax.security,
98 - chart_type: chartType,
99 - step: 'step_2',
100 - },
101 - success: function (data) {
102 - clearInterval(loaderDelay);
103 - $progress.css({ width: '100%' });
104 -
105 - if (1 === data.success) {
106 - if (data.chart_id) {
107 - var $shortcode = $('#basic_shortcode');
108 - if ($shortcode.length) {
109 - $shortcode.val(
110 - $shortcode.val().replace('{{chart_id}}', data.chart_id)
111 - );
46 + $('#step-2').find('button.disabled').removeClass('disabled');
47 + } else if( 2 === data.status && '' !== data.message ) {
48 + $('#step-2')
49 + .find('.vz-error-notice')
50 + .html( '<p>' + data.message + '</p>' )
51 + .removeClass('hidden');
52 + } else {
53 + $('#smartwizard').smartWizard('reset');
54 + }
55 + $('.vz-progress-bar').css({
56 + width: 0
57 + });
58 + clearInterval( loaderDelay );
112 59 }
113 - }
114 - if ($message.length) {
115 - $message
116 - .text($message.data('import_message'))
117 - .addClass('import_message');
118 - }
119 -
120 - setTimeout(function () {
121 - $spinner.removeClass('is-active');
122 - $('#smartwizard').smartWizard('next');
123 - }, 200);
124 - } else if (2 === data.status && '' !== data.message) {
125 - $error.html('<p>' + data.message + '</p>').removeClass('hidden');
126 - $spinner.removeClass('is-active');
127 - $button.removeClass('disabled');
128 - } else {
129 - $spinner.removeClass('is-active');
130 - $button.removeClass('disabled');
131 - $('#smartwizard').smartWizard('reset');
60 + }, 100 );
61 + },
62 + error: function() {
63 + $('#step-2').find('.vz-progress-bar').animate({ width: '0' });
132 64 }
133 - },
134 - error: function () {
135 - clearInterval(loaderDelay);
136 - $progress.css({ width: '0' });
137 - $spinner.removeClass('is-active');
138 - $button.removeClass('disabled');
139 - }
140 - });
141 - };
142 -
143 - var collectInstallSlugs = function () {
144 - var slugs = [];
145 - var $optimole = $('#enable_performance');
146 - if ($optimole.length && $optimole.is(':checked') && !$optimole.is(':disabled')) {
147 - slugs.push('optimole-wp');
65 + } );
148 66 }
149 - if ($('#enable_otter_blocks').is(':checked') && !$('#enable_otter_blocks').is(':disabled')) {
150 - slugs.push('otter-blocks');
151 - }
152 - if ($('#enable_page_cache').is(':checked') && !$('#enable_page_cache').is(':disabled')) {
153 - slugs.push('wp-cloudflare-page-cache');
154 - }
155 - return slugs;
156 - };
157 -
158 - var setInstallStatus = function (slug, statusClass) {
159 - var $status = $('[data-install-status="' + slug + '"]');
160 - $status.removeClass('is-installing is-done is-error').addClass(statusClass);
161 - };
162 -
163 - var installPluginsSequentially = function (slugs, onDone) {
164 - if (!slugs.length) {
165 - onDone(true);
166 - return;
167 - }
168 - var slug = slugs.shift();
169 - setInstallStatus(slug, 'is-installing');
170 - $.post(
171 - visualizerSetupWizardData.ajax.url,
172 - {
173 - action: 'visualizer_wizard_step_process',
174 - security: visualizerSetupWizardData.ajax.security,
175 - slug: slug,
176 - step: 'step_4',
177 - },
178 - function (response) {
179 - if (1 === response.status) {
180 - setInstallStatus(slug, 'is-done');
181 - installPluginsSequentially(slugs, onDone);
182 - } else {
183 - setInstallStatus(slug, 'is-error');
184 - onDone(false, response.message);
185 - }
186 - }
187 - ).fail(function () {
188 - setInstallStatus(slug, 'is-error');
189 - onDone(false, '');
190 - });
191 - };
67 + callback();
68 + }
192 69 $("#smartwizard").smartWizard({
193 70 transition: {
194 71 animation: "fade", // Animation effect on navigation, none|fade|slideHorizontal|slideVertical|slideSwing|css(Animation CSS class also need to specify)
195 72 speed: "400", // Animation speed. Not used if animation is 'css'
@@ -210,9 +87,10 @@
210 87 // CSS Class settings
211 88 btnCss: "",
212 89 btnNextCss: "btn-primary next-btn",
213 90 btnPrevCss: "btn-light",
214 - }
91 + },
92 + getContent: provideContent
215 93 });
216 94
217 95 // click to open accordion.
218 96 $(".vz-accordion .vz-accordion-item .vz-accordion-item__button").on(
@@ -240,25 +118,48 @@
240 118 "click",
241 119 ".btn-primary:not(.next-btn,.vz-create-page,.vz-subscribe)",
242 120 function (e) {
243 121 var stepNumber = $(this).data("step_number");
244 -
245 122 switch (stepNumber) {
246 123 case 1:
247 124 if ($(".vz-radio-btn").is(":checked")) {
248 - runImport();
125 + $('#smartwizard').smartWizard('next');
249 126 }
250 127 break;
251 - case 2:
252 - if ( isLivePreview ) {
253 - $('#smartwizard').smartWizard('next');
254 - } else {
255 - var urlParams = new URLSearchParams(window.location.search);
256 - urlParams.set('preview_chart', Date.now());
257 - window.location.hash = "#step-2";
258 - window.location.search = urlParams;
259 - }
128 + case 3:
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;
260 133 break;
134 + case 4:
135 + $('#step-4').find('.spinner').addClass('is-active');
136 + $('#step-4').find('.vz-error-notice').addClass('hidden');
137 +
138 + $.post(
139 + visualizerSetupWizardData.ajax.url,
140 + {
141 + action: 'visualizer_wizard_step_process',
142 + security: visualizerSetupWizardData.ajax.security,
143 + slug: 'optimole-wp',
144 + step: 'step_4',
145 + },
146 + function (response) {
147 + if (1 === response.status) {
148 + $('#smartwizard').smartWizard('next');
149 + } else if ( 'undefined' !== typeof response.message ) {
150 + $('#step-4')
151 + .find('.vz-error-notice')
152 + .html("<p>" + response.message + "</p>");
153 + $('#step-4').find('.vz-error-notice').removeClass('hidden');
154 + }
155 + $('#step-4').find('.spinner').removeClass('is-active');
156 + }
157 + ).fail(function () {
158 + $('#step-4').find('.spinner').removeClass('is-active');
159 + });
160 + e.preventDefault();
161 + break;
261 162 default:
262 163 e.preventDefault();
263 164 break;
264 165 }
@@ -279,13 +180,9 @@
279 180 add_basic_shortcode: $("#insert_shortcode").is(":checked"),
280 181 },
281 182 function (res) {
282 183 if (res.status > 0) {
283 - if ( isLivePreview ) {
284 - goToDraftPage();
285 - } else {
286 - $("#smartwizard").smartWizard("next");
287 - }
184 + $("#smartwizard").smartWizard("next");
288 185 }
289 186 _this.next(".spinner").removeClass("is-active");
290 187 }
291 188 ).fail(function () {
@@ -294,19 +191,21 @@
294 191 e.preventDefault();
295 192 });
296 193
297 194 // Enable performance feature.
195 + $("#step-4").on("change", "input:checkbox", function () {
196 + if ($(this).is(":checked")) {
197 + $(".skip-improvement").hide();
198 + $(".vz-wizard-install-plugin").show();
199 + } else {
200 + $(".skip-improvement").show();
201 + $(".vz-wizard-install-plugin").hide();
202 + }
203 + });
204 +
298 205 // Step: 4 Skip and subscribe process.
299 206 $(document).on( 'click', '.vz-subscribe', function (e) {
300 - var $btn = $(this);
301 -
302 - // Prevent double-clicks while the async flow is running.
303 - if ( $btn.prop('disabled') ) {
304 - e.preventDefault();
305 - return;
306 - }
307 -
308 - var withSubscribe = $btn.data("vz_subscribe");
207 + var withSubscribe = $(this).data("vz_subscribe");
309 208 var postData = {
310 209 action: "visualizer_wizard_step_process",
311 210 security: visualizerSetupWizardData.ajax.security,
312 211 step: "step_subscribe",
@@ -312,104 +211,49 @@
312 211 step: "step_subscribe",
313 212 };
314 213 var emailElement = $("#vz_subscribe_email");
315 214 // Remove error message.
316 - showNewsletterError(emailElement, '');
317 - var newsletterEnabled = $("#enable_newsletter").is(":checked");
215 + emailElement.next(".vz-field-error").remove();
318 216
319 - if (withSubscribe && newsletterEnabled) {
320 - var subscribeEmail = emailElement.val().trim();
217 + if (withSubscribe) {
218 + var subscribeEmail = emailElement.val();
219 + var EmailTest = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
321 220 var errorMessage = "";
322 221
323 222 if ("" === subscribeEmail) {
324 223 errorMessage = visualizerSetupWizardData.errorMessages.requiredEmail;
325 - } else if (!emailRegex.test(subscribeEmail)) {
224 + } else if (!EmailTest.test(subscribeEmail)) {
326 225 errorMessage = visualizerSetupWizardData.errorMessages.invalidEmail;
327 226 }
328 227 if ("" !== errorMessage) {
329 - showNewsletterError(emailElement, errorMessage);
228 + $('<span class="vz-field-error">' + errorMessage + "</span>").insertAfter(emailElement);
330 229 return false;
331 230 }
332 231
333 232 postData.email = subscribeEmail;
334 233 postData.with_subscribe = withSubscribe;
335 - } else {
336 - postData.with_subscribe = false;
337 234 }
235 + var currentStep = $( '.vz-wizard-wrap .tab-pane:last-child' );
236 + currentStep.find(".spinner").addClass("is-active");
338 237
339 - $btn.prop('disabled', true);
340 - var $step = $('#step-3');
341 - $step.find(".spinner").addClass("is-active");
342 - var $error = $step.find('.vz-error-notice').first();
343 - $error.addClass('hidden').empty();
344 -
345 - var slugs = collectInstallSlugs();
346 - installPluginsSequentially(slugs.slice(), function (ok, message) {
347 - if (!ok) {
348 - if (message) {
349 - $error.html('<p>' + message + '</p>').removeClass('hidden');
350 - }
351 - $step.find(".spinner").removeClass("is-active");
352 - $btn.prop('disabled', false);
353 - return;
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();
354 247 }
355 - goToDraftPage(postData);
248 + currentStep.find('.spinner').removeClass('is-active');
249 + }).fail(function () {
250 + $('.redirect-popup').hide();
251 + currentStep.find('.spinner').removeClass('is-active');
356 252 });
357 253 e.preventDefault();
358 254 });
359 255
360 - $(document).on('click', '.vz-change-email', function () {
361 - var $card = $(this).closest('.vz-option-card--newsletter');
362 - var $inputWrap = $card.find('.vz-option-input');
363 - $inputWrap.show();
364 - $card.find('#vz_subscribe_email').focus();
365 - validateNewsletterEmail();
366 - });
367 -
368 - var finalizeNewsletterEmail = function ($card) {
369 - var $input = $card.find('#vz_subscribe_email');
370 - var $text = $card.find('.vz-email-text');
371 - var email = $input.val();
372 - if (email) {
373 - $text.text(email);
374 - }
375 - $card.find('.vz-option-input').hide();
376 - };
377 -
378 - $(document).on('click', '.vz-save-email', function () {
379 - var $card = $(this).closest('.vz-option-card--newsletter');
380 - if (!validateNewsletterEmail()) {
381 - return;
382 - }
383 - finalizeNewsletterEmail($card);
384 - });
385 -
386 - var validateNewsletterEmail = function () {
387 - var $input = $("#vz_subscribe_email");
388 - if (!$input.length) {
389 - return true;
390 - }
391 - var $card = $input.closest('.vz-option-card--newsletter');
392 - var $saveButton = $card.find('.vz-save-email');
393 - var email = $input.val().trim();
394 - showNewsletterError($input, '');
395 - if (!email) {
396 - $saveButton.prop('disabled', false);
397 - return true;
398 - }
399 - if (!emailRegex.test(email)) {
400 - showNewsletterError($input, visualizerSetupWizardData.errorMessages.invalidEmail);
401 - $saveButton.prop('disabled', true);
402 - return false;
403 - }
404 - $saveButton.prop('disabled', false);
405 - return true;
406 - };
407 -
408 - $(document).on('input blur', '#vz_subscribe_email', function () {
409 - validateNewsletterEmail();
410 - });
411 -
412 256 // Click to copy.
413 257 var clipboard = new ClipboardJS(".vz-copy-code-btn");
414 258 clipboard.on("success", function (e) {
415 259 var inputElement = $(e.trigger).prev("input:text");
@@ -418,11 +262,8 @@
418 262 // Remove disabled class from get started button.
419 263 $("#step-1").on("change", "input:radio", function () {
420 264 $("#step-1").find('[data-step_number="1"]').removeClass("disabled");
421 265 });
422 - if ( $('#step-1 .vz-radio-btn:checked').length ) {
423 - $('#step-1').find('[data-step_number="1"]').removeClass('disabled');
424 - }
425 266
426 267 // Change button text.
427 268 $(document).on("change", "#insert_shortcode", function () {
428 269 if ($(this).is(":checked")) {
@@ -436,8 +277,31 @@
436 277 ' <span class="dashicons dashicons-arrow-right-alt"></span>'
437 278 );
438 279 }
439 280 });
281 +
282 + $('.vz-chart-list > ul').slick({
283 + dots: false,
284 + infinite: false,
285 + speed: 400,
286 + slidesToShow: 1,
287 + centerMode: false,
288 + variableWidth: true
289 + })
290 + .on( 'afterChange', function(event, slick, currentSlide) {
291 + // Disable next buttion.
292 + if( currentSlide === 4 ) {
293 + $('.slick-next').attr('disabled', true).css('pointer-events', 'none');
294 + } else {
295 + $('.slick-next').removeAttr('disabled').css('pointer-events', 'all');
296 + }
297 + // Disable prev buttion.
298 + if( currentSlide === 0 ) {
299 + $('.slick-prev').attr('disabled', true).css('pointer-events', 'none');
300 + } else {
301 + $('.slick-prev').removeAttr('disabled').css('pointer-events', 'all');
302 + }
303 + } );
440 304
441 305 $(window).bind('pageshow', function() {
442 306 if ( jQuery('.vz-chart-option input').is(':checked') ) {
443 307 $('#step-1').find('button.disabled').removeClass('disabled');