PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.10.8
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.10.8
3.13.3 3.13.2 3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 2.8.16 All 261 releases
wpfunnels / admin / modules / settings / js / settings.js

settings.js in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 3.10.8, at admin/modules/settings/js/settings.js

574 lines 24.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 jQuery(function ($) {
2
3 'use strict';
4 $(document).ready(function ($) {
5 /**
6 * toggle password functionality on settings page
7 */
8 $(".toggle-eye-icon").click(function() {
9 $('.toggle-eye-icon').removeClass('hide-eye-icon');
10 $(this).addClass('hide-eye-icon');
11 let input = $('#wpfnl-google-map-api-key');
12 if ( "password" === input.attr("type") ) {
13 input.attr("type", "text");
14 } else {
15 input.attr("type", "password");
16 }
17 });
18
19 function toggleLogOptions() {
20 const $checkbox = $('#enable-log-status');
21 const $logOptionsWrapper = $('.log-options-wrapper');
22
23 if (!$checkbox.length || !$logOptionsWrapper.length) return;
24
25 $checkbox.on('change', function () {
26 if ($(this).is(':checked')) {
27 $logOptionsWrapper.show();
28 } else {
29 $logOptionsWrapper.hide();
30 }
31 });
32 }
33 toggleLogOptions();
34
35 function enable_disable_recapcha() {
36 if ($("input[name='wpfnl-recapcha-enable']").prop("checked")) {
37 $("#wpfnl-recapcha").show()
38 } else {
39 $("#wpfnl-recapcha").hide()
40 }
41 }
42
43 // Toggle revenue report settings
44 function toggleRevenueReportSettings() {
45 if ($("#wpfnl-enable-revenue-report").is(':checked')) {
46 $("#wpfnl-revenue-report-settings").show();
47 } else {
48 $("#wpfnl-revenue-report-settings").hide();
49 }
50 }
51 toggleRevenueReportSettings();
52
53 $("#wpfnl-enable-revenue-report").on('change', function() {
54 toggleRevenueReportSettings();
55 });
56
57 $('#wpfunnels-page-builder').on('click', '.wpfnl-single-item', function() {
58 $('#wpfunnels-page-builder .wpfnl-single-item').removeClass('checked');
59 $(this).addClass('checked');
60 $('#clear-template').trigger('click');
61 });
62
63 $('#wpfunnels-funnel-type').on('click', '.wpfnl-single-item', function() {
64 $('#wpfunnels-funnel-type .wpfnl-single-item').removeClass('checked');
65 $(this).addClass('checked');
66 $('#clear-template').trigger('click');
67 });
68
69 if ($("input[name='wpfnl-utm-enable']").prop("checked")) {
70 $("#wpfnl-utm").show()
71 } else {
72 $("#wpfnl-utm").hide()
73 }
74 $('#utm-enable').on('click', function () {
75 if ($("input[name='wpfnl-utm-enable']").prop("checked")) {
76 $("#wpfnl-utm").show()
77 } else {
78 $("#wpfnl-utm").hide()
79 }
80 })
81
82 if ($("input[name='wpfnl-gtm-enable']").prop("checked")) {
83 $("#wpfnl-gtm").show()
84 } else {
85 $("#wpfnl-gtm").hide()
86 }
87 $('#gtm-enable').on('click', function () {
88 if ($("input[name='wpfnl-gtm-enable']").prop("checked")) {
89 $("#wpfnl-gtm").show()
90 } else {
91 $("#wpfnl-gtm").hide()
92 }
93 })
94
95
96 if ($("input[name='enable-skip-cart']").prop("checked")) {
97 $(".wpfnl-skip-cart").show()
98 } else {
99 $(".wpfnl-skip-cart").hide()
100 }
101 $('#enable-skip-cart').on('click', function () {
102 if ($("input[name='enable-skip-cart']").prop("checked")) {
103 $(".wpfnl-skip-cart").show()
104 } else {
105 $(".wpfnl-skip-cart").hide()
106 }
107 })
108
109
110 if ($("input[name='wpfnl-facebook-pixel-enable']").prop("checked")) {
111 $("#wpfnl-facebook-pixel").show()
112 } else {
113 $("#wpfnl-facebook-pixel").hide()
114 }
115 $('#facebook-pixel-enable').on('click', function () {
116 if ($("input[name='wpfnl-facebook-pixel-enable']").prop("checked")) {
117 $("#wpfnl-facebook-pixel").show()
118 } else {
119 $("#wpfnl-facebook-pixel").hide()
120 }
121 })
122
123 enable_disable_recapcha()
124
125 $('#recapcha-pixel-enable').on('click', function () {
126 enable_disable_recapcha()
127 })
128
129 $('.wpfnl-log-view').on('click', function (e) {
130 e.preventDefault();
131 var thisElement = $(this);
132 show_log(thisElement);
133 })
134
135 $('.wpfnl-log-delete').on('click', function (e) {
136 e.preventDefault();
137 var thisElement = $(this);
138 delete_log(thisElement);
139 })
140
141 /**
142 * Show WPFunnels log
143 */
144 function show_log(thisElement) {
145 thisElement.find('.wpfnl-loader').css('display', 'inline-block');
146
147 var log_key = $('#wpfnl-log option:selected').val();
148 var payload = {
149 'logKey': log_key
150 };
151 if (!log_key) {
152 $('#log-viewer pre').html('');
153 } else {
154 wpAjaxHelperRequest('wpfnl-show-log', payload)
155 .success(function (response) {
156 thisElement.find('.wpfnl-loader').hide();
157
158 if (response.success) {
159 $('#log-viewer pre').html(response.content);
160 }
161 })
162 .error(function (response) {
163 });
164 }
165
166 }
167
168 /**
169 * Show WPFunnels log
170 */
171 function delete_log(thisElement) {
172 thisElement.find('.wpfnl-loader').css('display', 'inline-block');
173 localStorage.setItem("buttonClicked", true);
174
175 var log_key = $('#wpfnl-log option:selected').val();
176 var payload = {
177 'logKey': log_key
178 };
179 if (!log_key) {
180 $('#log-viewer').html('');
181 } else {
182 wpAjaxHelperRequest('wpfnl-delete-log', payload)
183 .success(function (response) {
184 if (response.success) {
185 $('#wpfnl-log option:selected').remove();
186 $('#log-viewer').empty();
187 }
188
189 thisElement.find('.wpfnl-loader').hide();
190
191 })
192 .error(function (response) {
193 });
194 }
195
196 }
197
198 var GeneralSettingsHandler = function () {
199 $(document.body)
200 .on('click', '#wpfnl-update-global-settings', this.updateGeneralSettings)
201 .on('click', '#clear-template', this.clearTemplates)
202 .on('click', '#clear-transients', this.clearTransients)
203
204 /**
205 * settings page Permalink Settings permalink
206 * change on keyup
207 *
208 * @since 1.0.0
209 */
210 $('code.stepbase').text($('input[name="wpfnl-permalink-step-base"]').val());
211 $('code.funnelbase').text($('input[name="wpfnl-permalink-funnel-base"]').val());
212
213 $('input[name="wpfnl-permalink-step-base"]').keyup(function () {
214 if ($(this).val() != '') {
215 $('code.stepbase').text($(this).val());
216 } else {
217 $('code.stepbase').text('wpfunnels');
218 }
219 });
220
221 $('input[name="wpfnl-permalink-funnel-base"]').keyup(function () {
222 if ($(this).val() != '') {
223 $('code.funnelbase').text($(this).val());
224 } else {
225 $('code.funnelbase').text('step');
226 }
227 });
228
229 };
230
231
232 /**
233 * update general settings
234 *
235 * @param e
236 * @since 1.0.0
237 */
238 GeneralSettingsHandler.prototype.updateGeneralSettings = function (e) {
239 e.preventDefault();
240 var userRole = {};
241 var permittedRole = {};
242 var gtmEvents = {};
243 var fbTrackEvent = {};
244 var advancedSettings = {};
245 $("input[name='analytics-role[]']").map(function () {
246 if ($(this).prop("checked")) {
247 userRole[$(this).data('role')] = 'true';
248 }
249 return $(this).prop("checked") ? 1 : 0;
250 }).get();
251
252 $("input[name='permission-role[]']").map(function () {
253 if ($(this).prop("checked")) {
254 permittedRole[$(this).data('role')] = 'true';
255 }
256 return $(this).prop("checked") ? 1 : 0;
257 }).get();
258
259
260 $("input[name='wpfnl-gtm-events[]']").map(function () {
261 if ($(this).prop("checked")) {
262 gtmEvents[$(this).data('role')] = 'true';
263 }
264 return $(this).prop("checked") ? 1 : 0;
265 }).get();
266
267 $("input[name='wpfnl-facebook_pixel_events[]']").map(function () {
268 if ($(this).prop("checked")) {
269 fbTrackEvent[$(this).data('role')] = 'true';
270 }
271 return $(this).prop("checked") ? 1 : 0;
272 }).get();
273
274
275 // get the role management values from settings
276 var checkboxes = $('input[name="user_role[]"]'),
277 userRoleManagement = window.WPFunnelVars.user_role_manager_data;
278
279 checkboxes.each(function(checkbox) {
280 var role = $(this).attr('data-role');
281 userRoleManagement[role] = $(this).is(":checked") ? 'yes' : 'no';
282 });
283
284 var payload = {
285 'funnel_type': $('#wpfunnels-funnel-type .wpfnl-single-item.checked').attr('data-value'),
286 'builder': $('#wpfunnels-page-builder .wpfnl-single-item.checked').attr('data-value'),
287 'uninstall_cleanup': $('#wpfnl-data-cleanup').is(':checked') ? 'on' : 'off',
288 'paypal_reference': $('#wpfunnels-paypal-reference').is(':checked') ? 'on' : 'off',
289 'analytics_roles': userRole,
290 'permission_role': permittedRole,
291 'order_bump': $('#wpfunnels-order-bump').is(':checked') ? 'on' : 'off',
292 'ab_testing': $('#wpfunnels-ab-testing').is(':checked') ? 'on' : 'off',
293 'permalink_settings': $("input[name='wpfunnels-set-permalink']:checked").val(),
294 'permalink_step_base': $('#wpfunnels-permalink-step-base').val(),
295 'permalink_funnel_base': $('#wpfunnels-permalink-funnel-base').val(),
296 'sender_email': $('#wpfunnels-optin-sender-email').val(),
297 'sender_name': $('#wpfunnels-optin-sender-name').val(),
298 'email_subject': $('#wpfunnels-optin-email-subject').val(),
299 'set_permalink': $('input[name="wpfunnels-set-permalink"]:checked').val(),
300 'offer_orders': $('input[name="offer-orders"]:checked').val(),
301 'skip_offer_step': $('#wpfnl-skip-offer-step').is(':checked') ? 'on' : 'off',
302 'skip_offer_step_for_free': $('#wpfnl-skip-offer-step-for-free').is(':checked') ? 'on' : 'off',
303 'skip_offer_for_recurring_buyer': $('#wpfnl-skip-offer-for-recurring-buyer').is(':checked') ? 'on' : 'off',
304 'skip_offer_for_recurring_buyer_within_year': $('#wpfnl-skip-offer-for-recurring-buyer-within-year').is(':checked') ? 'on' : 'off',
305 'show_supported_payment_gateway': $('#wpfnl-show-supported-payment-gateway').is(':checked') ? 'on' : 'off',
306 'gtm_enable': $('input[name="wpfnl-gtm-enable"]:checked').val(),
307 'gtm_container_id': $('#wpfnl-gtm-container-id').val(),
308 'gtm_events': gtmEvents,
309 'enable_fb_pixel': $('input[name="wpfnl-facebook-pixel-enable"]:checked').val(),
310 'fb_tracking_code': $('#wpfnl-facebook-tracking-code').val(),
311 'fb_tracking_events': fbTrackEvent,
312 'utm_enable': $('input[name="wpfnl-utm-enable"]:checked').val(),
313 'utm_source': $('#wpfnl-utm-source').val(),
314 'utm_medium': $('#wpfnl-utm-medium').val(),
315 'utm_campaign': $('#wpfnl-utm-campaign').val(),
316 'utm_content': $('#wpfnl-utm-content').val(),
317 'disable_theme_style': $('#disable-theme-style').is(':checked') ? 'on' : 'off',
318 'enable_log_status': $('#enable-log-status').is(':checked') ? 'on' : 'off',
319 'enable_skip_cart': $('#enable-skip-cart').is(':checked') ? 'on' : 'off',
320 'skip_cart_for': $('input[name="skip-cart"]:checked').val(),
321 'enable_recaptcha': $('input[name="wpfnl-recapcha-enable"]:checked').val(),
322 'recaptcha_site_key': $('#wpfnl-recapcha-site-key').val(),
323 'recaptcha_site_secret': $('#wpfnl-recapcha-site-secret').val(),
324 'user_role_management': { roles: userRoleManagement },
325 'google_map_api_key' : $('#wpfnl-google-map-api-key').val(),
326 'enable_global_thankyou' : $('#wpfnl-enable-global-thankyou').is(':checked') ? 'on' : 'off',
327 'lms_provider' : $('#lms-provider-select').val(),
328 'enable_revenue_report' : $('#wpfnl-enable-revenue-report').is(':checked') ? 'yes' : 'no',
329 'revenue_report_frequency' : $('input[name="wpfnl-revenue-report-frequency"]:checked').val(),
330 'revenue_report_recipient' : $('#wpfnl-revenue-report-recipient').val(),
331 'revenue_report_subject' : $('#wpfnl-revenue-report-subject').val(),
332 'send_time' : $('#wpfnl-send-time').val(),
333 };
334
335 var thisLoader = $(this).find('.wpfnl-loader');
336 var thisAlert = $(this).siblings('.wpfnl-alert');
337
338 thisLoader.fadeIn(); //show loader
339
340 wpAjaxHelperRequest("update-general-settings", payload)
341 .success(function (response) {
342 thisLoader.fadeOut();
343 $('#wpfnl-toaster-wrapper').addClass('quick-toastify-successful-notification');
344
345 $('#wpfnl-toaster-icon').html('<svg width="26" height="26" fill="none" viewBox="0 0 26 26" xmlns="http://www.w3.org/2000/svg"><path fill="#4BAE4F" fill-rule="evenodd" d="M13 0C5.83 0 0 5.83 0 13s5.83 13 13 13 13-5.83 13-13S20.17 0 13 0z" clip-rule="evenodd"/><path fill="#fff" fill-rule="evenodd" d="M19.287 8.618a.815.815 0 010 1.148l-7.617 7.617a.812.812 0 01-1.148 0l-3.808-3.809a.815.815 0 010-1.147.815.815 0 011.147 0l3.235 3.234 7.044-7.043a.806.806 0 011.147 0z" clip-rule="evenodd"/></svg>');
346
347 $('#wpfnl-toaster-message').html('Saved Successfully')
348 $('#wpfnl-toaster-wrapper').show();
349
350 setTimeout(function() {
351 $('#wpfnl-toaster-wrapper').removeClass('quick-toastify-successful-notification');
352 $('#wpfnl-toaster-wrapper').hide(); 
353 }, 2000);
354
355 })
356 .error(function (response) {
357 thisLoader.fadeOut();
358 $('#wpfnl-toaster-wrapper').addClass('quick-toastify-warn-notification');
359
360 $('#wpfnl-toaster-icon').html('<svg width="26" height="26" fill="none" viewBox="0 0 26 26" xmlns="http://www.w3.org/2000/svg"><path fill="#EC5956" fill-rule="evenodd" d="M26 13c0 7.18-5.82 13-13 13S0 20.18 0 13 5.82 0 13 0s13 5.82 13 13zm-11.375 6.5a1.625 1.625 0 11-3.25 0 1.625 1.625 0 013.25 0zM13 4.875c-.898 0-1.625.728-1.625 1.625V13a1.625 1.625 0 103.25 0V6.5c0-.897-.727-1.625-1.625-1.625z" clip-rule="evenodd"/></svg>');
361
362 $('#wpfnl-toaster-message').html('Erorr occurred')
363 $('#wpfnl-toaster-wrapper').show();
364 setTimeout(function() {
365 $('#wpfnl-toaster-wrapper').removeClass('quick-toastify-warn-notification');
366 $('#wpfnl-toaster-wrapper').hide(); 
367 }, 2000);
368 });
369
370 };
371
372
373 GeneralSettingsHandler.prototype.clearTemplates = function (e) {
374 e.preventDefault();
375
376 var $btn = $(this);
377 var sync_icon = $btn.find('.icon-sync');
378 var check_icon = $btn.find('.check-icon');
379 var $textSpan = $btn.find('.sync-btn-text');
380 var thisAlert = $btn.siblings('.wpfnl-alert');
381
382 sync_icon.addClass('sync-icon');
383
384 var payload = {};
385 wpAjaxHelperRequest("clear-templates", payload)
386 .success(function (response) {
387 sync_icon.hide();
388 check_icon.fadeIn();
389
390 // Change text and add success style
391 $textSpan.addClass('success');
392 $textSpan.text('Templates synced successfully');
393 $btn.css({
394 'border-color': '#239654',
395 });
396
397 setTimeout(function () {
398 sync_icon.removeClass('sync-icon').show();
399 check_icon.hide();
400
401 // Restore original text and style
402 $textSpan.text('Sync Templates');
403 $textSpan.removeClass('success');
404 $btn.css({
405 'border-color': '',
406 });
407 }, 2000);
408
409 $("#wpfnl-update-global-settings").trigger("click");
410 })
411
412 .error(function (response) {
413 setTimeout(function () {
414 thisAlert.fadeOut().text('').removeClass('wpfnl-error');
415 }, 2000);
416 console.log('error');
417 });
418 };
419
420
421
422 /**
423 * clear all transients related to wpfunnels
424 *
425 * @param e
426 */
427 GeneralSettingsHandler.prototype.clearTransients = function (e) {
428 e.preventDefault();
429 if (confirm('Are you sure you want to run this tool?')) {
430
431 var sync_icon = $(this).find('.sync-icon');
432 var check_icon = $(this).find('.check-icon');
433 var thisAlert = $(this).siblings('.wpfnl-alert');
434
435 sync_icon.show();
436
437 var payload = {};
438 wpAjaxHelperRequest("clear-transient", payload)
439 .success(function (response) {
440 sync_icon.hide();
441 check_icon.fadeIn();
442 thisAlert.text('Successful').addClass('wpfnl-success').fadeIn();
443
444 setTimeout(function () {
445 check_icon.hide();
446 thisAlert.fadeOut().text('').removeClass('wpfnl-success');
447 }, 4000);
448 $("#wpfnl-update-global-settings").trigger("click");
449 })
450
451 .error(function (response) {
452 thisAlert.text('Erorr occurred').addClass('wpfnl-error').fadeIn();
453
454 setTimeout(function () {
455 thisAlert.fadeOut().text('').removeClass('wpfnl-error');
456 }, 2000);
457 console.log('error');
458 });
459 }
460 };
461
462
463 GeneralSettingsHandler.prototype.clearTransients = function (e) {
464 e.preventDefault();
465 if (confirm('Are you sure you want to run this tool?')) {
466
467 var sync_icon = $(this).find('.sync-icon');
468 var check_icon = $(this).find('.check-icon');
469 var thisAlert = $(this).siblings('.wpfnl-alert');
470
471 sync_icon.show();
472
473 var payload = {};
474 wpAjaxHelperRequest("clear-transient", payload)
475 .success(function (response) {
476 sync_icon.hide();
477 check_icon.fadeIn();
478 thisAlert.text('Successful').addClass('wpfnl-success').fadeIn();
479
480 setTimeout(function () {
481 check_icon.hide();
482 thisAlert.fadeOut().text('').removeClass('wpfnl-success');
483 }, 4000);
484 $("#wpfnl-update-global-settings").trigger("click");
485 })
486
487 .error(function (response) {
488 thisAlert.text('Erorr occurred').addClass('wpfnl-error').fadeIn();
489
490 setTimeout(function () {
491 thisAlert.fadeOut().text('').removeClass('wpfnl-error');
492 }, 2000);
493
494 console.log('error');
495 });
496 }
497 };
498
499 new GeneralSettingsHandler();
500
501 $('.inner-tab').on('click', function () {
502 $('.inner-tab').removeClass('active');
503 $('.wpfnl-tab-content').removeClass('active');
504
505 $(this).addClass('active');
506 var tabId = $(this).data('tab');
507 $('#' + tabId).addClass('active');
508 });
509
510 // Send test notification
511 $('#wpfnl-send-test-notification').on('click', function(e) {
512 e.preventDefault();
513
514 var $button = $(this);
515 var $loader = $button.find('.wpfnl-loader');
516 var email = $('#wpfnl-test-notification-email').val();
517
518 if (!email || !isValidEmail(email)) {
519 showToaster('error', 'Please enter a valid email address');
520 return;
521 }
522
523 $button.prop('disabled', true);
524 $loader.fadeIn();
525
526 var payload = {
527 'email': email
528 };
529
530 wpAjaxHelperRequest('wpfnl-send-test-notification', payload)
531 .success(function(response) {
532 $loader.fadeOut();
533 $button.prop('disabled', false);
534
535 if (response.success) {
536 showToaster('success', response.message);
537 } else {
538 showToaster('error', response.message);
539 }
540 })
541 .error(function(response) {
542 $loader.fadeOut();
543 $button.prop('disabled', false);
544 showToaster('error', 'Error occurred while sending test email');
545 });
546 });
547
548 function isValidEmail(email) {
549 var regex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
550 return regex.test(email);
551 }
552
553 function showToaster(type, message) {
554 var iconHtml = type === 'success'
555 ? '<svg width="26" height="26" fill="none" viewBox="0 0 26 26" xmlns="http://www.w3.org/2000/svg"><path fill="#4BAE4F" fill-rule="evenodd" d="M13 0C5.83 0 0 5.83 0 13s5.83 13 13 13 13-5.83 13-13S20.17 0 13 0z" clip-rule="evenodd"/><path fill="#fff" fill-rule="evenodd" d="M19.287 8.618a.815.815 0 010 1.148l-7.617 7.617a.812.812 0 01-1.148 0l-3.808-3.809a.815.815 0 010-1.147.815.815 0 011.147 0l3.235 3.234 7.044-7.043a.806.806 0 011.147 0z" clip-rule="evenodd"/></svg>'
556 : '<svg width="26" height="26" fill="none" viewBox="0 0 26 26" xmlns="http://www.w3.org/2000/svg"><path fill="#EC5956" fill-rule="evenodd" d="M26 13c0 7.18-5.82 13-13 13S0 20.18 0 13 5.82 0 13 0s13 5.82 13 13zm-11.375 6.5a1.625 1.625 0 11-3.25 0 1.625 1.625 0 013.25 0zM13 4.875c-.898 0-1.625.728-1.625 1.625V13a1.625 1.625 0 103.25 0V6.5c0-.897-.727-1.625-1.625-1.625z" clip-rule="evenodd"/></svg>';
557
558 var notificationClass = type === 'success' ? 'quick-toastify-successful-notification' : 'quick-toastify-warn-notification';
559
560 $('#wpfnl-toaster-wrapper').addClass(notificationClass);
561 $('#wpfnl-toaster-icon').html(iconHtml);
562 $('#wpfnl-toaster-message').html(message);
563 $('#wpfnl-toaster-wrapper').show();
564
565 setTimeout(function() {
566 $('#wpfnl-toaster-wrapper').removeClass(notificationClass);
567 $('#wpfnl-toaster-wrapper').hide();
568 }, 3000);
569 }
570
571 });
572
573 });
574