PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.13.0
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.13.0
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 / assets / js / wpfnl-admin.js

wpfnl-admin.js in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 3.13.0, at admin/assets/js/wpfnl-admin.js

3,112 lines 114.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 ;(function ($) {
2 'use strict'
3
4 var product_option = window.WPFunnelVars.products
5 var selectedIds = []
6 /**
7 * All of the code for your admin-facing JavaScript source
8 * should reside in this file.
9 *
10 * Note: It has been assumed you will write jQuery code here, so the
11 * $ function reference has been prepared for usage within the scope
12 * of this function.
13 *
14 * This enables you to define handlers, for when the DOM is ready:
15 *
16 * $(function() {
17 *
18 * });
19 *
20 * When the window is loaded:
21 *
22 * $( window ).load(function() {
23 *
24 * });
25 *
26 * ...and/or other possibilities.
27 *
28 * Ideally, it is not considered best practise to attach more than a
29 * single DOM-ready or window-load handler for a particular page.
30 * Although scripts in the WordPress core, Plugins and Themes may be
31 * practising this, we should strive to set a better example in our own work.
32 */
33
34 jQuery(document).ready(function ($) {
35
36 // ---delete import funnel notice permanently ------
37 $(document).on("click", ".wpfnl-import-notice .notice-dismiss", function(event) {
38 event.preventDefault();
39 var nonce = $('#wpfnl-import-nonce').val();
40
41 // Use standard WP ajaxurl if available or WPFunnelVars
42 var reqUrl = (typeof ajaxurl !== 'undefined') ? ajaxurl : (window.WPFunnelVars && window.WPFunnelVars.ajaxurl ? window.WPFunnelVars.ajaxurl : '');
43 if (reqUrl) {
44 $.ajax({
45 url: reqUrl,
46 type: 'POST',
47 data: {
48 action: 'wpfnl_hide_import_funnel_notice',
49 security: nonce
50 }
51 });
52 }
53 });
54
55 //date format
56 function PresentDateForm(date) {
57 var date = new Date(date),
58 day = date.getDate(),
59 month = date.getMonth() + 1, //Months are zero based
60 year = date.getFullYear(),
61 date = new Date(year + '-' + month + '-' + day).toDateString()
62 return date
63 }
64
65 function CompareDateForm(date) {
66 var date = new Date(date),
67 day = date.getDate(),
68 month = date.getMonth() + 1, //Months are zero based
69 year = date.getFullYear() - 1,
70 date = new Date(year + '-' + month + '-' + day).toDateString()
71 return date
72 }
73
74 // -------analytics line chart filter-------
75 function wpfnlDatePicker() {
76 $('.wpfunnel-datepicker').datepicker({
77 maxDate: 0,
78 changeMonth: true,
79 changeYear: true,
80 showOtherMonths: true,
81 selectOtherMonths: true,
82 beforeShowDay: function (date) {
83 let date1 = $.datepicker.parseDate(
84 $.datepicker._defaults.dateFormat,
85 $('#date_from_value').val(),
86 )
87 let date2 = $.datepicker.parseDate(
88 $.datepicker._defaults.dateFormat,
89 $('#date_to_value').val(),
90 )
91
92 let isStartDate = date1 && date.getTime() === date1.getTime()
93 let isEndDate = date2 && date.getTime() === date2.getTime()
94
95 return [
96 true,
97 isStartDate || (date2 && date >= date1 && date <= date2) ? 'in-range' : '',
98 isStartDate ? 'Start' : isEndDate ? 'End' : '',
99 ]
100 },
101 onSelect: function (dateText, inst) {
102 let date1 = $.datepicker.parseDate(
103 $.datepicker._defaults.dateFormat,
104 $('#date_from_value').val(),
105 )
106 let date2 = $.datepicker.parseDate(
107 $.datepicker._defaults.dateFormat,
108 $('#date_to_value').val(),
109 )
110 let selectedDate = $.datepicker.parseDate(
111 $.datepicker._defaults.dateFormat,
112 dateText,
113 )
114 const months = [
115 'Jan',
116 'Feb',
117 'Mar',
118 'Apr',
119 'May',
120 'Jun',
121 'Jul',
122 'Aug',
123 'Sep',
124 'Oct',
125 'Nov',
126 'Dec',
127 ]
128 const formattedDate =
129 months[selectedDate.getMonth()] +
130 ' ' +
131 selectedDate.getDate() +
132 ', ' +
133 selectedDate.getFullYear()
134
135 if (!date1 || date2) {
136 $('#date-from').val(formattedDate)
137 $('#date_from_value').val(dateText)
138 $('li.select-from-date').text(dateText).css('color', '#2D3149')
139
140 $('#date-to').val('')
141 $('#date_to_value').val('')
142 $(this).datepicker()
143 $('.analytics-header .custom-date-range').show()
144 } else if (selectedDate < date1) {
145 $('#date-to').val($('#date-from').val())
146 $('#date_to_value').val($('#date_from_value').val())
147 $('#date-from').val(formattedDate)
148 $('#date_from_value').val(dateText)
149
150 $('li.select-to-date')
151 .text($('li.select-from-date').text())
152 .css('color', '#2D3149')
153 $('li.select-from-date').text(dateText).css('color', '#2D3149')
154
155 $(this).datepicker()
156 } else {
157 $('#date-to').val(formattedDate)
158 $('#date_to_value').val(dateText)
159 $('li.select-to-date').text(dateText).css('color', '#2D3149')
160 $(this).datepicker()
161 $('.analytics-header .custom-date-range').show()
162 }
163 },
164 })
165 }
166
167 $('.wpfnl_muliple_select').select2()
168 // edit field error handle
169 $('.wpfnl-section-type-error').hide()
170 $('.wpfnl-field-type-error').hide()
171 $('.wpfnl-name-type-error').hide()
172 $('.wpfnl-label-type-error').hide()
173
174 //--------show calendar when select as custom filter----------
175 $(document).on('change', '#analytics-filter', function () {
176 let selectedValue = $(this).find(':selected').val()
177
178 if ('custom' === selectedValue) {
179 var selectedDate = $('#date-from').val()
180 $('.wpfnl-analytics .overlay-click').show()
181 $('.analytics-header .custom-date-range').show()
182 $('.analytics-header .header-right').addClass('show-calendar')
183 } else {
184 $('.wpfnl-analytics .overlay-click').hide()
185
186 $('.analytics-header .header-right').removeClass('show-calendar')
187 $('.analytics-header .custom-date-range').hide()
188 }
189 })
190
191 //--------hide calendar when click on calender filter button----------
192 $(document).on('click', '.do-filter', function (e) {
193 $('.analytics-header .header-right').removeClass('show-calendar')
194 $('.wpfnl-analytics .overlay-click').hide()
195 })
196
197 //--------analytics calendar filter dropdown----------
198 $(document).on('click', '.filter-selectbox', function (e) {
199 e.stopPropagation()
200 $(this).parents('.header-right').toggleClass('show-calendar')
201 $('.wpfnl-analytics .overlay-click').show()
202 })
203 $(document).on('click', '.calendar-dorpdown', function (e) {
204 e.stopPropagation()
205 })
206 $(document).on('click', '.wpfnl-analytics .overlay-click', function () {
207 $(this).hide()
208 $('.analytics-header .header-right').removeClass('show-calendar')
209 })
210
211 //--------analytics filter header dropdown----------
212 $(document).on('click', '.funnel-steps > li', function (e) {
213 e.preventDefault()
214 e.stopPropagation()
215 $(this).addClass('active')
216 $(this).siblings('li').removeClass('active')
217 $(this).children('.wpfnl-dropdown').toggleClass('show-dropdown')
218 $(this).siblings('li').children('.wpfnl-dropdown').removeClass('show-dropdown')
219 })
220 $(document).on('click', 'body', function () {
221 $('.chart-header .funnel-steps .wpfnl-dropdown').removeClass('show-dropdown')
222 })
223
224 // -------show/hide step stats info-------
225 $(document).on('change', '#stats', function (e) {
226 if ($(this).is(':checked')) {
227 $('.node-wrapper .node-stats').show()
228 } else {
229 $('.node-wrapper .node-stats').hide()
230 }
231 })
232
233 var FunnelHandler = function () {
234 this.initStepSortable()
235 this.initProductSortable()
236 $(document.body).on('submit', '#wpfnl-change-funnel-name', this.changeFunnelName)
237
238 $('.wpfnl-duplicate-funnel').on('click', this.cloneFunnel)
239 $('.wpfnl-delete-funnel').on('click', this.deleteFunnel)
240 $('.wpfnl-permanent-delete-funnel').on('click', this.permanentDeleteFunnel)
241 $('.wpfnl-restore-funnel').on('click', this.restoreFunnel)
242 $('.wpfnl-update-funnel-status').on('click', this.UpdateFunnelStatus)
243 $('.wpfnl-export-funnel').on('click', this.ExportFunnel)
244 $('.wpfnl-export-all-funnels').on('click', this.ExportAllFunnel)
245 $('#wpfnl-import-funnels').on('submit', this.ImportFunnels)
246 $('#wpfnl-import-funnels').on('change', this.UploadFile)
247 $('.wpfnl-import-funnels').on('click', this.ShowImportFunnelModal)
248 $(
249 '.import-funnel-modal .close-modal, .import-funnel-modal .import-funnel-modal-inner',
250 ).on('click', this.CloseImportFunnelModal)
251 $('.import-funnel-modal .import-funnel-modal-wrapper').on(
252 'click',
253 this.PreventImportFunnelModal,
254 )
255
256 $(document.body).on('click', '.wpfnl-bulk-trash', this.bulkTrashFunnel)
257 $(document.body).on('click', '.wpfnl-bulk-delete', this.bulkDeleteFunnel)
258 $(document.body).on('click', '.wpfnl-bulk-restore', this.bulkRestoreFunnel)
259 $(document.body).on('click', '.wpfnl-bulk-export', this.bulkExportFunnel)
260 }
261
262 /**
263 * Select quantity
264 *
265 * @since 1.0.0
266 */
267 $('input[name=quantity]').change(function () {
268 var val = parseInt(this.value)
269 var product = $(this).attr('data-product')
270
271 for (var i in product_option) {
272 if (product_option[i].id == product) {
273 product_option[i].quantity = val
274 break //Stop this loop, we found it!
275 }
276 }
277 })
278
279 /**
280 * Subtext Setup
281 *
282 * @since 1.0.0
283 */
284 $('input[name=subtext]').change(function () {
285 var val = $(this).val()
286 var product = $(this).attr('data-product')
287
288 for (var i in product_option) {
289 if (product_option[i].id == product) {
290 product_option[i].subtext = val
291 break //Stop this loop, we found it!
292 }
293 }
294 })
295
296 /**
297 * Highlight Text Setup
298 *
299 * @since 1.0.0
300 */
301 $('input[name=text-highlight]').change(function () {
302 var val = $(this).val()
303 var product = $(this).attr('data-product')
304
305 for (var i in product_option) {
306 if (product_option[i].id == product) {
307 product_option[i].text_highlight = val
308 break //Stop this loop, we found it!
309 }
310 }
311 })
312
313 /**
314 * Enable Highlight setup
315 *
316 * @since 1.0.0
317 */
318 $('input[name=hide-img-mobile]').change(function () {
319 if (this.checked) {
320 var val = 'on'
321 } else {
322 var val = 'off'
323 }
324
325 var product = $(this).attr('data-product')
326
327 for (var i in product_option) {
328 if (product_option[i].id == product) {
329 product_option[i].enable_highlight = val
330 break //Stop this loop, we found it!
331 }
332 }
333 })
334
335 /**
336 * Sort step order
337 *
338 * @since 1.0.0
339 */
340 FunnelHandler.prototype.initStepSortable = function () {
341 $('#wpfnl-funnel-step-lists').sortable({
342 axis: 'y',
343 start: function (event, ui) {},
344 update: function (event, ui) {
345 var order = $('#wpfnl-funnel-step-lists').sortable('toArray')
346
347 var funnel_id = getUrlParameter('id')
348
349 var payload = {
350 funnel_id: funnel_id,
351 order: order,
352 }
353 wpAjaxHelperRequest('funnel-drag-order', payload)
354 .success(function (response) {})
355 .error(function (response) {
356 // console.log('error');
357 })
358 },
359 })
360 $('#wpfnl-funnel-step-lists').disableSelection()
361 }
362
363 /**
364 * Sort product accordion order
365 *
366 * @since 1.0.0
367 */
368 FunnelHandler.prototype.initProductSortable = function () {
369 $('.product-single-accordion__sortable-wrapper').sortable({
370 axis: 'y',
371 start: function (event, ui) {},
372 update: function (event, ui) {
373 var product_order = $('.product-single-accordion__sortable-wrapper').sortable(
374 'toArray',
375 )
376
377 product_option = []
378 var funnel_id = getUrlParameter('id')
379
380 for (var i in product_order) {
381 var dragger_id = product_order[i]
382 var prod_id = dragger_id.replace('product__single-accordion-', '')
383 var quantity = $('#product-quantity-' + prod_id).val()
384 product_option.push({
385 id: prod_id,
386 quantity: quantity,
387 })
388 }
389 },
390 })
391 $('.product-single-accordion__sortable-wrapper').disableSelection()
392 }
393
394 /**
395 *
396 * Ajax handler for duplicate
397 * funnel action
398 *
399 * @param event
400 * @since 1.0.0
401 */
402 FunnelHandler.prototype.cloneFunnel = function (event) {
403 event.preventDefault()
404
405 const $this = $(this)
406 const funnel_id = $this.attr('data-id')
407 const loader = $this.find('.wpfnl-loader')
408
409 $this.css('pointer-events', 'none')
410 loader.show()
411
412 wpAjaxHelperRequest('clone-funnel', { funnel_id })
413 .success(response => {
414 localStorage.setItem('wpfnl_show_toast', 'clone_success')
415 window.location.href = response.redirectUrl
416 })
417 .error(handleAjaxError('Clone failed'))
418 .always(() => loader.hide())
419 }
420
421 /**
422 * delete funnel and all the related
423 * data
424 *
425 * @param event
426 * @since 1.0.0
427 */
428
429 FunnelHandler.prototype.deleteFunnel = function (event) {
430 event.preventDefault()
431
432 const funnel_id = $(this).attr('data-id')
433 if (!confirm('Are you sure?')) return
434
435 wpAjaxHelperRequest('trash-funnel', { funnel_id })
436 .success(response => {
437 localStorage.setItem('wpfnl_show_toast', 'trash_success')
438 window.location.href = response.redirectUrl
439 })
440 .error(handleAjaxError('Trash failed'))
441 }
442
443 // Toast logic on page load
444 function showToast(type, message) {
445 const icons = {
446 success: '<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>',
447 error: '<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>'
448 }
449
450 const toastClass = type === 'success'
451 ? 'quick-toastify-successful-notification'
452 : 'quick-toastify-warn-notification'
453
454 $('#wpfnl-toaster-wrapper')
455 .removeClass()
456 .addClass(toastClass)
457 .show()
458
459 $('#wpfnl-toaster-icon').html(icons[type])
460 $('#wpfnl-toaster-message').html(message)
461
462 setTimeout(() => {
463 $('#wpfnl-toaster-wrapper').removeClass(toastClass).hide()
464 }, 3000)
465 }
466 function handleAjaxError(message = 'Something went wrong') {
467 return function () {
468 console.error(message)
469 showToast('error', message)
470 }
471 }
472 function showToastFromStorage() {
473 const toastMap = {
474 trash_success: 'The funnel has been moved to Trash.',
475 clone_success: 'The funnel has been duplicated successfully.',
476 status_updated: 'Funnel status has been updated successfully.',
477 bulk_trash_success: 'The selected funnels have been moved to Trash.',
478 bulk_delete_success: 'The selected funnels have been deleted permanently.',
479 bulk_restore_success: 'The selected funnels have been restored successfully.',
480 }
481
482 const toastKey = localStorage.getItem('wpfnl_show_toast')
483 if (!toastKey || !toastMap[toastKey]) return
484
485 localStorage.removeItem('wpfnl_show_toast')
486 showToast('success', toastMap[toastKey])
487 }
488
489 $(showToastFromStorage)
490
491
492
493
494
495 /**
496 * delete funnel and all the related
497 * data
498 *
499 * @param event
500 * @since 1.0.0
501 */
502 FunnelHandler.prototype.permanentDeleteFunnel = function (event) {
503 event.preventDefault()
504 var funnel_id = $(this).attr('data-id')
505 var payload = {
506 funnel_id: funnel_id,
507 }
508 if (confirm('Are you sure?')) {
509 wpAjaxHelperRequest('delete-funnel', payload)
510 .success(function (response) {
511 window.location.href = response.redirectUrl
512 })
513 .error(function (response) {})
514 }
515 }
516
517 /**
518 * delete funnel and all the related
519 * data
520 *
521 * @param event
522 * @since 1.0.0
523 */
524 FunnelHandler.prototype.restoreFunnel = function (event) {
525 event.preventDefault()
526 var funnel_id = $(this).attr('data-id')
527 var payload = {
528 funnel_id: funnel_id,
529 }
530 if (confirm('Are you sure?')) {
531 wpAjaxHelperRequest('restore-funnel', payload)
532 .success(function (response) {
533 window.location.href = response.redirectUrl
534 })
535 .error(function (response) {})
536 }
537 }
538
539 /**
540 * bulk delete funnel and all the related
541 * data
542 *
543 * @param event
544 * @since 1.0.0
545 */
546 FunnelHandler.prototype.bulkDeleteFunnel = function (event) {
547 event.preventDefault()
548 let funnel_ids = selectedIds
549
550 let payload = {
551 ids: funnel_ids,
552 }
553
554 if (confirm('Are you sure?')) {
555 fetch(
556 `${window.template_library_object.rest_api_url}wpfunnels/v1/funnel-control/bulk-delete-funnel`,
557 {
558 method: 'POST',
559 headers: {
560 'Content-Type': 'application/json',
561 'X-WP-Nonce': wpApiSettings.nonce,
562 },
563 body: JSON.stringify(payload),
564 },
565 )
566 .then((response) => response.json())
567 .then((data) => {
568 if (data.success) {
569 localStorage.setItem('wpfnl_show_toast', 'bulk_delete_success'),
570 window.location.href = data.redirectUrl
571 }
572 })
573 .catch((error) => {
574 console.error('Error:', error)
575 })
576 }
577 selectedIds = []
578 }
579
580 /**
581 * bulk trash funnel and all the related
582 * data
583 *
584 * @param event
585 * @since 1.0.0
586 */
587 FunnelHandler.prototype.bulkTrashFunnel = function (event) {
588 event.preventDefault()
589 let funnel_ids = selectedIds
590
591 let payload = {
592 ids: funnel_ids,
593 }
594
595 if (confirm('Are you sure?')) {
596 fetch(
597 `${window.template_library_object.rest_api_url}wpfunnels/v1/funnel-control/bulk-trash-funnel`,
598 {
599 method: 'POST',
600 headers: {
601 'Content-Type': 'application/json',
602 'X-WP-Nonce': wpApiSettings.nonce,
603 },
604 body: JSON.stringify(payload),
605 },
606 )
607 .then((response) => response.json())
608 .then((data) => {
609 if (data.success) {
610 localStorage.setItem('wpfnl_show_toast', 'bulk_trash_success')
611 window.location.href = data.redirectUrl
612 }
613 })
614 .catch((error) => {
615 handleAjaxError('Trash failed')
616 })
617 }
618 selectedIds = []
619 }
620
621 /**
622 * bulk delete funnel and all the related
623 * data
624 *
625 * @param event
626 * @since 1.0.0
627 */
628 FunnelHandler.prototype.bulkRestoreFunnel = function (event) {
629 event.preventDefault()
630 let funnel_ids = selectedIds
631
632 let payload = {
633 ids: funnel_ids,
634 }
635
636 if (confirm('Are you sure?')) {
637 fetch(
638 `${window.template_library_object.rest_api_url}wpfunnels/v1/funnel-control/bulk-restore-funnel`,
639 {
640 method: 'POST',
641 headers: {
642 'Content-Type': 'application/json',
643 'X-WP-Nonce': wpApiSettings.nonce,
644 },
645 body: JSON.stringify(payload),
646 },
647 )
648 .then((response) => response.json())
649 .then((data) => {
650 if (data.success) {
651 localStorage.setItem('wpfnl_show_toast', 'bulk_restore_success')
652 window.location.href = data.redirectUrl
653 }
654 })
655 .catch((error) => {
656 console.error('Error:', error)
657 })
658 }
659 selectedIds = []
660 }
661
662 /**
663 * Update funnel status
664 * data
665 *
666 * @param event
667 * @since 1.0.0
668 */
669 FunnelHandler.prototype.UpdateFunnelStatus = function (event) {
670 event.preventDefault()
671
672 const funnel_id = $(this).attr('data-id')
673 const new_status = $(this).attr('data-status')
674 if (!confirm('Are you sure?')) return
675
676 wpAjaxHelperRequest('update-funnel-status', { funnel_id, status: new_status })
677 .success(response => {
678 localStorage.setItem('wpfnl_show_toast', 'status_updated')
679 window.location.href = response.redirect_url
680 })
681 .error(handleAjaxError('Status update failed'))
682 }
683
684 /**
685 *
686 * Ajax handler for export a single funnel
687 * funnel action
688 *
689 * @param event
690 * @since 2.6.3
691 */
692 FunnelHandler.prototype.ExportFunnel = function (event) {
693 event.preventDefault()
694
695 var funnel_id = $(this).attr('data-id'),
696 loader = $(this).find('.wpfnl-loader')
697 var payload = {
698 funnel_id: funnel_id,
699 }
700
701 $(this).css('pointer-events', 'none')
702 loader.show()
703
704 wpAjaxHelperRequest('wpfnl-export-funnel', payload)
705 .success(function (response) {
706 if (response.success) {
707 const jsonData = response.steps
708 const filename = response.title + '.json'
709 download(JSON.stringify(jsonData), filename, 'text/plain')
710 }
711 loader.hide()
712 })
713 .error(function (response) {
714 loader.hide()
715 })
716 }
717
718 /**
719 *
720 * Ajax handler for export a single funnel
721 * funnel action
722 *
723 * @param event
724 * @since 2.6.3
725 */
726 FunnelHandler.prototype.ExportAllFunnel = function (event) {
727 event.preventDefault()
728
729 var status = 'all',
730 loader = $(this).find('.wpfnl-loader')
731 var payload = {
732 status: status,
733 }
734
735 $(this).css('pointer-events', 'none')
736 loader.show()
737
738 wpAjaxHelperRequest('wpfnl-export-all-funnels', payload)
739 .success(function (response) {
740 if (response.success) {
741 const jsonData = response.data
742
743 var today = new Date()
744 var dd = String(today.getDate()).padStart(2, '0')
745 var mm = String(today.getMonth() + 1).padStart(2, '0') //January is 0!
746 var yyyy = today.getFullYear()
747 today = mm + '-' + dd + '-' + yyyy
748 const filename = 'wpfunnels-export-' + today + '-.json'
749
750 download(JSON.stringify(jsonData), filename, 'text/plain')
751 }
752 loader.hide()
753 })
754 .error(function (response) {
755 loader.hide()
756 })
757 }
758
759 /**
760 *
761 * Ajax handler for export bulk funnels
762 * funnel action
763 *
764 * @param event
765 * @since 2.7.19
766 */
767 FunnelHandler.prototype.bulkExportFunnel = function (event) {
768 event.preventDefault()
769
770 let funnel_ids = selectedIds
771
772 let status = 'all',
773 loader = $(this).find('.wpfnl-loader')
774 let payload = {
775 status: status,
776 ids: funnel_ids,
777 }
778
779 $(this).css('pointer-events', 'none')
780 loader.show()
781
782 fetch(
783 `${window.template_library_object.rest_api_url}wpfunnels/v1/import-export/bulk-export-funnel`,
784 {
785 method: 'POST',
786 headers: {
787 'Content-Type': 'application/json',
788 'X-WP-Nonce': wpApiSettings.nonce,
789 },
790 body: JSON.stringify(payload),
791 },
792 )
793 .then((response) => response.json())
794 .then((data) => {
795 if (data.success) {
796 const jsonData = data.data
797
798 let today = new Date()
799 let dd = String(today.getDate()).padStart(2, '0')
800 let mm = String(today.getMonth() + 1).padStart(2, '0') // January is 0!
801 let yyyy = today.getFullYear()
802 today = mm + '-' + dd + '-' + yyyy
803 const filename = 'wpfunnels-export-' + today + '-.json'
804
805 download(JSON.stringify(jsonData), filename, 'text/plain')
806 }
807 loader.hide()
808 window.location.href = data.redirectUrl
809 })
810 .catch((error) => {
811 console.error('Error:', error)
812 loader.hide()
813 })
814 selectedIds = []
815 }
816
817 /**
818 * Show import funnels Modal
819 *
820 * @param event
821 * @since 2.6.3
822 */
823 FunnelHandler.prototype.ShowImportFunnelModal = function (e) {
824 e.stopPropagation()
825 e.preventDefault()
826 $('.import-funnel-modal').addClass('show-modal')
827 }
828
829 /**
830 * Stop Propagation for .import-funnel-modal-wrapper
831 *
832 */
833 FunnelHandler.prototype.PreventImportFunnelModal = function (e) {
834 e.stopPropagation()
835 }
836
837 /**
838 * Close import funnels Modal
839 *
840 * @param event
841 * @since 2.6.3
842 */
843 FunnelHandler.prototype.CloseImportFunnelModal = function (e) {
844 e.preventDefault()
845 $('.import-funnel-modal').removeClass('show-modal')
846 $('#wpfnl-export-import-warning').css('display', 'none')
847 }
848
849 /**
850 * Show import funnels Modal
851 *
852 * @param event
853 * @since 2.6.3
854 */
855 FunnelHandler.prototype.ShowImportFunnelModal = function (e) {
856 e.stopPropagation()
857 e.preventDefault()
858 $('.import-funnel-modal').addClass('show-modal')
859 }
860
861 /**
862 * Stop Propagation for .import-funnel-modal-wrapper
863 *
864 */
865 FunnelHandler.prototype.PreventImportFunnelModal = function (e) {
866 e.stopPropagation()
867 }
868
869 /**
870 * Close import funnels Modal
871 *
872 * @param event
873 * @since 2.6.3
874 */
875 FunnelHandler.prototype.CloseImportFunnelModal = function (e) {
876 e.preventDefault()
877 $('.import-funnel-modal').removeClass('show-modal')
878 $('#wpfnl-export-import-warning').css('display', 'none')
879 }
880
881 /**
882 * Show a validation/error message inside the import funnel modal.
883 *
884 * The message element carries a default text, so it is always set
885 * explicitly here to avoid leaking a previous message.
886 *
887 * @param message
888 * @since 2.6.3
889 */
890 FunnelHandler.prototype.ShowImportWarning = function (message) {
891 $('#wpfnl-export-import-warning')
892 .text(message || 'Please select a valid file.')
893 .css('display', 'inline-block')
894 $('#wpfnl-import-funnel .wpfnl-loader').css('display', 'none')
895 }
896
897 /**
898 * Pull the error message out of an ajax response.
899 *
900 * wp_send_json_error() responses arrive either as a parsed body
901 * (HTTP 200) or on the jqXHR when a status code was passed.
902 *
903 * @param response
904 * @since 2.6.3
905 */
906 FunnelHandler.prototype.GetImportErrorMessage = function (response) {
907 const body = response && response.responseJSON ? response.responseJSON : response
908
909 if (body && body.data && body.data.message) {
910 return body.data.message
911 }
912
913 if (body && typeof body.data === 'string') {
914 return body.data
915 }
916
917 return ''
918 }
919
920 /**
921 *
922 * Ajax handler for import funnels
923 * funnel action
924 *
925 * @param event
926 * @since 2.6.3
927 */
928 FunnelHandler.prototype.ImportFunnels = function (event) {
929 event.preventDefault()
930 // `this` is the submitted form here, so reach the helpers via the prototype.
931 const handler = FunnelHandler.prototype
932 $('#wpfnl-import-funnel .wpfnl-loader').css('display', 'inline-block')
933 $('#wpfnl-export-import-warning').css('display', 'none')
934 let formData = new FormData(this)
935 let importFile = $('#wpfnl-file-import')[0].files[0]
936 if (importFile) {
937 const fileName = importFile?.name
938 const fileExtension = fileName.split('.').pop()
939 if ('json' === fileExtension) {
940 formData.append('action', 'wpfnl_import_funnels')
941 formData.append('is_ajax', 'yes')
942 formData.append('nonce', WPFunnelVars.import_nonce)
943 formData.append('uploaded_file', importFile)
944
945 $.ajax({
946 url: WPFunnelVars.ajaxurl,
947 type: 'post',
948 contentType: false,
949 dataType: 'json',
950 processData: false,
951 data: formData,
952 success: function (response) {
953 // wp_send_json_error() without a status code still returns HTTP 200.
954 if (response && false === response.success) {
955 handler.ShowImportWarning(handler.GetImportErrorMessage(response))
956 return
957 }
958 $('#wpfnl-import-funnel .wpfnl-loader').css('display', 'none')
959 $('.import-funnel-modal').removeClass('show-modal')
960 window.location.reload()
961 },
962 error: function (jqXHR) {
963 // Validation failures are sent with a 4xx status code.
964 handler.ShowImportWarning(handler.GetImportErrorMessage(jqXHR))
965 },
966 })
967 } else {
968 handler.ShowImportWarning('Please select a valid file.')
969 }
970 } else {
971 handler.ShowImportWarning('Please select a valid file.')
972 }
973 }
974
975 /**
976 *
977 * Ajax handler for import funnels
978 * funnel action
979 *
980 * @param event
981 * @since 2.6.3
982 */
983 FunnelHandler.prototype.UploadFile = function (event) {
984 event.preventDefault()
985 $('#wpfnl-export-import-warning').css('display', 'none')
986 let importFile = $('#wpfnl-file-import')[0].files[0]
987
988 if (importFile) {
989 const fileName = importFile?.name
990 const fileExtension = fileName.split('.').pop()
991
992 if ('json' === fileExtension) {
993 $('#wpfnl-export-import-warning').css('display', 'none')
994 $('.import-funnel-modal .import-label').addClass('file-added')
995 $('.import-funnel-modal .import-label > h4').text('Json file ready for import.')
996 $('.import-funnel-modal .import-label > p').text(fileName)
997 } else {
998 $('.import-funnel-modal .import-label').removeClass('file-added')
999 FunnelHandler.prototype.ShowImportWarning('Please select a valid file.')
1000
1001 $('.import-funnel-modal .import-label > h4').html(
1002 'Drag & Drop or <span class="primary-color">Choose file</span> to upload.',
1003 )
1004 $('.import-funnel-modal .import-label > p').text(
1005 'Supported formats: JSON file.',
1006 )
1007 }
1008 } else {
1009 $('.import-funnel-modal .import-label').removeClass('file-added')
1010 FunnelHandler.prototype.ShowImportWarning('Please select a valid file.')
1011
1012 $('.import-funnel-modal .import-label > h4').html(
1013 'Drag & Drop or <span class="primary-color">Choose file</span> to upload.',
1014 )
1015 $('.import-funnel-modal .import-label > p').text('Supported formats: JSON file.')
1016 }
1017 }
1018
1019 /**
1020 * Download json file
1021 *
1022 * @param content
1023 * @param fileName
1024 * @param contentType
1025 *
1026 * @since 2.6.3
1027 */
1028 function download(content, fileName, contentType) {
1029 const a = document.createElement('a')
1030 const file = new Blob([content], { type: contentType })
1031 a.href = URL.createObjectURL(file)
1032 a.download = fileName
1033 a.click()
1034 }
1035
1036 /**
1037 * Realtime funnel name change on header
1038 *
1039 * @param event
1040 * @since 1.0.0
1041 */
1042 var fnl_name = ''
1043 var fnl_name2 = ''
1044 var funnelNameWidth = ''
1045 $('.funnel-name-edit').on('click', function (e) {
1046 e.stopPropagation();
1047 fnl_name = $(this).parents('.steps-page__fnl-name').find('.funnel-name').text()
1048 $(this).hide()
1049 funnelNameWidth = $(this).parents('.steps-page__fnl-name').find('.funnel-name').width()
1050
1051 $(this)
1052 .parents('.steps-page__fnl-name')
1053 .find('.funnel-name-input')
1054 .css('width', funnelNameWidth + 'px')
1055 $(this)
1056 .parents('.steps-page__fnl-name')
1057 .find('.funnel-name-input')
1058 .val(fnl_name)
1059 .show()
1060 .focus()
1061 $(this).parents('.steps-page__fnl-name').find('.funnel-name').hide()
1062 })
1063
1064 $('.funnel-name-input').keyup(function (e) {
1065 e.stopPropagation();
1066 $(this).parents('.steps-page__fnl-name').find('.funnel-name').text($(this).val())
1067 funnelNameWidth = $(this).parents('.steps-page__fnl-name').find('.funnel-name').width()
1068
1069 let input = $(this);
1070 let valueLength = input.val().length;
1071 input.css('width', funnelNameWidth + 'px');
1072
1073 // When Enter is pressed, save and hide input, show funnel name
1074 if (e.keyCode === 13 || e.key === 'Enter') {
1075 fnl_name2 = $(this).val();
1076
1077 if(fnl_name2.length === 0){
1078 fnl_name2 = fnl_name;
1079 }
1080
1081 $(this).val(fnl_name2).hide();
1082 $(this).parents('.steps-page__fnl-name').find('.funnel-name').text(fnl_name2).show();
1083 $(this).blur(); // Remove focus from input
1084 }
1085 })
1086
1087 $('.funnel-name-input').on('click', function (e) {
1088 e.stopPropagation();
1089 })
1090
1091 if($('.funnel-name-input').length > 0){
1092 $('body').on('click', function (e) {
1093 fnl_name2 = $('.steps-page__fnl-name .funnel-name-input').val() || '';
1094
1095 if(fnl_name2.length === 0){
1096 fnl_name2 = fnl_name;
1097 }
1098
1099 $('.steps-page__fnl-name .funnel-name-input').val(fnl_name2).hide()
1100 $('.steps-page__fnl-name .funnel-name').text(fnl_name2).show()
1101 })
1102 }
1103
1104 /**
1105 * Realtime automation name change on automation drawer
1106 *
1107 * @param event
1108 * @since 1.0.0
1109 */
1110 var automation_name = ''
1111 var automation_name2 = ''
1112 $(document).on('click', '.automation-name-edit', function (e) {
1113 e.preventDefault()
1114
1115 automation_name = $(this)
1116 .parents('.automation-name-wrapper')
1117 .find('.automation-name-preview')
1118 .text()
1119 $(this).hide()
1120 $('.automation-name-cancel').css('display', 'flex')
1121 $(this)
1122 .parents('.automation-name-wrapper')
1123 .find('.automation-name-input')
1124 .val(automation_name)
1125 .css('display', 'flex')
1126 $(this).parents('.automation-name-wrapper').find('.automation-name-preview').hide()
1127 $(this)
1128 .parents('.automation-name-wrapper')
1129 .find('.automation-name-submit')
1130 .css('display', 'flex')
1131 })
1132
1133 // $(document).on("click", ".automation-name-edit", function(e) {
1134 $('.automation-name-input').keyup(function () {
1135 $(this)
1136 .parents('.automation-name-wrapper')
1137 .find('.automation-name-preview')
1138 .text($(this).val())
1139 })
1140
1141 $(document).on('click', '.automation-name-submit', function (e) {
1142 e.preventDefault()
1143 automation_name2 = $(this)
1144 .parents('.automation-name-wrapper')
1145 .find('.automation-name-input')
1146 .val()
1147 $(this).hide()
1148 $('.automation-name-cancel').hide()
1149 $(this)
1150 .parents('.automation-name-wrapper')
1151 .find('.automation-name-input')
1152 .val(automation_name2)
1153 .hide()
1154 $(this)
1155 .parents('.automation-name-wrapper')
1156 .find('.automation-name-preview')
1157 .text(automation_name2)
1158 .css('display', 'flex')
1159 $(this)
1160 .parents('.automation-name-wrapper')
1161 .find('.automation-name-edit')
1162 .css('display', 'flex')
1163 })
1164
1165 $(document).on('click', '.automation-name-cancel', function (e) {
1166 e.preventDefault()
1167 $(this).hide()
1168 $('.automation-name-cancel').hide()
1169 $(this)
1170 .parents('.automation-name-wrapper')
1171 .find('.automation-name-input')
1172 .val(automation_name)
1173 .hide()
1174 $(this)
1175 .parents('.automation-name-wrapper')
1176 .find('.automation-name-preview')
1177 .text(automation_name)
1178 .css('display', 'flex')
1179 $(this).parents('.automation-name-wrapper').find('.automation-name-submit').hide()
1180 $(this)
1181 .parents('.automation-name-wrapper')
1182 .find('.automation-name-edit')
1183 .css('display', 'flex')
1184 })
1185
1186 $(document).on('click', '#save_automation', function (e) {
1187 e.preventDefault()
1188 $('.event-trigger').each(function () {
1189 if ($(this).children('option:selected').val() == '') {
1190 $(this).parents('.wpfnl-form-group').addClass('field-required')
1191 } else {
1192 $(this).parents('.wpfnl-form-group').removeClass('field-required')
1193 }
1194 })
1195 $('.list-trigger').each(function () {
1196 if ($(this).children('option:selected').val() == '') {
1197 $(this).parents('.wpfnl-form-group').addClass('field-required')
1198 } else {
1199 $(this).parents('.wpfnl-form-group').removeClass('field-required')
1200 }
1201 })
1202 $('.tag-trigger').each(function () {
1203 if ($(this).children('option:selected').val() == '') {
1204 $(this).parents('.wpfnl-form-group').addClass('field-required')
1205 } else {
1206 $(this).parents('.wpfnl-form-group').removeClass('field-required')
1207 }
1208 })
1209 })
1210
1211 //-----remove "field-required" class when data selected-------
1212 $(document).on('change', '.single-trigger .selectbox-wrapper select', function (e) {
1213 if ($(this).children('option:selected').val() != '') {
1214 $(this).parents('.wpfnl-form-group').removeClass('field-required')
1215 }
1216 })
1217
1218 /**
1219 * change funnel name
1220 *
1221 * @param event
1222 * @since 1.0.0
1223 */
1224 FunnelHandler.prototype.changeFunnelName = function (event) {
1225 event.preventDefault()
1226 var payload = {
1227 data: $(this).serialize(),
1228 },
1229 button = $(this).find('.funnel-name-submit')
1230 button.hide()
1231 button.parents('.steps-page__fnl-name').find('.funnel-name-input').hide()
1232 button.parents('.steps-page__fnl-name').find('.funnel-name').show()
1233 button.parents('.steps-page__fnl-name').find('.funnel-name-edit').show()
1234 wpAjaxHelperRequest('funnel-name-change', payload)
1235 .success(function (response) {
1236 location.reload()
1237 })
1238 .error(function (response) {})
1239 }
1240
1241 var StepHandler = function () {
1242 $(document.body)
1243 .on('click', '#wpfnl-delete-step', this.deleteStep)
1244 .on('click', '#wpfnl-update-checkout-product-tab', this.updateCheckoutProduct)
1245 .on('click', '#wpfnl-update-thank-you-settings', this.updateThankYouSettings)
1246 .on('click', '#wpfnl-update-upsell-settings', this.updateUpsellSettings)
1247 .on('click', '#wpfnl-update-downsell-settings', this.updateDownsellSettings)
1248 .on('change', '#wpfnl-choose-step-type', this.stepTypeChange)
1249 // .on('click', '#wpfnl-add-product', this.addProduct)
1250 }
1251
1252 /**
1253 * add product
1254 * @param event
1255 */
1256 StepHandler.prototype.addProduct = function (event) {
1257 event.preventDefault()
1258 var _prObj = $('#wpfnl-checkout-products').select2('data')[0],
1259 step_id = $(this).attr('data-id')
1260 if (_prObj) {
1261 product_option.push({
1262 id: _prObj.id,
1263 quantity: 1,
1264 })
1265 var payload = {
1266 id: _prObj.id,
1267 step_id: step_id,
1268 products: JSON.stringify(product_option),
1269 index: parseInt($('.product__single-accordion').length),
1270 },
1271 that = $(this)
1272
1273 wpAjaxHelperRequest('wpfnl-add-product', payload)
1274 .success(function (response) {
1275 if (response.success) {
1276 $('.no-product-notice').hide()
1277 $('.accordion-head').show()
1278 // $('.product-accordion__wrapper').append(response.html);
1279 $('.product-single-accordion__sortable-wrapper').append(response.html)
1280 $('#wpfnl-checkout-products').val(null).trigger('change')
1281 if (product_option.length) that.html('Add product')
1282 // $('.product__single-accordion:nth-child(2)').addClass('active');
1283 }
1284 console.log('Woohoo!')
1285 console.log(response)
1286 $('#setp-list-' + step_id + ' span').css('color', 'black')
1287
1288 $('.product-single-accordion__sortable-wrapper').sortable({
1289 axis: 'y',
1290 start: function (event, ui) {},
1291 update: function (event, ui) {
1292 var product_order = $(
1293 '.product-single-accordion__sortable-wrapper',
1294 ).sortable('toArray')
1295
1296 product_option = []
1297 var funnel_id = getUrlParameter('id')
1298
1299 for (var i in product_order) {
1300 var dragger_id = product_order[i]
1301 var prod_id = dragger_id.replace(
1302 'product__single-accordion-',
1303 '',
1304 )
1305 var quantity = $('#product-quantity-' + prod_id).val()
1306 product_option.push({
1307 id: prod_id,
1308 quantity: quantity,
1309 })
1310 }
1311 },
1312 })
1313 $('.product-single-accordion__sortable-wrapper').disableSelection()
1314 })
1315 .error(function (response) {})
1316 }
1317 }
1318
1319 /**
1320 * delete product from checkout
1321 *
1322 * @param event
1323 */
1324 StepHandler.prototype.deleteproduct = function (event) {
1325 event.preventDefault()
1326 var index = $(this).attr('data-index')
1327 product_option.splice(index, 1)
1328 var payload = {
1329 step_id: $(this).attr('data-id'),
1330 products: JSON.stringify(product_option),
1331 }
1332 wpAjaxHelperRequest('wpfnl-update-checkout-product-tab', payload)
1333 .success(function (response) {
1334 if (response.success) {
1335 location.reload()
1336 return false
1337 }
1338 console.log('Woohoo!')
1339 console.log(response)
1340 })
1341 .error(function (response) {})
1342 }
1343
1344 /**
1345 * save function for checkout steps
1346 * product tab
1347 *
1348 * @param event
1349 * @since 1.0.0
1350 */
1351 StepHandler.prototype.updateCheckoutProduct = function (event) {
1352 event.preventDefault()
1353 var thisLoader = $(this).find('.wpfnl-loader')
1354 var thisAlert = $(this).siblings('.wpfnl-alert')
1355
1356 //=== Enable additional checkout fields===//
1357 var coupon = 'no'
1358 if ($('#enable-checkout-coupon').prop('checked') == true) {
1359 coupon = 'yes'
1360 } else if ($('#enable-checkout-coupon').prop('checked') == false) {
1361 coupon = 'no'
1362 }
1363
1364 //=== Enable additional checkout fields===//
1365
1366 thisLoader.fadeIn()
1367 var payload = {
1368 step_id: $(this).attr('data-iddata-id'),
1369 coupon: coupon,
1370 products: JSON.stringify(product_option),
1371 // discount: $(".wpfnl-checkout-discount").val(),
1372 }
1373 wpAjaxHelperRequest('wpfnl-update-checkout-product-tab', payload)
1374 .success(function (response) {
1375 thisLoader.fadeOut()
1376 thisAlert.text('Saved Successfully').addClass('box wpfnl-success').fadeIn()
1377
1378 setTimeout(function () {
1379 thisAlert.fadeOut().text('').removeClass('box wpfnl-success')
1380 }, 2000)
1381
1382 console.log('Woohoo!')
1383 console.log(response)
1384 })
1385 .error(function (response) {
1386 console.log('Uh, oh!')
1387 console.log(response.statusText)
1388
1389 thisLoader.fadeOut()
1390 thisAlert.text('Erorr occurred').addClass('box wpfnl-error').fadeIn()
1391 setTimeout(function () {
1392 thisAlert.fadeOut().text('').removeClass('box wpfnl-error')
1393 }, 2000)
1394 })
1395 }
1396
1397 /**
1398 * Set minimum time for custom redirection in thankyou page
1399 *
1400 * @param event
1401 *
1402 */
1403 $(document).on('keyup', '#set-time', function () {
1404 if ($('#set-time').val() && $('#set-time').val() < 1) {
1405 $('#set-time').val(1)
1406 }
1407 })
1408
1409 /**
1410 * save thankyou settings
1411 * options
1412 *
1413 * @param event
1414 * @since 1.0.0
1415 */
1416 StepHandler.prototype.updateThankYouSettings = function (event) {
1417 event.preventDefault()
1418 var thisLoader = $(this).find('.wpfnl-loader')
1419 var thisAlert = $(this).siblings('.wpfnl-alert')
1420 thisLoader.fadeIn()
1421 var payload = {
1422 step_id: $(this).attr('data-id'),
1423 text: $('.thankyou-page-text').val(),
1424 redirect_link: $('.thankyou-redirect-link').val(),
1425 order_overview: $('#enable-order-overview').is(':checked') ? 'on' : 'off',
1426 order_details: $('#enable-order-details').is(':checked') ? 'on' : 'off',
1427 billing_details: $('#enable-billing-details').is(':checked') ? 'on' : 'off',
1428 shipping_details: $('#enable-shipping-details').is(':checked') ? 'on' : 'off',
1429 is_custom_redirect: $('#enable-custom-redirect').is(':checked') ? 'on' : 'off',
1430
1431 is_direct_redirect: $('#direct-custom-redirect').is(':checked') ? 'on' : 'off',
1432 set_time: $('#set-time').val(),
1433 custom_redirect_url: $('#custom-redirect-url').val(),
1434 }
1435
1436 wpAjaxHelperRequest('update-thankyou-settings', payload)
1437 .success(function (response) {
1438 thisLoader.fadeOut()
1439 $('#wpfnl-toaster-wrapper').addClass('quick-toastify-successful-notification')
1440
1441 $('#wpfnl-toaster-icon').html(
1442 '<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>',
1443 )
1444
1445 $('#wpfnl-toaster-message').html('Saved Successfully')
1446 $('#wpfnl-toaster-wrapper').show()
1447 setTimeout(function () {
1448 $('#wpfnl-toaster-wrapper').removeClass(
1449 'quick-toastify-successful-notification',
1450 )
1451 $('#wpfnl-toaster-wrapper').hide()
1452 }, 3000)
1453 })
1454 .error(function (response) {
1455 console.log('Uh, oh!')
1456 console.log(response.statusText)
1457 thisLoader.fadeOut()
1458 $('#wpfnl-toaster-wrapper').addClass('quick-toastify-warn-notification')
1459
1460 $('#wpfnl-toaster-icon').html(
1461 '<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>',
1462 )
1463
1464 $('#wpfnl-toaster-message').html('Erorr occurred')
1465 $('#wpfnl-toaster-wrapper').show()
1466 setTimeout(function () {
1467 $('#wpfnl-toaster-wrapper').removeClass('quick-toastify-warn-notification')
1468 $('#wpfnl-toaster-wrapper').hide()
1469 }, 3000)
1470 })
1471 }
1472
1473 /**
1474 * save upsell settings
1475 * options
1476 *
1477 * @param event
1478 * @since 1.0.0
1479 */
1480 StepHandler.prototype.updateUpsellSettings = function (event) {
1481 event.preventDefault()
1482 var thisLoader = $(this).find('.wpfnl-loader')
1483 var thisAlert = $(this).siblings('.wpfnl-alert')
1484 thisLoader.fadeIn()
1485 var payload = {
1486 step_id: $(this).attr('data-id'),
1487 product: $('.wpfnl-product-search').val(),
1488 quantity: $('#upsell-product-quantity').val(),
1489 product_price: $('#upsell-original-price').val(),
1490 product_sale_price: $('#upsell-sale-price').val(),
1491 discount_type: $('#upsell-discount-type').val(),
1492 discount_value: $('#upsell-discount-value').val(),
1493 hide_image: $('#img-hide-mobile').prop('checked') ? 'on' : 'off',
1494 next_step_yes: $('#next-step-yes').val(),
1495 next_step_no: $('#next-step-no').val(),
1496 }
1497 wpAjaxHelperRequest('update-upsell-settings', payload)
1498 .success(function (response) {
1499 thisLoader.fadeOut()
1500 thisAlert.text('Saved Successfully').addClass('box wpfnl-success').fadeIn()
1501 setTimeout(function () {
1502 thisAlert.fadeOut().text('').removeClass('box wpfnl-success')
1503 }, 2000)
1504 console.log('Woohoo!')
1505 console.log(response)
1506 })
1507 .error(function (response) {
1508 console.log('Uh, oh!')
1509 console.log(response.statusText)
1510 thisLoader.fadeOut()
1511 thisAlert.text('Erorr occurred').addClass('box wpfnl-error').fadeIn()
1512 setTimeout(function () {
1513 thisAlert.fadeOut().text('').removeClass('box wpfnl-error')
1514 }, 2000)
1515 })
1516 }
1517
1518 /**
1519 * save downsell settings
1520 * options
1521 *
1522 * @param event
1523 * @since 1.0.0
1524 */
1525 StepHandler.prototype.updateDownsellSettings = function (event) {
1526 event.preventDefault()
1527 var thisLoader = $(this).find('.wpfnl-loader')
1528 var thisAlert = $(this).siblings('.wpfnl-alert')
1529 thisLoader.fadeIn()
1530 var payload = {
1531 step_id: $(this).attr('data-id'),
1532 product: $('.wpfnl-product-search').val(),
1533 quantity: $('#downsell-product-quantity').val(),
1534 product_price: $('#downsell-original-price').val(),
1535 product_sale_price: $('#downsell-sale-price').val(),
1536 discount_type: $('#downsell-discount-type').val(),
1537 discount_value: $('#downsell-discount-value').val(),
1538 hide_image: $('#img-hide-mobile').prop('checked') ? 'on' : 'off',
1539 next_step_yes: $('#next-step-yes').val(),
1540 next_step_no: $('#next-step-no').val(),
1541 }
1542 wpAjaxHelperRequest('update-downsell-settings', payload)
1543 .success(function (response) {
1544 thisLoader.fadeOut()
1545 thisAlert.text('Saved Successfully').addClass('box wpfnl-success').fadeIn()
1546 setTimeout(function () {
1547 thisAlert.fadeOut().text('').removeClass('box wpfnl-success')
1548 }, 2000)
1549 console.log('Woohoo!')
1550 console.log(response)
1551 })
1552 .error(function (response) {
1553 console.log('Uh, oh!')
1554 console.log(response.statusText)
1555 thisLoader.fadeOut()
1556 thisAlert.text('Erorr occurred').addClass('box wpfnl-error').fadeIn()
1557 setTimeout(function () {
1558 thisAlert.fadeOut().text('').removeClass('box wpfnl-error')
1559 }, 2000)
1560 })
1561 }
1562
1563 /**
1564 * Ajax handler for step
1565 * deletion action
1566 *
1567 * @param event
1568 */
1569 StepHandler.prototype.deleteStep = function (event) {
1570 event.preventDefault()
1571 var step_id = $(this).attr('data-id')
1572 var payload = {
1573 step_id: step_id,
1574 }
1575 if (confirm('Are you sure?')) {
1576 wpAjaxHelperRequest('delete-step', payload)
1577 .success(function (response) {
1578 console.log('Woohoo!')
1579 console.log(response)
1580 window.location.href = response.redirectUrl
1581 })
1582 .error(function (response) {
1583 console.log('Uh, oh!')
1584 console.log(response.statusText)
1585 })
1586 }
1587 }
1588
1589 /**
1590 * Ajax handler for step
1591 * creation
1592 *
1593 * @param e
1594 * @since 1.0.0
1595 */
1596 StepHandler.prototype.createStep = function (e) {
1597 e.preventDefault()
1598 var thisLoader = $(this).find('.wpfnl-loader')
1599 var thisAlert = $(this).siblings('.wpfnl-alert')
1600
1601 thisLoader.fadeIn()
1602
1603 var wrapper = $('#create-step-form'),
1604 type = $(this).attr('data-step-type'),
1605 funnelId = $(this).attr('data-funnel-id'),
1606 stepListWrapper = $('#wpfnl-funnel-step-lists')
1607
1608 var payload = {
1609 funnel_id: funnelId,
1610 step_type: type,
1611 }
1612 wpAjaxHelperRequest('create-step', payload)
1613 .success(function (response) {
1614 console.log('success')
1615 thisLoader.fadeOut()
1616 thisAlert
1617 .text('Successfully Step Created')
1618 .addClass('box wpfnl-success')
1619 .fadeIn()
1620
1621 setTimeout(function () {
1622 thisAlert.fadeOut().text('').removeClass('box wpfnl-success')
1623 }, 2000)
1624
1625 if (response.success) {
1626 window.location.href = response.redirectUrl
1627 } else {
1628 console.log(response)
1629 }
1630 })
1631 .error(function (response) {
1632 thisLoader.fadeOut()
1633 thisAlert.text('Erorr Occurred').addClass('box wpfnl-error').fadeIn()
1634
1635 setTimeout(function () {
1636 thisAlert.fadeOut().text('').removeClass('box wpfnl-error')
1637 }, 2000)
1638 })
1639 }
1640
1641 StepHandler.prototype.stepTypeChange = function (event) {
1642 event.preventDefault()
1643 var wrapper = $('.choose-step-type'),
1644 step_type = $(this).find(':selected').val(),
1645 saveBtn = $('#wpfnl-create-step')
1646 if (
1647 WPFunnelVars.is_wc_installed === 'no' &&
1648 (step_type === 'checkout' || step_type === 'upsell' || step_type === 'downsell')
1649 ) {
1650 $('.wpfnl-modal__body').find('p').remove()
1651 wrapper.after(
1652 "<p style='text-align: center; color: red'>You need install and active WooCommerce to use this step type. </p>",
1653 )
1654 saveBtn.addClass('disabled').css('pointer-events', 'none')
1655 return
1656 } else {
1657 $('.wpfnl-modal__body').find('p').remove()
1658 saveBtn.removeClass('disabled').css('pointer-events', 'inherit')
1659 }
1660 }
1661
1662 var DataSerachHandler = function () {
1663 this.initProductSearch()
1664 this.initCouponSearch()
1665 }
1666
1667 /**
1668 * initialize product search
1669 * for checkout
1670 *
1671 * @param event
1672 * @since 1.0.0
1673 */
1674 DataSerachHandler.prototype.initProductSearch = function (event) {
1675 var select2Args = {
1676 minimumInputLength: 3,
1677 allowClear: true,
1678 maximumSelectionLength: 1,
1679 ajax: {
1680 url: WPFunnelVars.ajaxurl,
1681 dataType: 'json',
1682 delay: 250,
1683 data: function (params) {
1684 return {
1685 term: params.term,
1686 action: 'wpfnl_product_search',
1687 security: WPFunnelVars.security,
1688 }
1689 },
1690 processResults: function (data) {
1691 var terms = []
1692 if (data) {
1693 $.each(data, function (id, value) {
1694 terms.push({
1695 id: id,
1696 text: value.name,
1697 price: value.price,
1698 sale_price: value.sale_price,
1699 })
1700 })
1701 }
1702 return {
1703 results: terms,
1704 }
1705 },
1706 cache: true,
1707 },
1708 }
1709
1710 $('.wpfnl-product-search').on('select2:select', function (e) {
1711 var data = e.params.data
1712 $('#upsell-original-price').val(data.price)
1713 $('#upsell-sale-price').val(data.sale_price)
1714
1715 $('#downsell-original-price').val(data.price)
1716 $('#downsell-sale-price').val(data.sale_price)
1717 })
1718 $('.wpfnl-product-search').select2(select2Args)
1719 }
1720
1721 /**
1722 * initialize coupon search
1723 * for checkout
1724 *
1725 * @param event
1726 * @since 1.0.0
1727 */
1728 DataSerachHandler.prototype.initCouponSearch = function (event) {
1729 var select2Args = {
1730 minimumInputLength: 3,
1731 allowClear: true,
1732 ajax: {
1733 url: WPFunnelVars.ajaxurl,
1734 dataType: 'json',
1735 delay: 250,
1736 data: function (params) {
1737 return {
1738 term: params.term,
1739 action: 'wpfnl_coupon_search',
1740 security: WPFunnelVars.security,
1741 }
1742 },
1743 processResults: function (data) {
1744 var terms = []
1745 if (data) {
1746 $.each(data, function (id, text) {
1747 terms.push({
1748 id: id,
1749 text: text,
1750 })
1751 })
1752 }
1753 return {
1754 results: terms,
1755 }
1756 },
1757 cache: true,
1758 },
1759 }
1760 $('.wpfnl-discount-search').select2(select2Args)
1761 }
1762
1763 var AdminNotices = function () {
1764 $(document.body)
1765 .on('click', '#wpfnl-install-plugin', this.installPlugin)
1766 .on('wp-plugin-install-success', this.installSuccess)
1767 $(document).on('wp-plugin-install-success', self._installSuccess)
1768 }
1769 AdminNotices.prototype.installPlugin = function (e) {
1770 e.preventDefault()
1771 let slug = $(this).attr('data-slug')
1772 wp.updates.queue.push({
1773 action: 'install-plugin', // Required action.
1774 data: {
1775 slug: slug,
1776 },
1777 })
1778 wp.updates.queueChecker()
1779 }
1780 AdminNotices.prototype.installSuccess = function (event, response) {
1781 event.preventDefault()
1782 console.log(response)
1783 }
1784
1785 new FunnelHandler()
1786 new StepHandler()
1787 new DataSerachHandler()
1788 new AdminNotices()
1789
1790 /**
1791 * funnel list show more action on click
1792 *
1793 * @since 1.0.0
1794 */
1795 $('body').on('click', function () {
1796 $('.funnel-list__more-action').removeClass('show-actions')
1797 })
1798
1799 $('.funnel-list__more-action').on('click', function (e) {
1800 e.stopPropagation()
1801 $(this).toggleClass('show-actions')
1802 $(this)
1803 .parents('.funnel__single-list')
1804 .siblings()
1805 .find('.funnel-list__more-action')
1806 .removeClass('show-actions')
1807 })
1808
1809 $('.funnel-list__more-action .wpfnl-dropdown').on('click', function (e) {
1810 e.stopPropagation()
1811 })
1812
1813 /**
1814 * copy to clipboard
1815 *
1816 * @since 1.0.0
1817 */
1818 $('.wpfnl-copy-clipboard').on('click', function () {
1819 var getID = $(this).attr('data-id')
1820 var getText = $('#' + getID).val()
1821 CopyToClipboard(getText)
1822
1823 $(this).siblings('.copied-msg').text('Copied').fadeIn(500)
1824
1825 setTimeout(function () {
1826 $('.copied-msg').fadeOut('slow')
1827 }, 2500)
1828 })
1829
1830 /**
1831 * copy to clipboard helper function
1832 *
1833 * @since 1.0.0
1834 */
1835 function CopyToClipboard(text) {
1836 if (window.clipboardData && window.clipboardData.setData) {
1837 return clipboardData.setData('Text', text)
1838 } else if (document.queryCommandSupported && document.queryCommandSupported('copy')) {
1839 var textarea = document.createElement('textarea')
1840 textarea.textContent = text
1841 textarea.style.position = 'fixed'
1842 document.body.appendChild(textarea)
1843 textarea.select()
1844
1845 try {
1846 return document.execCommand('copy')
1847 } catch (ex) {
1848 console.warn('Copy to clipboard failed.', ex)
1849 return false
1850 } finally {
1851 document.body.removeChild(textarea)
1852 }
1853 }
1854 }
1855
1856 /**
1857 * open modal when add new step
1858 *
1859 * @param event
1860 * @since 1.0.0
1861 */
1862 $('.wpfnl-modal-close').on('click', function (e) {
1863 e.preventDefault()
1864 $(this).parents('.wpfnl-modal').fadeOut(200)
1865 })
1866
1867 $('.wpfnl-modal__wrapper').on('click', function (e) {
1868 e.stopPropagation()
1869 })
1870
1871 /**
1872 * step name change on step page
1873 *
1874 * @param event
1875 * @since 1.0.0
1876 */
1877 var stepName = ''
1878 $('.step-name-edit').on('click', function (e) {
1879 e.preventDefault()
1880 $(this).hide()
1881 stepName = $(this).parents('.title-area').find('.step-name-input').val()
1882 $(this).parents('.title-area').find('.step-name-input').show()
1883 $(this).parents('.title-area').find('.step-name-noupdate').show()
1884 $(this).parents('.title-area').find('.step-name').hide()
1885 $(this).parents('.title-area').find('.step-name-update').show()
1886 })
1887
1888 $('.step-name-update').on('click', function (e) {
1889 e.preventDefault()
1890 $(this).hide()
1891 $(this).parents('.title-area').find('.step-name-input').hide()
1892 $(this).parents('.title-area').find('.step-name-noupdate').hide()
1893 $(this).parents('.title-area').find('.step-name').show()
1894 $(this).parents('.title-area').find('.step-name-edit').show()
1895 })
1896
1897 $('.step-name-noupdate').on('click', function (e) {
1898 e.preventDefault()
1899 $(this).hide()
1900 $(this).parents('.title-area').find('.step-name-input').val(stepName).hide()
1901 $(this).parents('.title-area').find('.step-name-update').hide()
1902 $(this).parents('.title-area').find('.step-name').text(stepName).show()
1903 $(this).parents('.title-area').find('.step-name-edit').show()
1904 })
1905
1906 $('.step-name-input').keyup(function () {
1907 $(this).parents('.title-area').find('.step-name').text($(this).val())
1908 })
1909
1910 /**
1911 * step settings tab
1912 *
1913 * @since 1.0.0
1914 */
1915 $('.step-settings__single-tab-content:first-child').show()
1916
1917 $(document).on('click', '.steps-settings__tab-nav:not(.ab-nav) a', function (e) {
1918 if (!$(this).parent('li').hasClass('disabled')) {
1919 e.preventDefault()
1920 var dataID = $(this).attr('href')
1921
1922 $(this).parent('li').addClass('active').siblings().removeClass('active')
1923 $(this).parents('.steps-settings').find(dataID).show()
1924 $(this).parents('.steps-settings').find(dataID).siblings().hide()
1925 }
1926 })
1927
1928 /**
1929 * step settings product options tab
1930 *
1931 * @since 1.0.0
1932 */
1933 $('.product-options__tab-nav a').on('click', function (e) {
1934 e.preventDefault()
1935
1936 var dataID = $(this).attr('href')
1937 $(this).parent('li').addClass('active').siblings().removeClass('active')
1938
1939 $(this).parents('.wpfnl-product-options').find(dataID).show()
1940 $(this).parents('.wpfnl-product-options').find(dataID).siblings().hide()
1941 })
1942
1943 /**
1944 * wpfnl accordion
1945 *
1946 * @since 1.0.0
1947 */
1948 $('.wpfnl__accordion-content').hide()
1949 $('.wpfnl__single-accordion:first-child .wpfnl__accordion-content').show()
1950 $('.wpfnl__accordion-title').on('click', function (e) {
1951 e.preventDefault()
1952
1953 var dataID = $(this).attr('href')
1954
1955 $(this).parent('.wpfnl__single-accordion').find(dataID).slideToggle()
1956 $(this)
1957 .parents('.wpfnl__single-accordion')
1958 .siblings()
1959 .find('.wpfnl__accordion-content')
1960 .slideUp()
1961 })
1962
1963 /**
1964 * steps-header-hamburger toggle menu
1965 *
1966 * @since 1.0.0
1967 */
1968 $('body').on('click', function () {
1969 $('#steps-header-hamburger').removeClass('show')
1970 })
1971 // $(document).on("click", "#steps-header-hamburger", function(e) {
1972 $('#steps-header-hamburger').on('click', function (e) {
1973 e.stopPropagation()
1974 if (!$(this).hasClass('show')) {
1975 $(this).removeClass('show')
1976 } else {
1977 $(this).addClass('show')
1978 }
1979
1980 wpfnlDatePicker()
1981 })
1982
1983 /**
1984 * wpfnl step title edit
1985 *
1986 * @param event
1987 * @since 1.0.0
1988 */
1989 function step_edit(e) {
1990 e.preventDefault()
1991 var step_id = $(this).attr('data-id')
1992 var input = $('#step-name-input-' + step_id).val()
1993 var payload = {
1994 step_id: step_id,
1995 input: input,
1996 }
1997 wpAjaxHelperRequest('step-edit', payload)
1998 .success(function (response) {
1999 $('#setp-list-' + step_id + ' .title-txt').text(input)
2000
2001 if (response.success) {
2002 console.log('success')
2003 } else {
2004 console.log(response)
2005 }
2006 })
2007 .error(function (response) {
2008 console.log('error')
2009 })
2010 }
2011 $('.step-name-update').on('click', step_edit)
2012 })
2013
2014 function getUrlParameter(sParam) {
2015 var sPageURL = window.location.search.substring(1),
2016 sURLVariables = sPageURL.split('&'),
2017 sParameterName,
2018 i
2019
2020 for (i = 0; i < sURLVariables.length; i++) {
2021 sParameterName = sURLVariables[i].split('=')
2022
2023 if (sParameterName[0] === sParam) {
2024 return sParameterName[1] === undefined
2025 ? true
2026 : decodeURIComponent(sParameterName[1])
2027 }
2028 }
2029 }
2030
2031 /**
2032 * settings page tab nav
2033 *
2034 * @since 1.0.0
2035 */
2036 function activateSettingsTab(dataID, syncHash) {
2037 // dataID comes straight off the URL hash, which is not always a settings tab
2038 // id: the funnel canvas parks router paths there (VerticalFlowView.vue sets
2039 // `#<step_id>/automation/`). Resolve the panel with getElementById, which
2040 // accepts any string, and bail before building a selector out of dataID —
2041 // `$('#17/automation/')` throws "unrecognized expression", and on the
2042 // ready-time syncSettingsTabFromHash() call that abort takes every event
2043 // binding below it in this file down with it.
2044 var containerEl = dataID ? document.getElementById(dataID) : null;
2045
2046 if (!containerEl) {
2047 return false;
2048 }
2049
2050 var $container = $(containerEl);
2051 var $navItem = $('.wpfn-settings__nav .nav-li:not(.disabled)').filter(function () {
2052 return $(this).attr('data-id') === dataID;
2053 });
2054
2055 if (!$navItem.length) {
2056 return false;
2057 }
2058
2059 $navItem.addClass('active').siblings('.nav-li').removeClass('active');
2060
2061 // Show the selected panel, hide others.
2062 $container.show().siblings('.wpfnl-funnel__single-settings').hide();
2063
2064 // Inside the visible panel, activate the first inner-tab.
2065 $container.find('.inner-tab').removeClass('active');
2066 $container.find('.wpfnl-tab-content').removeClass('active');
2067
2068 var $firstInnerTab = $container.find('.inner-tab').first();
2069 var tabId = $firstInnerTab.data('tab');
2070
2071 if ($firstInnerTab.length) {
2072 $firstInnerTab.addClass('active');
2073 }
2074
2075 if (tabId) {
2076 $container.find('.wpfnl-tab-content').filter(function () {
2077 return this.id === String(tabId);
2078 }).addClass('active');
2079 }
2080
2081 if (syncHash && window.location.hash !== '#' + dataID) {
2082 if (window.history && window.history.replaceState) {
2083 window.history.replaceState(null, '', window.location.pathname + window.location.search + '#' + dataID);
2084 } else {
2085 window.location.hash = dataID;
2086 }
2087 }
2088
2089 return true;
2090 }
2091
2092 function syncSettingsTabFromHash() {
2093 var dataID = (window.location.hash || '').replace(/^#/, '');
2094
2095 if (!dataID) {
2096 return;
2097 }
2098
2099 activateSettingsTab(dataID, false);
2100 }
2101
2102 $('.wpfn-settings__nav .nav-li:not(.disabled)').on('click', function () {
2103 activateSettingsTab($(this).attr('data-id'), true);
2104 });
2105
2106 syncSettingsTabFromHash();
2107 $(window).on('hashchange', syncSettingsTabFromHash);
2108
2109
2110 /**
2111 * Checkout Edit Field delete alert modal
2112 *
2113 * @since 1.0.0
2114 */
2115 $(document).on('click', '.delete-checkout-field', function () {
2116 $(this)
2117 .parents('.checkout__single-field')
2118 .find('.wpfnl-delete-alert-wrapper')
2119 .css('display', 'flex')
2120 })
2121
2122 $(document).on('click', '.wpfnl-delete-confirm-btn .cancel', function () {
2123 $(this).parents('.wpfnl-delete-alert-wrapper').hide()
2124 })
2125
2126 /**
2127 * edit-field settings tab
2128 *
2129 * @since 1.0.0
2130 */
2131 $('.edit-field-settings__single-tab-content:first-child').show()
2132
2133 $(document).on('click', '.edit-field-settings__tab-nav a', function (e) {
2134 e.preventDefault()
2135 var dataID = $(this).attr('href')
2136 $(this).parent('li').addClass('active').siblings().removeClass('active')
2137 $(this).parents('.checkout-edit-field-tab__content-wrapper').find(dataID).show()
2138 $(this).parents('.checkout-edit-field-tab__content-wrapper').find(dataID).siblings().hide()
2139 })
2140
2141 /**
2142 * add new checkout field drawer
2143 *
2144 * @since 1.0.0
2145 */
2146 $('.add-new-checkout-field-btn').on('click', function (e) {
2147 e.preventDefault()
2148 $(this)
2149 .parents('.checkout-edit-field-tab__content-wrapper')
2150 .find('.add-checkout-field-wrapper')
2151 .addClass('show-drawer')
2152 })
2153
2154 $('.add-checkout-field-close').on('click', function (e) {
2155 e.preventDefault()
2156 $(this).parents('.add-checkout-field-wrapper').removeClass('show-drawer')
2157 })
2158
2159 /**
2160 * edit checkout field drawer
2161 *
2162 * @since 1.0.0
2163 */
2164 // $('button.edit-field').on('click', function(e) {
2165 $(document).on('click', 'button.edit-field', function (e) {
2166 e.preventDefault()
2167 $(this)
2168 .parents('.checkout-edit-field-tab__content-wrapper')
2169 .find('.edit-checkout-field-wrapper')
2170 .addClass('show-drawer')
2171 })
2172
2173 $('.add-checkout-field-close').on('click', function (e) {
2174 e.preventDefault()
2175 $(this).parents('.edit-checkout-field-wrapper').removeClass('show-drawer')
2176 })
2177
2178 /**
2179 * show edit field type options
2180 *
2181 * @since 1.0.0
2182 */
2183 $('.wpfnl-edit-field-type').on('change', function (e) {
2184 e.preventDefault()
2185 var thisVal = $(this).val()
2186
2187 if (thisVal == 'select') {
2188 $(this).parents('.field-body').find('.field-type-options').show()
2189 } else {
2190 $(this).parents('.field-body').find('.field-type-options').hide()
2191 }
2192 })
2193
2194 jQuery(document).ready(function () {
2195 var selectedType = $('.wpfnl-edit-field-type').val()
2196
2197 if (selectedType == 'select') {
2198 $('.wpfnl-edit-field-type').parents('.field-body').find('.field-type-options').show()
2199 } else {
2200 $('.wpfnl-edit-field-type').parents('.field-body').find('.field-type-options').hide()
2201 }
2202 })
2203
2204 /**
2205 * Step preview permalink copy to clipboard
2206 *
2207 * @since 2.2.5
2208 */
2209 $(document).on('click', '.steps-url-slug .copy-slug-url', function (e) {
2210 e.preventDefault()
2211 $(this).addClass('copy-confirmed')
2212 var $temp = $('<input>')
2213 $(this).parents('.field-group').append($temp)
2214 $temp.val($(this).parents('.field-group').find('#step-preview-link').val()).select()
2215 document.execCommand('copy')
2216 $temp.remove()
2217
2218 setTimeout(function () {
2219 $('.steps-url-slug .copy-slug-url').removeClass('copy-confirmed')
2220 }, 1000)
2221 })
2222
2223 $(document).on('keyup change input', '.wpfnl-set-quantity-limit', function (e) {
2224 // Get the input value
2225 var inputValue = $(this).val()
2226
2227 // If input is blank, default it to 1
2228 if (isNaN(inputValue)) {
2229 inputValue = '1'
2230 }
2231 // Remove any non-numeric characters except '.'
2232 inputValue = inputValue.replace(/[^0-9.]/g, '')
2233
2234 // Split the value into integer and decimal parts
2235 var parts = inputValue.split('.')
2236
2237 // If there are more than one decimal point, consider only the first part
2238 if (parts.length > 2) {
2239 inputValue = parts[0] + '.' + parts.slice(1).join('')
2240 }
2241
2242 // Parse the value into an integer
2243 var quantity = parseInt(inputValue)
2244 // Set the input value to the parsed integer
2245 $(this).val(quantity)
2246
2247 if (quantity < 1) {
2248 $(this).val(1)
2249 }
2250 })
2251
2252 $(document).on('blur', '.wpfnl-set-quantity-limit', function (e) {
2253 var inputValue = $(this).val()
2254 if (inputValue.trim() === '') {
2255 $(this).val('1')
2256 }
2257 })
2258
2259 /**
2260 * AB testing permalink copy to clipboard
2261 *
2262 * @since 3.1.0
2263 */
2264 $(document).on('click', '.copy-ab-url', function (e) {
2265 e.preventDefault()
2266 $(this).addClass('copy-confirmed')
2267 var $temp = $('<input>')
2268 $(this).parents('.header-right').append($temp)
2269 $temp.val($(this).parents('.header-right').find('#ab-testing-link').val()).select()
2270 document.execCommand('copy')
2271 $temp.remove()
2272
2273 setTimeout(function () {
2274 $('.copy-ab-url').removeClass('copy-confirmed')
2275 }, 1000)
2276 })
2277
2278 /**
2279 * rollback feature for WPF
2280 */
2281 $('select#wpfnl-rollback')
2282 .on('change', function () {
2283 var $this = $(this),
2284 $rollbackButton = $this.next('.wpfnl-rollback-button'),
2285 originalHref = $rollbackButton.attr('href'),
2286 selectedVersion = $this.val();
2287
2288 if (originalHref && originalHref.includes('VERSION')) {
2289 var updatedHref = originalHref.replace('VERSION', selectedVersion);
2290 $rollbackButton.attr('href', updatedHref);
2291 }
2292 })
2293 .trigger('change');
2294
2295
2296 $('.wpfnl-rollback-button').on('click', function (event) {
2297 event.preventDefault()
2298 var $this = $(this)
2299 if (confirm('Are you sure?')) {
2300 $this.addClass('show-loader')
2301 $this.addClass('loading')
2302 location.href = $this.attr('href')
2303 }
2304 })
2305
2306 // ---delete promotional-banner notice permanently ------
2307 $(document).on('click', '.gwpf-promotional-notice .close-promotional-banner', function (event) {
2308 event.preventDefault()
2309 $('.gwpf-promotional-notice').attr('style', 'display: none !important');
2310 wpAjaxHelperRequest('delete_promotional_banner')
2311 })
2312
2313 $(document).on('click', '.wpfnl-notification-counter__btn-area', function (event) {
2314 event.preventDefault()
2315 $('.gwpf-promotional-notice').attr('style', 'display: none !important');
2316 wpAjaxHelperRequest('delete_promotional_banner')
2317 })
2318
2319 // ---delete new UI notice permanently ------
2320 $(document).on('click', '.wpfunnels-newui-notice .close-newui-notice', function (event) {
2321 event.preventDefault()
2322 $('.wpfunnels-newui-notice.notice').css('display', 'none')
2323 wpAjaxHelperRequest('delete_new_ui_notice')
2324 })
2325
2326 /**
2327 * Multiple Orderbump Accordion
2328 *
2329 */
2330 $(document).on(
2331 'click',
2332 '.single-order-bump .order-bump-accordion-header .title-area',
2333 function (e) {
2334 e.preventDefault()
2335 $(this).parents('.single-order-bump').siblings().removeClass('expanded-orderbump')
2336 $(this).parents('.single-order-bump').toggleClass('expanded-orderbump')
2337
2338 $(this)
2339 .parents('.single-order-bump')
2340 .siblings()
2341 .find('.order-bump-accordion-content')
2342 .removeClass('show-content')
2343 $(this)
2344 .parents('.single-order-bump')
2345 .find('.order-bump-accordion-content')
2346 .toggleClass('show-content')
2347 },
2348 )
2349
2350 $(document).ready(function () {
2351 const $stickyElement = $('.wpfnl-pvf-table-header');
2352 if($stickyElement.length === 0) return;
2353 const stickyOffset = $stickyElement.offset().top;
2354
2355 $(window).on('scroll', function () {
2356 const scrollTop = $(this).scrollTop();
2357 if (scrollTop >= stickyOffset - 44) {
2358 $stickyElement.addClass('is-sticky');
2359 } else {
2360 $stickyElement.removeClass('is-sticky');
2361 }
2362 });
2363 });
2364
2365
2366 //------expand last orderbump when added a new orderbump----
2367 $(document).on('click', '.order-bump-header .add-new-orderbump', function (e) {
2368 e.preventDefault()
2369 $('.single-order-bump').siblings().removeClass('expanded-orderbump')
2370 $('.single-order-bump:last-child').addClass('expanded-orderbump')
2371
2372 $('.single-order-bump')
2373 .siblings()
2374 .find('.order-bump-accordion-content')
2375 .removeClass('show-content')
2376 $('.single-order-bump:last-child')
2377 .find('.order-bump-accordion-content')
2378 .addClass('show-content')
2379 })
2380
2381 /**
2382 * Automatic winner choose condition dropdown
2383 *
2384 */
2385 $(document).on('click', '.automatic-winner .set-condition .selected-item', function (e) {
2386 e.preventDefault()
2387 e.stopPropagation()
2388 $(this).parents('.wpfnl-selectbox').find('.selectable-option').slideToggle(300)
2389 })
2390 $(document).on('click', 'body', function () {
2391 $('.automatic-winner .set-condition .selectable-option').hide()
2392 })
2393
2394 $(document).on('click', '.automatic-winner .set-condition .selectable-option li', function (e) {
2395 e.preventDefault()
2396 var selected_item_text = $(this).text()
2397 var selected_item_data = $(this).attr('data-value')
2398
2399 $(this).siblings().removeClass('active')
2400 $(this).addClass('active')
2401 $('.automatic-winner .set-condition .selected-item')
2402 .text(selected_item_text)
2403 .attr('data-value', selected_item_data)
2404 })
2405
2406 /**
2407 * Show step control button when clik on step (on drawflow window page)
2408 *
2409 */
2410 $(document).on('click', '.drawflow .drawflow-node .single-node', function (e) {
2411 e.stopPropagation()
2412 $(this)
2413 .parents('.parent-node')
2414 .siblings()
2415 .find('.single-node')
2416 .removeClass('im-selected-node')
2417 $(this).siblings().removeClass('im-selected-node')
2418 $(this)
2419 .parent('.single-node-wrapper')
2420 .siblings()
2421 .find('.single-node')
2422 .removeClass('im-selected-node')
2423 $(this).addClass('im-selected-node')
2424 })
2425
2426 $(document).on('click', 'body', function () {
2427 $('.drawflow .drawflow-node .single-node').removeClass('im-selected-node')
2428 })
2429
2430 /**
2431 * Add list, add tag dropdown show/hide
2432 *
2433 */
2434 $(document).on('click', '.wpfnl-custom-selectbox .selectbox-selected-value', function (e) {
2435 e.stopPropagation()
2436 $(this).parents('.wpfnl-custom-selectbox').toggleClass('show-options')
2437 })
2438
2439 $(document).on('click', '.wpfnl-custom-selectbox .selectbox-options', function (e) {
2440 e.stopPropagation()
2441 })
2442
2443 $(document).on('click', 'body', function () {
2444 $('.wpfnl-custom-selectbox').removeClass('show-options')
2445 })
2446
2447 /**
2448 * Funnel Bulk select action dropdown
2449 *
2450 */
2451 $(document).on('click', '.bulk-delete-toggler', function (e) {
2452 e.stopPropagation()
2453 $(this).toggleClass('show-dropdown')
2454 })
2455
2456 $(document).on('click', '.wpfnl-dropdown', function (e) {
2457 e.stopPropagation()
2458 })
2459
2460 $(document).on('click', 'body', function () {
2461 $('.bulk-delete-toggler').removeClass('show-dropdown')
2462 })
2463
2464 $(document).on('change', 'select#wpfnl_listing_page_offset', updateFunnelListingPageOffset)
2465 function updateFunnelListingPageOffset() {
2466 const offset = $(this).find('option:selected').val()
2467 const queryParams = new URLSearchParams(window.location.search)
2468
2469 // Set new or modify existing parameter value.
2470 queryParams.set('pageno', '1')
2471 queryParams.set('per_page', offset)
2472 // Replace current querystring with the new one.
2473 history.replaceState(null, null, '?' + queryParams.toString())
2474 location.reload()
2475 }
2476
2477 function selectedFunnelIds(params) {
2478 let ids = []
2479 if (params.length > 0) {
2480 for (let key = 0; key < params.length; key++) {
2481 const inputItem = params[key]?.id
2482 const id = inputItem.match(/\d+/)[0]
2483 ids.push(parseInt(id))
2484 }
2485 }
2486 selectedIds = ids
2487 }
2488
2489 /**
2490 * Funnel Bulk select checkbox on change event
2491 *
2492 */
2493 function selectedFunnelCounter() {
2494 let totalSelectedFunnel = $('input[name=funnel-list-select]:checked').length
2495
2496 selectedFunnelIds($('input[name=funnel-list-select]:checked'))
2497
2498 if (totalSelectedFunnel > 0) {
2499 $('.funnel__single-list.list-header .bulk-action-wrapper').css('display', 'flex')
2500 } else {
2501 $('.funnel__single-list.list-header .bulk-action-wrapper').css('display', 'none')
2502 }
2503
2504 if (totalSelectedFunnel > 1) {
2505 $('.funnel__single-list.list-header .bulk-action-wrapper .selected-funnel-count').text(
2506 totalSelectedFunnel + ' Funnels',
2507 )
2508 } else {
2509 $('.funnel__single-list.list-header .bulk-action-wrapper .selected-funnel-count').text(
2510 totalSelectedFunnel + ' Funnel',
2511 )
2512 }
2513 }
2514
2515 $('.funnel__single-list.list-body input[name=funnel-list-select]').on('change', function () {
2516 $('.funnel-list__bulk-select.select-all-funnels input[name=funnel-list__bulk-select]').prop(
2517 'checked',
2518 false,
2519 )
2520 selectedFunnelCounter()
2521 })
2522
2523 $('.funnel-list__bulk-select.select-all-funnels input[name=funnel-list__bulk-select]').on(
2524 'change',
2525 function () {
2526 if ($(this).is(':checked')) {
2527 $('.funnel__single-list.list-body input[name=funnel-list-select]').prop(
2528 'checked',
2529 true,
2530 )
2531 selectedFunnelCounter()
2532 } else {
2533 $('.funnel__single-list.list-header .bulk-action-wrapper').css('display', 'none')
2534 $('.funnel__single-list.list-body input[name=funnel-list-select]').prop(
2535 'checked',
2536 false,
2537 )
2538 }
2539 },
2540 )
2541
2542 /**
2543 * Funnel window page and Empty funnel page help resource show/hide.
2544 *
2545 */
2546 $(document).on('click', '.wpfnl-helper-btn', function (e) {
2547 e.stopPropagation()
2548 $(this).parent('.wpfnl-canvas-helper').toggleClass('show-helpers')
2549 })
2550
2551 $(document).on('click', 'body', function () {
2552 $('.wpfnl-canvas-helper').removeClass('show-helpers')
2553 })
2554
2555 /**
2556 * add new step option dropdown show/hide.
2557 *
2558 */
2559 $(document).on('click', '.addstep .add-step-wrapper .icon', function (e) {
2560 e.stopPropagation()
2561 $(this).parent('.add-step-wrapper').toggleClass('show-options')
2562 })
2563
2564 $(document).on('click', '.option-duplicate', function (e) {
2565 e.stopPropagation()
2566 })
2567
2568 $(document).on('click', 'body', function () {
2569 $('.addstep .add-step-wrapper').removeClass('show-options')
2570 })
2571
2572 /**
2573 * Showmore option hide/show
2574 * Three dot more option hide/show.
2575 *
2576 */
2577 $(document).on('click', '.on-showmore-options', function (e) {
2578 e.stopPropagation()
2579 $(this).toggleClass('show-dropdown')
2580 })
2581 $(document).on('click', 'body', function () {
2582 $('.on-showmore-options').removeClass('show-dropdown')
2583 })
2584
2585 /*----mailmint actions dropdown------ */
2586 $(document).on('click', '.mailmint-automation .add-action > button', function (e) {
2587 e.stopPropagation()
2588
2589 $(this).parents('.logical-decision-box').siblings('.add-action').removeClass('show-actions')
2590 $(this).parents('.single-decision').find('.add-action').removeClass('show-actions')
2591 $(this)
2592 .parents('.single-decision')
2593 .siblings()
2594 .find('.add-action')
2595 .removeClass('show-actions')
2596
2597 $(this)
2598 .parents('.automation-single-step')
2599 .siblings()
2600 .find('.add-action')
2601 .removeClass('show-actions')
2602
2603 $(this).parents('.add-action').toggleClass('show-actions')
2604 })
2605
2606 $(document).on('click', '.mailmint-automation .mailmint-actions', function (e) {
2607 e.stopPropagation()
2608 })
2609
2610 $(document).on('click', 'body, .mailmint-single-action, .automation-start-point', function (e) {
2611 $('.mailmint-automation .add-action').removeClass('show-actions')
2612 })
2613
2614 //----when click first-action plus (+) button------
2615 $(document).on('click', '.mailmint-automation .add-action.first-action > button', function (e) {
2616 $('.automation-single-step .add-action').removeClass('show-actions')
2617 })
2618
2619 //----when click automation-single-step's plus (+) button------
2620 $(document).on('click', '.automation-single-step .add-action > button', function (e) {
2621 $('.selected-trigger .add-action').removeClass('show-actions')
2622 //$('.logical-decision-box .add-action').removeClass('show-actions');
2623 })
2624
2625 //--------select box placeholder color and active color--------
2626 $(document).on('change', 'select.has-placeholder-color', function () {
2627 var thisVal = $(this).find(':selected').val()
2628 if ('' != thisVal) {
2629 $(this).addClass('value-selected')
2630 } else {
2631 $(this).removeClass('value-selected')
2632 }
2633 })
2634
2635 $(document).on('click', '.add-new-webhook', function () {
2636 $('select.has-placeholder-color').removeClass('value-selected')
2637 })
2638
2639 /*----A|B testing modal header's more option's dropdown show/hide------ */
2640 $(document).on('click', '.ab-testing-drawer .header-right .more-options', function (e) {
2641 e.stopPropagation()
2642 $(this).toggleClass('show-options')
2643 })
2644
2645 $(document).on('click', 'body', function () {
2646 $('.ab-testing-drawer .header-right .more-options').removeClass('show-options')
2647 })
2648
2649 /*----A|B testing variations steps more option's dropdown show/hide------ */
2650 $(document).on('click', '.single-ab-step .more-option > button', function (e) {
2651 e.stopPropagation()
2652 $(this)
2653 .parents('.single-ab-step')
2654 .siblings()
2655 .find('.more-option')
2656 .removeClass('show-dorpdown')
2657 $(this).parents('li.more-option').toggleClass('show-dorpdown')
2658 })
2659
2660 $(document).on('click', '.single-ab-step .more-option .options-dropdown', function (e) {
2661 e.stopPropagation()
2662 })
2663
2664 $(document).on('click', 'body', function () {
2665 $('.ab-testing-drawer .single-ab-step li.more-option').removeClass('show-dorpdown')
2666 })
2667
2668 /**
2669 * wpfnl custom selectbox dropdown option hide/show
2670 *
2671 */
2672 $(document).on('click', '.wpfnl-selectbox .selected-option', function (e) {
2673 e.stopPropagation()
2674
2675 $(this)
2676 .parents('.single-rules')
2677 .siblings()
2678 .find('.wpfnl-selectbox')
2679 .removeClass('show-options')
2680 $(this).parents('.rules').siblings().find('.wpfnl-selectbox').removeClass('show-options')
2681
2682 $(this)
2683 .parents('.condition-single-row')
2684 .siblings()
2685 .find('.wpfnl-selectbox')
2686 .removeClass('show-options')
2687 $(this)
2688 .parents('.single-condition')
2689 .siblings()
2690 .find('.wpfnl-selectbox')
2691 .removeClass('show-options')
2692
2693 $(this).parent('.wpfnl-selectbox').toggleClass('show-options')
2694 })
2695 $(document).on('click', 'body', function () {
2696 $('.wpfnl-selectbox').removeClass('show-options')
2697 })
2698
2699 /**
2700 * wpfnl custom selectbox sub dropdown option hide/show
2701 *
2702 */
2703 $(document).on('click', '.single-rules .selectable-options > li', function (e) {
2704 e.stopPropagation()
2705
2706 $(this)
2707 .parents('.single-rules')
2708 .siblings()
2709 .find('.selectable-options > li')
2710 .removeClass('show-options')
2711 $(this)
2712 .parents('.rules')
2713 .siblings()
2714 .find('.selectable-options > li')
2715 .removeClass('show-options')
2716 $(this).siblings().removeClass('show-options')
2717
2718 $(this).toggleClass('show-options')
2719 })
2720 $(document).on('click', 'body', function () {
2721 $('.single-rules .wpfnl-selectbox').removeClass('show-options')
2722 $('.single-rules .selectable-options > li').removeClass('show-options')
2723 })
2724
2725 $(document).on(
2726 'click',
2727 '.single-rules .submenu > li, .rules-is .selectable-options > li',
2728 function () {
2729 $('.single-rules .wpfnl-selectbox').removeClass('show-options')
2730 },
2731 )
2732
2733 //---------------------------
2734 $(document).on('click', '.single-rules .selected-option', function (e) {
2735 $('.single-rules .wpfnl-custom-selectbox').removeClass('show-options')
2736 })
2737
2738 $(document).on('click', '.wpfnl-custom-selectbox .selectbox-selected-value', function (e) {
2739 $('.single-rules .wpfnl-selectbox ').removeClass('show-options')
2740 $(this)
2741 .parents('.single-rules')
2742 .siblings()
2743 .find('.wpfnl-custom-selectbox')
2744 .removeClass('show-options')
2745 })
2746
2747 // ------------------ Pro Modal Open and Close ---------------------- //
2748
2749 // close modal starts
2750 $(document).on('click', '#wpfnl-pro-modal-close', function (e) {
2751 const html = '<strong>Small</strong> <span>License for 1 site</span>';
2752 $('#pro-modal-package-type').html(html)
2753 $('.wpfnl-footer-btn-wrapper .btn-default.confirmed').attr('href', 'https://useraccount.getwpfunnels.com/wpf-small-annual-brand-new/steps/wpf-sa-checkout/');
2754 $('#wpfnl-pro-modal').hide()
2755 })
2756
2757 $(document).on('click', '#wpfnl-pro-modal-close-btn', function (e) {
2758 const html = '<strong>Small</strong> <span>License for 1 site</span>';
2759 $('#pro-modal-package-type').html(html)
2760 $('.wpfnl-footer-btn-wrapper .btn-default.confirmed').attr('href', 'https://useraccount.getwpfunnels.com/wpf-small-annual-brand-new/steps/wpf-sa-checkout/');
2761 $('#wpfnl-pro-modal').hide()
2762 })
2763 // close modal ends
2764
2765 /* Configure the pro modal
2766 * config[object] - parameter
2767 * showSubHeading - boolean
2768 * subHeading - string
2769 * confirmLink - string
2770 * features - Array of Object
2771 * label - String
2772 * value - String
2773 */
2774 const configureProModal = (config) => {
2775 const { showSubHeading, subHeading, confirmLink, features } = config
2776
2777 // Define Ratings and Users
2778 const ratings = 105
2779 const users = 8000
2780
2781 // Define Elements
2782 const modalElement = document.querySelector('#wpfnl-pro-modal')
2783 const subHeadingElement = document.querySelector('#wpfnl-pro-modal .wpfnl-pro-sub-heading')
2784 const confirmBtnElement = document.querySelector('#wpfnl-pro-modal .btn-default.confirmed')
2785 const modalBodyElement = document.querySelector('#wpfnl-pro-modal .wpfnl-pro-modal-body')
2786 const featureFirstColElement = document.querySelector(
2787 '#wpfnl-pro-modal .wpfnl-pro-modal-body .wpfnl-pro-features.first-col',
2788 )
2789 const featureSecondColElement = document.querySelector(
2790 '#wpfnl-pro-modal .wpfnl-pro-modal-body .wpfnl-pro-features.second-col',
2791 )
2792 const footerTextElement = document.querySelector(
2793 '#wpfnl-pro-modal .wpfnl-pro-modal-footer-text span',
2794 )
2795
2796 // Tic Icon for Features
2797 const ticIcon = `<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 14 14" fill="none"><path d="M1.45455 6.23252C1.17901 6.23329 0.909321 6.31206 0.676682 6.45971C0.444044 6.60736 0.257963 6.81786 0.139966 7.06685C0.0219701 7.31585 -0.0231188 7.59316 0.00991618 7.86671C0.0429511 8.14026 0.15276 8.39887 0.326638 8.61261L4.03332 13.1533C4.16548 13.3174 4.33489 13.4476 4.52748 13.5331C4.72006 13.6186 4.93026 13.6569 5.14063 13.6448C5.59054 13.6206 5.99673 13.38 6.2557 12.9842L13.9554 0.583858C13.9567 0.581801 13.958 0.579744 13.9593 0.577717C14.0316 0.46679 14.0082 0.246962 13.859 0.108864C13.8181 0.0709399 13.7698 0.0418041 13.7171 0.0232503C13.6645 0.00469649 13.6086 -0.00288247 13.5529 0.000980338C13.4972 0.00484315 13.4429 0.020066 13.3933 0.0457111C13.3437 0.0713562 13.2999 0.106881 13.2646 0.150097C13.2618 0.153494 13.259 0.156841 13.2561 0.160136L5.49078 8.93373C5.46124 8.96712 5.42535 8.9943 5.38521 9.0137C5.34507 9.0331 5.30147 9.04433 5.25695 9.04674C5.21243 9.04915 5.16788 9.04268 5.12588 9.02773C5.08388 9.01277 5.04527 8.98962 5.01229 8.95961L2.43514 6.61439C2.16749 6.36903 1.81765 6.23279 1.45455 6.23252Z" fill="#2FCF5C"></path></svg>`
2798
2799 // Show or hide subheading
2800 if (showSubHeading) {
2801 subHeadingElement.innerHTML = subHeading
2802 } else {
2803 modalElement.removeChild(subHeadingElement)
2804 }
2805
2806 // confirm link setting
2807 if (confirmLink) {
2808 confirmBtnElement.setAttribute('href', confirmLink)
2809 } else {
2810 confirmBtnElement.setAttribute('href', 'https://useraccount.getwpfunnels.com/wpf-small-annual-brand-new/steps/wpf-sa-checkout/')
2811 }
2812
2813 // features setting
2814 if (Array.isArray(features) && features?.length > 0) {
2815 let middle = Math.ceil(features.length / 2)
2816 featureFirstColElement.innerHTML = ''
2817 featureSecondColElement.innerHTML = ''
2818
2819 features.forEach((feature, index) => {
2820 if (index < middle) {
2821 featureFirstColElement.innerHTML += `<li>${ticIcon}<span>${feature.label}</span></li>`
2822 } else {
2823 featureSecondColElement.innerHTML += `<li>${ticIcon}<span>${feature.label}</span></li>`
2824 }
2825 })
2826 } else {
2827 modalElement.removeChild(modalBodyElement)
2828 }
2829
2830 // Set Footer Text
2831 if (footerTextElement)
2832 footerTextElement.innerHTML = `Easiest Funnel Builder: <strong>${users}+</strong> Users, <strong>${ratings}+</strong> Five-Star Reviews</strong>`
2833 }
2834
2835 // modal Open function
2836 const openModal = (config) => {
2837 // configureProModal(config)
2838 $('#wpfnl-pro-modal').css('display', 'flex')
2839 }
2840 // open modal starts
2841 $(document).on('click', '#wpfnl-export-all-pro', function (e) {
2842 const config = {
2843 showSubHeading: true,
2844 subHeading: 'Upgrade to Export Funnels.',
2845 confirmLink: 'https://useraccount.getwpfunnels.com/wpf-small-annual-brand-new/steps/wpf-sa-checkout/',
2846 features: [
2847 {
2848 label: 'Export Funnels',
2849 value: 'export_funnels',
2850 },
2851 {
2852 label: 'Download Funnel as JSON',
2853 value: 'download_funnel_as_json',
2854 },
2855 {
2856 label: 'Export Single Funnel',
2857 value: 'export_single_funnels',
2858 },
2859 {
2860 label: 'Bulk Export',
2861 value: 'bulk_export',
2862 },
2863 ],
2864 }
2865 openModal(config)
2866 })
2867
2868 $(document).on('click', '#wpfnl-import-funnels-pro, .pro-import-button', function (e) {
2869 const config = {
2870 showSubHeading: true,
2871 subHeading: 'Upgrade to Import Funnels.',
2872 confirmLink: 'https://useraccount.getwpfunnels.com/wpf-small-annual-brand-new/steps/wpf-sa-checkout/',
2873 features: [
2874
2875 {
2876 label: 'Import JSON File',
2877 value: 'import_json_to_create_funnel',
2878 },
2879 {
2880 label: 'Import Funnels',
2881 value: 'import_funnels',
2882 },
2883 {
2884 label: 'Bulk Import',
2885 value: 'bulk_import_funnels',
2886 },
2887 ],
2888 }
2889 openModal(config)
2890 })
2891
2892 $(document).on('click', '#wpfnl-offer-settings', function (e) {
2893 const config = {
2894 showSubHeading: true,
2895 subHeading: 'Upgrade to Unlock Offer Settings.',
2896 confirmLink: 'https://useraccount.getwpfunnels.com/wpf-small-annual-brand-new/steps/wpf-sa-checkout/',
2897 features: [
2898 {
2899 label: 'Create Child Order',
2900 value: 'create_child_order',
2901 },
2902 {
2903 label: 'Show Supported Payment Gateway',
2904 value: 'show_supported_payment_gateway',
2905 },
2906 {
2907 label: 'Skip Offer',
2908 value: 'skip_offer',
2909 },
2910 ],
2911 }
2912 openModal(config)
2913 })
2914
2915 $('.duplicate.wpfnl-export-funnel-pro').on('click', function (e) {
2916 const config = {
2917 showSubHeading: true,
2918 subHeading: 'Upgrade to Export Funnels.',
2919 confirmLink: 'https://useraccount.getwpfunnels.com/wpf-small-annual-brand-new/steps/wpf-sa-checkout/',
2920 features: [
2921 {
2922 label: 'Export Funnels',
2923 value: 'export_funnels',
2924 },
2925 {
2926 label: 'Download Funnel as JSON',
2927 value: 'download_funnel_as_json',
2928 },
2929 {
2930 label: 'Export Single Funnel',
2931 value: 'export_single_funnels',
2932 },
2933 {
2934 label: 'Bulk Export',
2935 value: 'bulk_export',
2936 },
2937 ],
2938 }
2939 openModal(config)
2940 })
2941
2942 $('#facebook-pixel-enable-pro').on('click', function (e) {
2943 const config = {
2944 showSubHeading: true,
2945 subHeading:
2946 'This feature is only available in the Pro version. Upgrade Now to continue all these awesome features',
2947 confirmLink: 'https://useraccount.getwpfunnels.com/wpf-small-annual-brand-new/steps/wpf-sa-checkout/',
2948 features: [
2949 {
2950 label: 'Unlimited Contacts k',
2951 value: 'unlimited_contacts',
2952 },
2953 {
2954 label: 'Conditional Prancing k',
2955 value: 'conditional_prancing',
2956 },
2957 {
2958 label: '360 Contacts view',
2959 value: '360_contacts_view',
2960 },
2961 {
2962 label: 'Connect with From Plugins',
2963 value: 'Connect_with_From_Plugins',
2964 },
2965 {
2966 label: 'Over 60+ Integrations',
2967 value: 'Over_60+_Integrations',
2968 },
2969 ],
2970 }
2971 openModal(config)
2972 })
2973
2974 $(document).on('click', '#facebook-pixel-enable-pro', function (e) {
2975 e.preventDefault()
2976 e.target.checked = false
2977 const config = {
2978 showSubHeading: true,
2979 subHeading: 'Upgrade to Pro for FB Pixel Tracking.',
2980 confirmLink: 'https://useraccount.getwpfunnels.com/wpf-small-annual-brand-new/steps/wpf-sa-checkout/',
2981 features: [
2982 {
2983 label: 'FB Pixel Tracking',
2984 value: 'fb_pixel_tracking',
2985 },
2986 {
2987 label: 'Enable/Disable for Single Funnel',
2988 value: 'enable_disable_single_funnel',
2989 },
2990 {
2991 label: 'Purchase Event Tracking',
2992 value: 'purchase_event_tracking',
2993 },
2994 {
2995 label: 'Page View Tracking',
2996 value: 'page_view_tracking',
2997 },
2998 {
2999 label: 'Add to Cart Tracking',
3000 value: 'add_to_cart_tracking',
3001 },
3002 {
3003 label: 'Upsell/Downsell Tracking',
3004 value: 'offer_tracking',
3005 },
3006 ],
3007 }
3008 openModal(config)
3009 })
3010
3011 $(document).on('click', '#gtm-enable-pro', function (e) {
3012 e.preventDefault()
3013 e.target.checked = false
3014 const config = {
3015 showSubHeading: true,
3016 subHeading: 'Upgrade to Pro for GTM Tracking.',
3017 confirmLink: 'https://useraccount.getwpfunnels.com/wpf-small-annual-brand-new/steps/wpf-sa-checkout/',
3018 features: [
3019 {
3020 label: 'GTM Tracking',
3021 value: 'gtm_tracking',
3022 },
3023 {
3024 label: 'Enable/Disable for Single Funnel',
3025 value: 'enable_disable_single_funnel',
3026 },
3027 {
3028 label: 'Purchase Event Tracking',
3029 value: 'purchase_event_tracking',
3030 },
3031 {
3032 label: 'Page View Tracking',
3033 value: 'page_view_tracking',
3034 },
3035 {
3036 label: 'Add to Cart Tracking',
3037 value: 'add_to_cart_tracking',
3038 },
3039 {
3040 label: 'Shipping Info Tracking',
3041 value: 'shipping_tracking',
3042 },
3043 {
3044 label: 'OrderBump Tracking',
3045 value: 'orderbump_tracking',
3046 },
3047 {
3048 label: 'Upsell/Downsell Tracking',
3049 value: 'offer_tracking',
3050 },
3051 ],
3052 }
3053 openModal(config)
3054 })
3055
3056 // open modal ends
3057
3058 // Close Toaster
3059 $(document).on('click', '#wpfnl-toaster-close-btn', function (e) {
3060 $('#wpfnl-toaster-wrapper').hide()
3061 })
3062
3063 // Pro modal
3064 $(document).on('click', '#pro-modal-dropdown-btn', function () {
3065 $('#pro-modal-dropdown-body').toggleClass('show-dropdown')
3066 $('#pro-modal-dropdown-btn').toggleClass('btn-rotate')
3067 })
3068
3069 $(document).on('click', '.wpfnl-pro-modal-dropdown li', function () {
3070 const selectedValue = $(this).attr('value')
3071 const url = $(this).data('url')
3072 const selectedHTML = $(this).html()
3073
3074 $('#pro-modal-package-type').html(selectedHTML)
3075 $('#pro-modal-package-price').html(`<strong>$ ${selectedValue}</strong> <span>/year</span>`)
3076 $('.wpfnl-footer-btn-wrapper .btn-default.confirmed').attr('href', url);
3077 $('#pro-modal-dropdown-body').toggleClass('show-dropdown')
3078 $('#pro-modal-dropdown-btn').toggleClass('btn-rotate')
3079 })
3080
3081
3082 // no funnels screen video popup
3083 $(document).on('click', '.no-funnel-play-button', function () {
3084 const $popup = $('#no-funnel-video-popup');
3085 const $iframe = $('#no-funnel-video-iframe');
3086 const videoSrc = $iframe.data('src');
3087
3088 // Set the iframe src to start video with autoplay
3089 if (videoSrc && !$iframe.attr('src')) {
3090 $iframe.attr('src', videoSrc);
3091 }
3092
3093 $popup.addClass('show');
3094 $('body').css('overflow', 'hidden');
3095 })
3096
3097 $(document).on('click', '#no-funnel-video-popup .video-popup-close, #no-funnel-video-popup', function (e) {
3098 // Only close if clicking the close button or overlay (not the content)
3099 if ($(e.target).is('#no-funnel-video-popup') || $(e.target).closest('.video-popup-close').length) {
3100 const $popup = $('#no-funnel-video-popup');
3101 const $iframe = $('#no-funnel-video-iframe');
3102
3103 // Remove src to stop the video
3104 $iframe.attr('src', '');
3105
3106 $popup.removeClass('show');
3107 $('body').css('overflow', '');
3108 }
3109 })
3110
3111 })(jQuery)
3112