| 1 |
/** |
| 2 |
* Plugin Name: Visualizer: Tables and Charts for WordPress |
| 3 |
* Plugin URI: https://themeisle.com/plugins/visualizer-charts-and-graphs/ |
| 4 |
* Author: Themeisle |
| 5 |
* |
| 6 |
* @package Visualizer |
| 7 |
*/ |
| 8 |
/* jshint unused:false */ |
| 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 |
var provideContent = function(id, stepDirection, stepPosition, selStep, callback) { |
| 53 |
// Import chart data. |
| 54 |
if ( 1 == id ) { |
| 55 |
var chartType = $(".vz-radio-btn:checked").val(); |
| 56 |
var percentBarWidth = 0; |
| 57 |
var loaderDelay; |
| 58 |
$.ajax( { |
| 59 |
beforeSend: function() { |
| 60 |
loaderDelay = setInterval(function () { |
| 61 |
$('.vz-progress-bar').css({ |
| 62 |
width: percentBarWidth++ + '%' |
| 63 |
}); |
| 64 |
}, 1000); |
| 65 |
}, |
| 66 |
type: 'POST', |
| 67 |
url: visualizerSetupWizardData.ajax.url, |
| 68 |
dataType: 'json', |
| 69 |
data: { |
| 70 |
action: 'visualizer_wizard_step_process', |
| 71 |
security: visualizerSetupWizardData.ajax.security, |
| 72 |
chart_type: chartType, |
| 73 |
step: 'step_2', |
| 74 |
}, |
| 75 |
success: function (data) { |
| 76 |
clearInterval( loaderDelay ); |
| 77 |
loaderDelay = setInterval(function () { |
| 78 |
$('.vz-progress-bar').css({ |
| 79 |
width: percentBarWidth++ + '%' |
| 80 |
}); |
| 81 |
if ( percentBarWidth >= 100 ) { |
| 82 |
if ( 1 === data.success ) { |
| 83 |
var importMessage = jQuery('[data-import_message]'); |
| 84 |
importMessage |
| 85 |
.html( importMessage.data('import_message') ) |
| 86 |
.addClass('import_message'); |
| 87 |
|
| 88 |
$('#step-2').find('button.disabled').removeClass('disabled'); |
| 89 |
} else if( 2 === data.status && '' !== data.message ) { |
| 90 |
$('#step-2') |
| 91 |
.find('.vz-error-notice') |
| 92 |
.html( '<p>' + data.message + '</p>' ) |
| 93 |
.removeClass('hidden'); |
| 94 |
} else { |
| 95 |
$('#smartwizard').smartWizard('reset'); |
| 96 |
} |
| 97 |
$('.vz-progress-bar').css({ |
| 98 |
width: 100 + '%' |
| 99 |
}); |
| 100 |
$('.vz-progress').css({ |
| 101 |
visibility: 'hidden' |
| 102 |
}); |
| 103 |
clearInterval( loaderDelay ); |
| 104 |
} |
| 105 |
}, 36 ); |
| 106 |
}, |
| 107 |
error: function() { |
| 108 |
$('#step-2').find('.vz-progress-bar').animate({ width: '0' }); |
| 109 |
} |
| 110 |
} ); |
| 111 |
} |
| 112 |
callback(); |
| 113 |
} |
| 114 |
$("#smartwizard").smartWizard({ |
| 115 |
transition: { |
| 116 |
animation: "fade", // Animation effect on navigation, none|fade|slideHorizontal|slideVertical|slideSwing|css(Animation CSS class also need to specify) |
| 117 |
speed: "400", // Animation speed. Not used if animation is 'css' |
| 118 |
}, |
| 119 |
lang: { |
| 120 |
// Language variables for button |
| 121 |
next: visualizerSetupWizardData.nextButtonText, |
| 122 |
previous: visualizerSetupWizardData.backButtonText, |
| 123 |
}, |
| 124 |
keyboard: { |
| 125 |
keyNavigation: false, // Enable/Disable keyboard navigation(left and right keys are used if enabled) |
| 126 |
}, |
| 127 |
anchor: { |
| 128 |
enableNavigation: false, // Enable/Disable anchor navigation |
| 129 |
enableNavigationAlways: false, // Activates all anchors clickable always |
| 130 |
}, |
| 131 |
style: { |
| 132 |
// CSS Class settings |
| 133 |
btnCss: "", |
| 134 |
btnNextCss: "btn-primary next-btn", |
| 135 |
btnPrevCss: "btn-light", |
| 136 |
}, |
| 137 |
getContent: provideContent |
| 138 |
}); |
| 139 |
|
| 140 |
// click to open accordion. |
| 141 |
$(".vz-accordion .vz-accordion-item .vz-accordion-item__button").on( |
| 142 |
"click", |
| 143 |
function () { |
| 144 |
var current_item = $(this).parents(); |
| 145 |
$(".vz-accordion .vz-accordion-item .vz-accordion-item__content").each( |
| 146 |
function (i, el) { |
| 147 |
if ($(el).parent().is(current_item)) { |
| 148 |
$(el).prev().toggleClass("is-active"); |
| 149 |
$(el).slideToggle(); |
| 150 |
$(this).toggleClass("is-active"); |
| 151 |
} else { |
| 152 |
$(el).prev().removeClass("is-active"); |
| 153 |
$(el).slideUp(); |
| 154 |
$(this).removeClass("is-active"); |
| 155 |
} |
| 156 |
} |
| 157 |
); |
| 158 |
} |
| 159 |
); |
| 160 |
|
| 161 |
// Click to next step. |
| 162 |
$(document).on( |
| 163 |
"click", |
| 164 |
".btn-primary:not(.next-btn,.vz-create-page,.vz-subscribe)", |
| 165 |
function (e) { |
| 166 |
var stepNumber = $(this).data("step_number"); |
| 167 |
|
| 168 |
switch (stepNumber) { |
| 169 |
case 1: |
| 170 |
if ($(".vz-radio-btn").is(":checked")) { |
| 171 |
$('#smartwizard').smartWizard('next'); |
| 172 |
} |
| 173 |
break; |
| 174 |
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 |
} |
| 183 |
break; |
| 184 |
case 4: |
| 185 |
$('#step-4').find('.spinner').addClass('is-active'); |
| 186 |
$('#step-4').find('.vz-error-notice').addClass('hidden'); |
| 187 |
|
| 188 |
$.post( |
| 189 |
visualizerSetupWizardData.ajax.url, |
| 190 |
{ |
| 191 |
action: 'visualizer_wizard_step_process', |
| 192 |
security: visualizerSetupWizardData.ajax.security, |
| 193 |
slug: 'optimole-wp', |
| 194 |
step: 'step_4', |
| 195 |
}, |
| 196 |
function (response) { |
| 197 |
if (1 === response.status) { |
| 198 |
$('#smartwizard').smartWizard('next'); |
| 199 |
} else if ( 'undefined' !== typeof response.message ) { |
| 200 |
$('#step-4') |
| 201 |
.find('.vz-error-notice') |
| 202 |
.html("<p>" + response.message + "</p>"); |
| 203 |
$('#step-4').find('.vz-error-notice').removeClass('hidden'); |
| 204 |
} |
| 205 |
$('#step-4').find('.spinner').removeClass('is-active'); |
| 206 |
} |
| 207 |
).fail(function () { |
| 208 |
$('#step-4').find('.spinner').removeClass('is-active'); |
| 209 |
}); |
| 210 |
e.preventDefault(); |
| 211 |
break; |
| 212 |
default: |
| 213 |
e.preventDefault(); |
| 214 |
break; |
| 215 |
} |
| 216 |
} |
| 217 |
); |
| 218 |
|
| 219 |
// Create draft page. |
| 220 |
$(document).on("click", ".vz-create-page", function (e) { |
| 221 |
var _this = $(this); |
| 222 |
_this.next(".spinner").addClass("is-active"); |
| 223 |
$.post( |
| 224 |
visualizerSetupWizardData.ajax.url, |
| 225 |
{ |
| 226 |
action: "visualizer_wizard_step_process", |
| 227 |
security: visualizerSetupWizardData.ajax.security, |
| 228 |
step: "create_draft_page", |
| 229 |
basic_shortcode: $("#basic_shortcode").val(), |
| 230 |
add_basic_shortcode: $("#insert_shortcode").is(":checked"), |
| 231 |
}, |
| 232 |
function (res) { |
| 233 |
if (res.status > 0) { |
| 234 |
if ( isLivePreview ) { |
| 235 |
goToDraftPage(); |
| 236 |
} else { |
| 237 |
$("#smartwizard").smartWizard("next"); |
| 238 |
} |
| 239 |
} |
| 240 |
_this.next(".spinner").removeClass("is-active"); |
| 241 |
} |
| 242 |
).fail(function () { |
| 243 |
_this.next(".spinner").removeClass("is-active"); |
| 244 |
}); |
| 245 |
e.preventDefault(); |
| 246 |
}); |
| 247 |
|
| 248 |
// Enable performance feature. |
| 249 |
$("#step-4").on("change", "input:checkbox", function () { |
| 250 |
if ($(this).is(":checked")) { |
| 251 |
$(".skip-improvement").hide(); |
| 252 |
$(".vz-wizard-install-plugin").show(); |
| 253 |
} else { |
| 254 |
$(".skip-improvement").show(); |
| 255 |
$(".vz-wizard-install-plugin").hide(); |
| 256 |
} |
| 257 |
}); |
| 258 |
|
| 259 |
// Step: 4 Skip and subscribe process. |
| 260 |
$(document).on( 'click', '.vz-subscribe', function (e) { |
| 261 |
var withSubscribe = $(this).data("vz_subscribe"); |
| 262 |
var postData = { |
| 263 |
action: "visualizer_wizard_step_process", |
| 264 |
security: visualizerSetupWizardData.ajax.security, |
| 265 |
step: "step_subscribe", |
| 266 |
}; |
| 267 |
var emailElement = $("#vz_subscribe_email"); |
| 268 |
// Remove error message. |
| 269 |
emailElement.next(".vz-field-error").remove(); |
| 270 |
|
| 271 |
if (withSubscribe) { |
| 272 |
var subscribeEmail = emailElement.val(); |
| 273 |
var EmailTest = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/; |
| 274 |
var errorMessage = ""; |
| 275 |
|
| 276 |
if ("" === subscribeEmail) { |
| 277 |
errorMessage = visualizerSetupWizardData.errorMessages.requiredEmail; |
| 278 |
} else if (!EmailTest.test(subscribeEmail)) { |
| 279 |
errorMessage = visualizerSetupWizardData.errorMessages.invalidEmail; |
| 280 |
} |
| 281 |
if ("" !== errorMessage) { |
| 282 |
$('<span class="vz-field-error">' + errorMessage + "</span>").insertAfter(emailElement); |
| 283 |
return false; |
| 284 |
} |
| 285 |
|
| 286 |
postData.email = subscribeEmail; |
| 287 |
postData.with_subscribe = withSubscribe; |
| 288 |
} |
| 289 |
var currentStep = $( '.vz-wizard-wrap .tab-pane:last-child' ); |
| 290 |
currentStep.find(".spinner").addClass("is-active"); |
| 291 |
|
| 292 |
goToDraftPage( postData ); |
| 293 |
e.preventDefault(); |
| 294 |
}); |
| 295 |
|
| 296 |
// Click to copy. |
| 297 |
var clipboard = new ClipboardJS(".vz-copy-code-btn"); |
| 298 |
clipboard.on("success", function (e) { |
| 299 |
var inputElement = $(e.trigger).prev("input:text"); |
| 300 |
}); |
| 301 |
|
| 302 |
// Remove disabled class from get started button. |
| 303 |
$("#step-1").on("change", "input:radio", function () { |
| 304 |
$("#step-1").find('[data-step_number="1"]').removeClass("disabled"); |
| 305 |
}); |
| 306 |
|
| 307 |
// Change button text. |
| 308 |
$(document).on("change", "#insert_shortcode", function () { |
| 309 |
if ($(this).is(":checked")) { |
| 310 |
$(".vz-create-page").html( |
| 311 |
visualizerSetupWizardData.draftPageButtonText.firstButtonText + |
| 312 |
' <span class="dashicons dashicons-arrow-right-alt"></span>' |
| 313 |
); |
| 314 |
} else { |
| 315 |
$(".vz-create-page").html( |
| 316 |
visualizerSetupWizardData.draftPageButtonText.secondButtonText + |
| 317 |
' <span class="dashicons dashicons-arrow-right-alt"></span>' |
| 318 |
); |
| 319 |
} |
| 320 |
}); |
| 321 |
|
| 322 |
$('.vz-chart-list > ul').slick({ |
| 323 |
dots: false, |
| 324 |
infinite: false, |
| 325 |
speed: 400, |
| 326 |
slidesToShow: 1, |
| 327 |
centerMode: false, |
| 328 |
variableWidth: true |
| 329 |
}) |
| 330 |
.on( 'afterChange', function(event, slick, currentSlide) { |
| 331 |
// Disable next buttion. |
| 332 |
if( currentSlide === 4 ) { |
| 333 |
$('.slick-next').attr('disabled', true).css('pointer-events', 'none'); |
| 334 |
} else { |
| 335 |
$('.slick-next').removeAttr('disabled').css('pointer-events', 'all'); |
| 336 |
} |
| 337 |
// Disable prev buttion. |
| 338 |
if( currentSlide === 0 ) { |
| 339 |
$('.slick-prev').attr('disabled', true).css('pointer-events', 'none'); |
| 340 |
} else { |
| 341 |
$('.slick-prev').removeAttr('disabled').css('pointer-events', 'all'); |
| 342 |
} |
| 343 |
} ); |
| 344 |
|
| 345 |
$(window).bind('pageshow', function() { |
| 346 |
if ( jQuery('.vz-chart-option input').is(':checked') ) { |
| 347 |
$('#step-1').find('button.disabled').removeClass('disabled'); |
| 348 |
} |
| 349 |
}); |
| 350 |
}); |
| 351 |
|