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

3,021 lines 111.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 *
883 * Ajax handler for import funnels
884 * funnel action
885 *
886 * @param event
887 * @since 2.6.3
888 */
889 FunnelHandler.prototype.ImportFunnels = function (event) {
890 event.preventDefault()
891 $('#wpfnl-import-funnel .wpfnl-loader').css('display', 'inline-block')
892 $('#wpfnl-export-import-warning').css('display', 'none')
893 let formData = new FormData(this)
894 let importFile = $('#wpfnl-file-import')[0].files[0]
895 if (importFile) {
896 const fileName = importFile?.name
897 const fileExtension = fileName.split('.').pop()
898 if ('json' === fileExtension) {
899 formData.append('action', 'wpfnl_import_funnels')
900 formData.append('is_ajax', 'yes')
901 formData.append('nonce', WPFunnelVars.import_nonce)
902 formData.append('uploaded_file', importFile)
903
904 $.ajax({
905 url: WPFunnelVars.ajaxurl,
906 type: 'post',
907 contentType: false,
908 dataType: 'json',
909 processData: false,
910 data: formData,
911 success: function (response) {
912 window.location.reload();
913 $('#wpfnl-import-funnel .wpfnl-loader').css('display', 'none')
914 $('.import-funnel-modal').removeClass('show-modal')
915 },
916 }).done(function (request, status, XHR) {
917 if (status.success) {
918 // window.location.reload();
919 }
920 $('#wpfnl-import-funnel .wpfnl-loader').css('display', 'none')
921 $('.import-funnel-modal').removeClass('show-modal')
922 })
923 } else {
924 $('#wpfnl-export-import-warning').css('display', 'inline-block')
925 $('#wpfnl-export-import-warning').css('color', '#d63638 !important')
926 $('#wpfnl-import-funnel .wpfnl-loader').css('display', 'none')
927 }
928 } else {
929 $('#wpfnl-export-import-warning').css('display', 'inline-block')
930 $('#wpfnl-export-import-warning').css('color', '#d63638 !important')
931 $('#wpfnl-import-funnel .wpfnl-loader').css('display', 'none')
932 }
933 }
934
935 /**
936 *
937 * Ajax handler for import funnels
938 * funnel action
939 *
940 * @param event
941 * @since 2.6.3
942 */
943 FunnelHandler.prototype.UploadFile = function (event) {
944 event.preventDefault()
945 $('#wpfnl-export-import-warning').css('display', 'none')
946 let importFile = $('#wpfnl-file-import')[0].files[0]
947
948 if (importFile) {
949 const fileName = importFile?.name
950 const fileExtension = fileName.split('.').pop()
951
952 if ('json' === fileExtension) {
953 $('#wpfnl-export-import-warning').css('display', 'none')
954 $('.import-funnel-modal .import-label').addClass('file-added')
955 $('.import-funnel-modal .import-label > h4').text('Json file ready for import.')
956 $('.import-funnel-modal .import-label > p').text(fileName)
957 } else {
958 $('.import-funnel-modal .import-label').removeClass('file-added')
959 $('#wpfnl-export-import-warning').css('display', 'inline-block')
960 $('#wpfnl-export-import-warning').css('color', '#d63638 !important')
961
962 $('.import-funnel-modal .import-label > h4').html(
963 'Drag & Drop or <span class="primary-color">Choose file</span> to upload.',
964 )
965 $('.import-funnel-modal .import-label > p').text(
966 'Supported formats: JSON file.',
967 )
968 }
969 } else {
970 $('.import-funnel-modal .import-label').removeClass('file-added')
971 $('#wpfnl-export-import-warning').css('display', 'inline-block')
972 $('#wpfnl-export-import-warning').css('color', '#d63638 !important')
973
974 $('.import-funnel-modal .import-label > h4').html(
975 'Drag & Drop or <span class="primary-color">Choose file</span> to upload.',
976 )
977 $('.import-funnel-modal .import-label > p').text('Supported formats: JSON file.')
978 }
979 }
980
981 /**
982 * Download json file
983 *
984 * @param content
985 * @param fileName
986 * @param contentType
987 *
988 * @since 2.6.3
989 */
990 function download(content, fileName, contentType) {
991 const a = document.createElement('a')
992 const file = new Blob([content], { type: contentType })
993 a.href = URL.createObjectURL(file)
994 a.download = fileName
995 a.click()
996 }
997
998 /**
999 * Realtime funnel name change on header
1000 *
1001 * @param event
1002 * @since 1.0.0
1003 */
1004 var fnl_name = ''
1005 var fnl_name2 = ''
1006 var funnelNameWidth = ''
1007 $('.funnel-name-edit').on('click', function (e) {
1008 e.stopPropagation();
1009 fnl_name = $(this).parents('.steps-page__fnl-name').find('.funnel-name').text()
1010 $(this).hide()
1011 funnelNameWidth = $(this).parents('.steps-page__fnl-name').find('.funnel-name').width()
1012
1013 $(this)
1014 .parents('.steps-page__fnl-name')
1015 .find('.funnel-name-input')
1016 .css('width', funnelNameWidth + 'px')
1017 $(this)
1018 .parents('.steps-page__fnl-name')
1019 .find('.funnel-name-input')
1020 .val(fnl_name)
1021 .show()
1022 .focus()
1023 $(this).parents('.steps-page__fnl-name').find('.funnel-name').hide()
1024 })
1025
1026 $('.funnel-name-input').keyup(function (e) {
1027 e.stopPropagation();
1028 $(this).parents('.steps-page__fnl-name').find('.funnel-name').text($(this).val())
1029 funnelNameWidth = $(this).parents('.steps-page__fnl-name').find('.funnel-name').width()
1030
1031 let input = $(this);
1032 let valueLength = input.val().length;
1033 input.css('width', funnelNameWidth + 'px');
1034
1035 // When Enter is pressed, save and hide input, show funnel name
1036 if (e.keyCode === 13 || e.key === 'Enter') {
1037 fnl_name2 = $(this).val();
1038
1039 if(fnl_name2.length === 0){
1040 fnl_name2 = fnl_name;
1041 }
1042
1043 $(this).val(fnl_name2).hide();
1044 $(this).parents('.steps-page__fnl-name').find('.funnel-name').text(fnl_name2).show();
1045 $(this).blur(); // Remove focus from input
1046 }
1047 })
1048
1049 $('.funnel-name-input').on('click', function (e) {
1050 e.stopPropagation();
1051 })
1052
1053 if($('.funnel-name-input').length > 0){
1054 $('body').on('click', function (e) {
1055 fnl_name2 = $('.steps-page__fnl-name .funnel-name-input').val() || '';
1056
1057 if(fnl_name2.length === 0){
1058 fnl_name2 = fnl_name;
1059 }
1060
1061 $('.steps-page__fnl-name .funnel-name-input').val(fnl_name2).hide()
1062 $('.steps-page__fnl-name .funnel-name').text(fnl_name2).show()
1063 })
1064 }
1065
1066 /**
1067 * Realtime automation name change on automation drawer
1068 *
1069 * @param event
1070 * @since 1.0.0
1071 */
1072 var automation_name = ''
1073 var automation_name2 = ''
1074 $(document).on('click', '.automation-name-edit', function (e) {
1075 e.preventDefault()
1076
1077 automation_name = $(this)
1078 .parents('.automation-name-wrapper')
1079 .find('.automation-name-preview')
1080 .text()
1081 $(this).hide()
1082 $('.automation-name-cancel').css('display', 'flex')
1083 $(this)
1084 .parents('.automation-name-wrapper')
1085 .find('.automation-name-input')
1086 .val(automation_name)
1087 .css('display', 'flex')
1088 $(this).parents('.automation-name-wrapper').find('.automation-name-preview').hide()
1089 $(this)
1090 .parents('.automation-name-wrapper')
1091 .find('.automation-name-submit')
1092 .css('display', 'flex')
1093 })
1094
1095 // $(document).on("click", ".automation-name-edit", function(e) {
1096 $('.automation-name-input').keyup(function () {
1097 $(this)
1098 .parents('.automation-name-wrapper')
1099 .find('.automation-name-preview')
1100 .text($(this).val())
1101 })
1102
1103 $(document).on('click', '.automation-name-submit', function (e) {
1104 e.preventDefault()
1105 automation_name2 = $(this)
1106 .parents('.automation-name-wrapper')
1107 .find('.automation-name-input')
1108 .val()
1109 $(this).hide()
1110 $('.automation-name-cancel').hide()
1111 $(this)
1112 .parents('.automation-name-wrapper')
1113 .find('.automation-name-input')
1114 .val(automation_name2)
1115 .hide()
1116 $(this)
1117 .parents('.automation-name-wrapper')
1118 .find('.automation-name-preview')
1119 .text(automation_name2)
1120 .css('display', 'flex')
1121 $(this)
1122 .parents('.automation-name-wrapper')
1123 .find('.automation-name-edit')
1124 .css('display', 'flex')
1125 })
1126
1127 $(document).on('click', '.automation-name-cancel', function (e) {
1128 e.preventDefault()
1129 $(this).hide()
1130 $('.automation-name-cancel').hide()
1131 $(this)
1132 .parents('.automation-name-wrapper')
1133 .find('.automation-name-input')
1134 .val(automation_name)
1135 .hide()
1136 $(this)
1137 .parents('.automation-name-wrapper')
1138 .find('.automation-name-preview')
1139 .text(automation_name)
1140 .css('display', 'flex')
1141 $(this).parents('.automation-name-wrapper').find('.automation-name-submit').hide()
1142 $(this)
1143 .parents('.automation-name-wrapper')
1144 .find('.automation-name-edit')
1145 .css('display', 'flex')
1146 })
1147
1148 $(document).on('click', '#save_automation', function (e) {
1149 e.preventDefault()
1150 $('.event-trigger').each(function () {
1151 if ($(this).children('option:selected').val() == '') {
1152 $(this).parents('.wpfnl-form-group').addClass('field-required')
1153 } else {
1154 $(this).parents('.wpfnl-form-group').removeClass('field-required')
1155 }
1156 })
1157 $('.list-trigger').each(function () {
1158 if ($(this).children('option:selected').val() == '') {
1159 $(this).parents('.wpfnl-form-group').addClass('field-required')
1160 } else {
1161 $(this).parents('.wpfnl-form-group').removeClass('field-required')
1162 }
1163 })
1164 $('.tag-trigger').each(function () {
1165 if ($(this).children('option:selected').val() == '') {
1166 $(this).parents('.wpfnl-form-group').addClass('field-required')
1167 } else {
1168 $(this).parents('.wpfnl-form-group').removeClass('field-required')
1169 }
1170 })
1171 })
1172
1173 //-----remove "field-required" class when data selected-------
1174 $(document).on('change', '.single-trigger .selectbox-wrapper select', function (e) {
1175 if ($(this).children('option:selected').val() != '') {
1176 $(this).parents('.wpfnl-form-group').removeClass('field-required')
1177 }
1178 })
1179
1180 /**
1181 * change funnel name
1182 *
1183 * @param event
1184 * @since 1.0.0
1185 */
1186 FunnelHandler.prototype.changeFunnelName = function (event) {
1187 event.preventDefault()
1188 var payload = {
1189 data: $(this).serialize(),
1190 },
1191 button = $(this).find('.funnel-name-submit')
1192 button.hide()
1193 button.parents('.steps-page__fnl-name').find('.funnel-name-input').hide()
1194 button.parents('.steps-page__fnl-name').find('.funnel-name').show()
1195 button.parents('.steps-page__fnl-name').find('.funnel-name-edit').show()
1196 wpAjaxHelperRequest('funnel-name-change', payload)
1197 .success(function (response) {
1198 location.reload()
1199 })
1200 .error(function (response) {})
1201 }
1202
1203 var StepHandler = function () {
1204 $(document.body)
1205 .on('click', '#wpfnl-delete-step', this.deleteStep)
1206 .on('click', '#wpfnl-update-checkout-product-tab', this.updateCheckoutProduct)
1207 .on('click', '#wpfnl-update-thank-you-settings', this.updateThankYouSettings)
1208 .on('click', '#wpfnl-update-upsell-settings', this.updateUpsellSettings)
1209 .on('click', '#wpfnl-update-downsell-settings', this.updateDownsellSettings)
1210 .on('change', '#wpfnl-choose-step-type', this.stepTypeChange)
1211 // .on('click', '#wpfnl-add-product', this.addProduct)
1212 }
1213
1214 /**
1215 * add product
1216 * @param event
1217 */
1218 StepHandler.prototype.addProduct = function (event) {
1219 event.preventDefault()
1220 var _prObj = $('#wpfnl-checkout-products').select2('data')[0],
1221 step_id = $(this).attr('data-id')
1222 if (_prObj) {
1223 product_option.push({
1224 id: _prObj.id,
1225 quantity: 1,
1226 })
1227 var payload = {
1228 id: _prObj.id,
1229 step_id: step_id,
1230 products: JSON.stringify(product_option),
1231 index: parseInt($('.product__single-accordion').length),
1232 },
1233 that = $(this)
1234
1235 wpAjaxHelperRequest('wpfnl-add-product', payload)
1236 .success(function (response) {
1237 if (response.success) {
1238 $('.no-product-notice').hide()
1239 $('.accordion-head').show()
1240 // $('.product-accordion__wrapper').append(response.html);
1241 $('.product-single-accordion__sortable-wrapper').append(response.html)
1242 $('#wpfnl-checkout-products').val(null).trigger('change')
1243 if (product_option.length) that.html('Add product')
1244 // $('.product__single-accordion:nth-child(2)').addClass('active');
1245 }
1246 console.log('Woohoo!')
1247 console.log(response)
1248 $('#setp-list-' + step_id + ' span').css('color', 'black')
1249
1250 $('.product-single-accordion__sortable-wrapper').sortable({
1251 axis: 'y',
1252 start: function (event, ui) {},
1253 update: function (event, ui) {
1254 var product_order = $(
1255 '.product-single-accordion__sortable-wrapper',
1256 ).sortable('toArray')
1257
1258 product_option = []
1259 var funnel_id = getUrlParameter('id')
1260
1261 for (var i in product_order) {
1262 var dragger_id = product_order[i]
1263 var prod_id = dragger_id.replace(
1264 'product__single-accordion-',
1265 '',
1266 )
1267 var quantity = $('#product-quantity-' + prod_id).val()
1268 product_option.push({
1269 id: prod_id,
1270 quantity: quantity,
1271 })
1272 }
1273 },
1274 })
1275 $('.product-single-accordion__sortable-wrapper').disableSelection()
1276 })
1277 .error(function (response) {})
1278 }
1279 }
1280
1281 /**
1282 * delete product from checkout
1283 *
1284 * @param event
1285 */
1286 StepHandler.prototype.deleteproduct = function (event) {
1287 event.preventDefault()
1288 var index = $(this).attr('data-index')
1289 product_option.splice(index, 1)
1290 var payload = {
1291 step_id: $(this).attr('data-id'),
1292 products: JSON.stringify(product_option),
1293 }
1294 wpAjaxHelperRequest('wpfnl-update-checkout-product-tab', payload)
1295 .success(function (response) {
1296 if (response.success) {
1297 location.reload()
1298 return false
1299 }
1300 console.log('Woohoo!')
1301 console.log(response)
1302 })
1303 .error(function (response) {})
1304 }
1305
1306 /**
1307 * save function for checkout steps
1308 * product tab
1309 *
1310 * @param event
1311 * @since 1.0.0
1312 */
1313 StepHandler.prototype.updateCheckoutProduct = function (event) {
1314 event.preventDefault()
1315 var thisLoader = $(this).find('.wpfnl-loader')
1316 var thisAlert = $(this).siblings('.wpfnl-alert')
1317
1318 //=== Enable additional checkout fields===//
1319 var coupon = 'no'
1320 if ($('#enable-checkout-coupon').prop('checked') == true) {
1321 coupon = 'yes'
1322 } else if ($('#enable-checkout-coupon').prop('checked') == false) {
1323 coupon = 'no'
1324 }
1325
1326 //=== Enable additional checkout fields===//
1327
1328 thisLoader.fadeIn()
1329 var payload = {
1330 step_id: $(this).attr('data-iddata-id'),
1331 coupon: coupon,
1332 products: JSON.stringify(product_option),
1333 // discount: $(".wpfnl-checkout-discount").val(),
1334 }
1335 wpAjaxHelperRequest('wpfnl-update-checkout-product-tab', payload)
1336 .success(function (response) {
1337 thisLoader.fadeOut()
1338 thisAlert.text('Saved Successfully').addClass('box wpfnl-success').fadeIn()
1339
1340 setTimeout(function () {
1341 thisAlert.fadeOut().text('').removeClass('box wpfnl-success')
1342 }, 2000)
1343
1344 console.log('Woohoo!')
1345 console.log(response)
1346 })
1347 .error(function (response) {
1348 console.log('Uh, oh!')
1349 console.log(response.statusText)
1350
1351 thisLoader.fadeOut()
1352 thisAlert.text('Erorr occurred').addClass('box wpfnl-error').fadeIn()
1353 setTimeout(function () {
1354 thisAlert.fadeOut().text('').removeClass('box wpfnl-error')
1355 }, 2000)
1356 })
1357 }
1358
1359 /**
1360 * Set minimum time for custom redirection in thankyou page
1361 *
1362 * @param event
1363 *
1364 */
1365 $(document).on('keyup', '#set-time', function () {
1366 if ($('#set-time').val() && $('#set-time').val() < 1) {
1367 $('#set-time').val(1)
1368 }
1369 })
1370
1371 /**
1372 * save thankyou settings
1373 * options
1374 *
1375 * @param event
1376 * @since 1.0.0
1377 */
1378 StepHandler.prototype.updateThankYouSettings = function (event) {
1379 event.preventDefault()
1380 var thisLoader = $(this).find('.wpfnl-loader')
1381 var thisAlert = $(this).siblings('.wpfnl-alert')
1382 thisLoader.fadeIn()
1383 var payload = {
1384 step_id: $(this).attr('data-id'),
1385 text: $('.thankyou-page-text').val(),
1386 redirect_link: $('.thankyou-redirect-link').val(),
1387 order_overview: $('#enable-order-overview').is(':checked') ? 'on' : 'off',
1388 order_details: $('#enable-order-details').is(':checked') ? 'on' : 'off',
1389 billing_details: $('#enable-billing-details').is(':checked') ? 'on' : 'off',
1390 shipping_details: $('#enable-shipping-details').is(':checked') ? 'on' : 'off',
1391 is_custom_redirect: $('#enable-custom-redirect').is(':checked') ? 'on' : 'off',
1392
1393 is_direct_redirect: $('#direct-custom-redirect').is(':checked') ? 'on' : 'off',
1394 set_time: $('#set-time').val(),
1395 custom_redirect_url: $('#custom-redirect-url').val(),
1396 }
1397
1398 wpAjaxHelperRequest('update-thankyou-settings', payload)
1399 .success(function (response) {
1400 thisLoader.fadeOut()
1401 $('#wpfnl-toaster-wrapper').addClass('quick-toastify-successful-notification')
1402
1403 $('#wpfnl-toaster-icon').html(
1404 '<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>',
1405 )
1406
1407 $('#wpfnl-toaster-message').html('Saved Successfully')
1408 $('#wpfnl-toaster-wrapper').show()
1409 setTimeout(function () {
1410 $('#wpfnl-toaster-wrapper').removeClass(
1411 'quick-toastify-successful-notification',
1412 )
1413 $('#wpfnl-toaster-wrapper').hide()
1414 }, 3000)
1415 })
1416 .error(function (response) {
1417 console.log('Uh, oh!')
1418 console.log(response.statusText)
1419 thisLoader.fadeOut()
1420 $('#wpfnl-toaster-wrapper').addClass('quick-toastify-warn-notification')
1421
1422 $('#wpfnl-toaster-icon').html(
1423 '<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>',
1424 )
1425
1426 $('#wpfnl-toaster-message').html('Erorr occurred')
1427 $('#wpfnl-toaster-wrapper').show()
1428 setTimeout(function () {
1429 $('#wpfnl-toaster-wrapper').removeClass('quick-toastify-warn-notification')
1430 $('#wpfnl-toaster-wrapper').hide()
1431 }, 3000)
1432 })
1433 }
1434
1435 /**
1436 * save upsell settings
1437 * options
1438 *
1439 * @param event
1440 * @since 1.0.0
1441 */
1442 StepHandler.prototype.updateUpsellSettings = function (event) {
1443 event.preventDefault()
1444 var thisLoader = $(this).find('.wpfnl-loader')
1445 var thisAlert = $(this).siblings('.wpfnl-alert')
1446 thisLoader.fadeIn()
1447 var payload = {
1448 step_id: $(this).attr('data-id'),
1449 product: $('.wpfnl-product-search').val(),
1450 quantity: $('#upsell-product-quantity').val(),
1451 product_price: $('#upsell-original-price').val(),
1452 product_sale_price: $('#upsell-sale-price').val(),
1453 discount_type: $('#upsell-discount-type').val(),
1454 discount_value: $('#upsell-discount-value').val(),
1455 hide_image: $('#img-hide-mobile').prop('checked') ? 'on' : 'off',
1456 next_step_yes: $('#next-step-yes').val(),
1457 next_step_no: $('#next-step-no').val(),
1458 }
1459 wpAjaxHelperRequest('update-upsell-settings', payload)
1460 .success(function (response) {
1461 thisLoader.fadeOut()
1462 thisAlert.text('Saved Successfully').addClass('box wpfnl-success').fadeIn()
1463 setTimeout(function () {
1464 thisAlert.fadeOut().text('').removeClass('box wpfnl-success')
1465 }, 2000)
1466 console.log('Woohoo!')
1467 console.log(response)
1468 })
1469 .error(function (response) {
1470 console.log('Uh, oh!')
1471 console.log(response.statusText)
1472 thisLoader.fadeOut()
1473 thisAlert.text('Erorr occurred').addClass('box wpfnl-error').fadeIn()
1474 setTimeout(function () {
1475 thisAlert.fadeOut().text('').removeClass('box wpfnl-error')
1476 }, 2000)
1477 })
1478 }
1479
1480 /**
1481 * save downsell settings
1482 * options
1483 *
1484 * @param event
1485 * @since 1.0.0
1486 */
1487 StepHandler.prototype.updateDownsellSettings = function (event) {
1488 event.preventDefault()
1489 var thisLoader = $(this).find('.wpfnl-loader')
1490 var thisAlert = $(this).siblings('.wpfnl-alert')
1491 thisLoader.fadeIn()
1492 var payload = {
1493 step_id: $(this).attr('data-id'),
1494 product: $('.wpfnl-product-search').val(),
1495 quantity: $('#downsell-product-quantity').val(),
1496 product_price: $('#downsell-original-price').val(),
1497 product_sale_price: $('#downsell-sale-price').val(),
1498 discount_type: $('#downsell-discount-type').val(),
1499 discount_value: $('#downsell-discount-value').val(),
1500 hide_image: $('#img-hide-mobile').prop('checked') ? 'on' : 'off',
1501 next_step_yes: $('#next-step-yes').val(),
1502 next_step_no: $('#next-step-no').val(),
1503 }
1504 wpAjaxHelperRequest('update-downsell-settings', payload)
1505 .success(function (response) {
1506 thisLoader.fadeOut()
1507 thisAlert.text('Saved Successfully').addClass('box wpfnl-success').fadeIn()
1508 setTimeout(function () {
1509 thisAlert.fadeOut().text('').removeClass('box wpfnl-success')
1510 }, 2000)
1511 console.log('Woohoo!')
1512 console.log(response)
1513 })
1514 .error(function (response) {
1515 console.log('Uh, oh!')
1516 console.log(response.statusText)
1517 thisLoader.fadeOut()
1518 thisAlert.text('Erorr occurred').addClass('box wpfnl-error').fadeIn()
1519 setTimeout(function () {
1520 thisAlert.fadeOut().text('').removeClass('box wpfnl-error')
1521 }, 2000)
1522 })
1523 }
1524
1525 /**
1526 * Ajax handler for step
1527 * deletion action
1528 *
1529 * @param event
1530 */
1531 StepHandler.prototype.deleteStep = function (event) {
1532 event.preventDefault()
1533 var step_id = $(this).attr('data-id')
1534 var payload = {
1535 step_id: step_id,
1536 }
1537 if (confirm('Are you sure?')) {
1538 wpAjaxHelperRequest('delete-step', payload)
1539 .success(function (response) {
1540 console.log('Woohoo!')
1541 console.log(response)
1542 window.location.href = response.redirectUrl
1543 })
1544 .error(function (response) {
1545 console.log('Uh, oh!')
1546 console.log(response.statusText)
1547 })
1548 }
1549 }
1550
1551 /**
1552 * Ajax handler for step
1553 * creation
1554 *
1555 * @param e
1556 * @since 1.0.0
1557 */
1558 StepHandler.prototype.createStep = function (e) {
1559 e.preventDefault()
1560 var thisLoader = $(this).find('.wpfnl-loader')
1561 var thisAlert = $(this).siblings('.wpfnl-alert')
1562
1563 thisLoader.fadeIn()
1564
1565 var wrapper = $('#create-step-form'),
1566 type = $(this).attr('data-step-type'),
1567 funnelId = $(this).attr('data-funnel-id'),
1568 stepListWrapper = $('#wpfnl-funnel-step-lists')
1569
1570 var payload = {
1571 funnel_id: funnelId,
1572 step_type: type,
1573 }
1574 wpAjaxHelperRequest('create-step', payload)
1575 .success(function (response) {
1576 console.log('success')
1577 thisLoader.fadeOut()
1578 thisAlert
1579 .text('Successfully Step Created')
1580 .addClass('box wpfnl-success')
1581 .fadeIn()
1582
1583 setTimeout(function () {
1584 thisAlert.fadeOut().text('').removeClass('box wpfnl-success')
1585 }, 2000)
1586
1587 if (response.success) {
1588 window.location.href = response.redirectUrl
1589 } else {
1590 console.log(response)
1591 }
1592 })
1593 .error(function (response) {
1594 thisLoader.fadeOut()
1595 thisAlert.text('Erorr Occurred').addClass('box wpfnl-error').fadeIn()
1596
1597 setTimeout(function () {
1598 thisAlert.fadeOut().text('').removeClass('box wpfnl-error')
1599 }, 2000)
1600 })
1601 }
1602
1603 StepHandler.prototype.stepTypeChange = function (event) {
1604 event.preventDefault()
1605 var wrapper = $('.choose-step-type'),
1606 step_type = $(this).find(':selected').val(),
1607 saveBtn = $('#wpfnl-create-step')
1608 if (
1609 WPFunnelVars.is_wc_installed === 'no' &&
1610 (step_type === 'checkout' || step_type === 'upsell' || step_type === 'downsell')
1611 ) {
1612 $('.wpfnl-modal__body').find('p').remove()
1613 wrapper.after(
1614 "<p style='text-align: center; color: red'>You need install and active WooCommerce to use this step type. </p>",
1615 )
1616 saveBtn.addClass('disabled').css('pointer-events', 'none')
1617 return
1618 } else {
1619 $('.wpfnl-modal__body').find('p').remove()
1620 saveBtn.removeClass('disabled').css('pointer-events', 'inherit')
1621 }
1622 }
1623
1624 var DataSerachHandler = function () {
1625 this.initProductSearch()
1626 this.initCouponSearch()
1627 }
1628
1629 /**
1630 * initialize product search
1631 * for checkout
1632 *
1633 * @param event
1634 * @since 1.0.0
1635 */
1636 DataSerachHandler.prototype.initProductSearch = function (event) {
1637 var select2Args = {
1638 minimumInputLength: 3,
1639 allowClear: true,
1640 maximumSelectionLength: 1,
1641 ajax: {
1642 url: WPFunnelVars.ajaxurl,
1643 dataType: 'json',
1644 delay: 250,
1645 data: function (params) {
1646 return {
1647 term: params.term,
1648 action: 'wpfnl_product_search',
1649 security: WPFunnelVars.security,
1650 }
1651 },
1652 processResults: function (data) {
1653 var terms = []
1654 if (data) {
1655 $.each(data, function (id, value) {
1656 terms.push({
1657 id: id,
1658 text: value.name,
1659 price: value.price,
1660 sale_price: value.sale_price,
1661 })
1662 })
1663 }
1664 return {
1665 results: terms,
1666 }
1667 },
1668 cache: true,
1669 },
1670 }
1671
1672 $('.wpfnl-product-search').on('select2:select', function (e) {
1673 var data = e.params.data
1674 $('#upsell-original-price').val(data.price)
1675 $('#upsell-sale-price').val(data.sale_price)
1676
1677 $('#downsell-original-price').val(data.price)
1678 $('#downsell-sale-price').val(data.sale_price)
1679 })
1680 $('.wpfnl-product-search').select2(select2Args)
1681 }
1682
1683 /**
1684 * initialize coupon search
1685 * for checkout
1686 *
1687 * @param event
1688 * @since 1.0.0
1689 */
1690 DataSerachHandler.prototype.initCouponSearch = function (event) {
1691 var select2Args = {
1692 minimumInputLength: 3,
1693 allowClear: true,
1694 ajax: {
1695 url: WPFunnelVars.ajaxurl,
1696 dataType: 'json',
1697 delay: 250,
1698 data: function (params) {
1699 return {
1700 term: params.term,
1701 action: 'wpfnl_coupon_search',
1702 security: WPFunnelVars.security,
1703 }
1704 },
1705 processResults: function (data) {
1706 var terms = []
1707 if (data) {
1708 $.each(data, function (id, text) {
1709 terms.push({
1710 id: id,
1711 text: text,
1712 })
1713 })
1714 }
1715 return {
1716 results: terms,
1717 }
1718 },
1719 cache: true,
1720 },
1721 }
1722 $('.wpfnl-discount-search').select2(select2Args)
1723 }
1724
1725 var AdminNotices = function () {
1726 $(document.body)
1727 .on('click', '#wpfnl-install-plugin', this.installPlugin)
1728 .on('wp-plugin-install-success', this.installSuccess)
1729 $(document).on('wp-plugin-install-success', self._installSuccess)
1730 }
1731 AdminNotices.prototype.installPlugin = function (e) {
1732 e.preventDefault()
1733 let slug = $(this).attr('data-slug')
1734 wp.updates.queue.push({
1735 action: 'install-plugin', // Required action.
1736 data: {
1737 slug: slug,
1738 },
1739 })
1740 wp.updates.queueChecker()
1741 }
1742 AdminNotices.prototype.installSuccess = function (event, response) {
1743 event.preventDefault()
1744 console.log(response)
1745 }
1746
1747 new FunnelHandler()
1748 new StepHandler()
1749 new DataSerachHandler()
1750 new AdminNotices()
1751
1752 /**
1753 * funnel list show more action on click
1754 *
1755 * @since 1.0.0
1756 */
1757 $('body').on('click', function () {
1758 $('.funnel-list__more-action').removeClass('show-actions')
1759 })
1760
1761 $('.funnel-list__more-action').on('click', function (e) {
1762 e.stopPropagation()
1763 $(this).toggleClass('show-actions')
1764 $(this)
1765 .parents('.funnel__single-list')
1766 .siblings()
1767 .find('.funnel-list__more-action')
1768 .removeClass('show-actions')
1769 })
1770
1771 $('.funnel-list__more-action .wpfnl-dropdown').on('click', function (e) {
1772 e.stopPropagation()
1773 })
1774
1775 /**
1776 * copy to clipboard
1777 *
1778 * @since 1.0.0
1779 */
1780 $('.wpfnl-copy-clipboard').on('click', function () {
1781 var getID = $(this).attr('data-id')
1782 var getText = $('#' + getID).val()
1783 CopyToClipboard(getText)
1784
1785 $(this).siblings('.copied-msg').text('Copied').fadeIn(500)
1786
1787 setTimeout(function () {
1788 $('.copied-msg').fadeOut('slow')
1789 }, 2500)
1790 })
1791
1792 /**
1793 * copy to clipboard helper function
1794 *
1795 * @since 1.0.0
1796 */
1797 function CopyToClipboard(text) {
1798 if (window.clipboardData && window.clipboardData.setData) {
1799 return clipboardData.setData('Text', text)
1800 } else if (document.queryCommandSupported && document.queryCommandSupported('copy')) {
1801 var textarea = document.createElement('textarea')
1802 textarea.textContent = text
1803 textarea.style.position = 'fixed'
1804 document.body.appendChild(textarea)
1805 textarea.select()
1806
1807 try {
1808 return document.execCommand('copy')
1809 } catch (ex) {
1810 console.warn('Copy to clipboard failed.', ex)
1811 return false
1812 } finally {
1813 document.body.removeChild(textarea)
1814 }
1815 }
1816 }
1817
1818 /**
1819 * open modal when add new step
1820 *
1821 * @param event
1822 * @since 1.0.0
1823 */
1824 $('.wpfnl-modal-close').on('click', function (e) {
1825 e.preventDefault()
1826 $(this).parents('.wpfnl-modal').fadeOut(200)
1827 })
1828
1829 $('.wpfnl-modal__wrapper').on('click', function (e) {
1830 e.stopPropagation()
1831 })
1832
1833 /**
1834 * step name change on step page
1835 *
1836 * @param event
1837 * @since 1.0.0
1838 */
1839 var stepName = ''
1840 $('.step-name-edit').on('click', function (e) {
1841 e.preventDefault()
1842 $(this).hide()
1843 stepName = $(this).parents('.title-area').find('.step-name-input').val()
1844 $(this).parents('.title-area').find('.step-name-input').show()
1845 $(this).parents('.title-area').find('.step-name-noupdate').show()
1846 $(this).parents('.title-area').find('.step-name').hide()
1847 $(this).parents('.title-area').find('.step-name-update').show()
1848 })
1849
1850 $('.step-name-update').on('click', function (e) {
1851 e.preventDefault()
1852 $(this).hide()
1853 $(this).parents('.title-area').find('.step-name-input').hide()
1854 $(this).parents('.title-area').find('.step-name-noupdate').hide()
1855 $(this).parents('.title-area').find('.step-name').show()
1856 $(this).parents('.title-area').find('.step-name-edit').show()
1857 })
1858
1859 $('.step-name-noupdate').on('click', function (e) {
1860 e.preventDefault()
1861 $(this).hide()
1862 $(this).parents('.title-area').find('.step-name-input').val(stepName).hide()
1863 $(this).parents('.title-area').find('.step-name-update').hide()
1864 $(this).parents('.title-area').find('.step-name').text(stepName).show()
1865 $(this).parents('.title-area').find('.step-name-edit').show()
1866 })
1867
1868 $('.step-name-input').keyup(function () {
1869 $(this).parents('.title-area').find('.step-name').text($(this).val())
1870 })
1871
1872 /**
1873 * step settings tab
1874 *
1875 * @since 1.0.0
1876 */
1877 $('.step-settings__single-tab-content:first-child').show()
1878
1879 $(document).on('click', '.steps-settings__tab-nav:not(.ab-nav) a', function (e) {
1880 if (!$(this).parent('li').hasClass('disabled')) {
1881 e.preventDefault()
1882 var dataID = $(this).attr('href')
1883
1884 $(this).parent('li').addClass('active').siblings().removeClass('active')
1885 $(this).parents('.steps-settings').find(dataID).show()
1886 $(this).parents('.steps-settings').find(dataID).siblings().hide()
1887 }
1888 })
1889
1890 /**
1891 * step settings product options tab
1892 *
1893 * @since 1.0.0
1894 */
1895 $('.product-options__tab-nav a').on('click', function (e) {
1896 e.preventDefault()
1897
1898 var dataID = $(this).attr('href')
1899 $(this).parent('li').addClass('active').siblings().removeClass('active')
1900
1901 $(this).parents('.wpfnl-product-options').find(dataID).show()
1902 $(this).parents('.wpfnl-product-options').find(dataID).siblings().hide()
1903 })
1904
1905 /**
1906 * wpfnl accordion
1907 *
1908 * @since 1.0.0
1909 */
1910 $('.wpfnl__accordion-content').hide()
1911 $('.wpfnl__single-accordion:first-child .wpfnl__accordion-content').show()
1912 $('.wpfnl__accordion-title').on('click', function (e) {
1913 e.preventDefault()
1914
1915 var dataID = $(this).attr('href')
1916
1917 $(this).parent('.wpfnl__single-accordion').find(dataID).slideToggle()
1918 $(this)
1919 .parents('.wpfnl__single-accordion')
1920 .siblings()
1921 .find('.wpfnl__accordion-content')
1922 .slideUp()
1923 })
1924
1925 /**
1926 * steps-header-hamburger toggle menu
1927 *
1928 * @since 1.0.0
1929 */
1930 $('body').on('click', function () {
1931 $('#steps-header-hamburger').removeClass('show')
1932 })
1933 // $(document).on("click", "#steps-header-hamburger", function(e) {
1934 $('#steps-header-hamburger').on('click', function (e) {
1935 e.stopPropagation()
1936 if (!$(this).hasClass('show')) {
1937 $(this).removeClass('show')
1938 } else {
1939 $(this).addClass('show')
1940 }
1941
1942 wpfnlDatePicker()
1943 })
1944
1945 /**
1946 * wpfnl step title edit
1947 *
1948 * @param event
1949 * @since 1.0.0
1950 */
1951 function step_edit(e) {
1952 e.preventDefault()
1953 var step_id = $(this).attr('data-id')
1954 var input = $('#step-name-input-' + step_id).val()
1955 var payload = {
1956 step_id: step_id,
1957 input: input,
1958 }
1959 wpAjaxHelperRequest('step-edit', payload)
1960 .success(function (response) {
1961 $('#setp-list-' + step_id + ' .title-txt').text(input)
1962
1963 if (response.success) {
1964 console.log('success')
1965 } else {
1966 console.log(response)
1967 }
1968 })
1969 .error(function (response) {
1970 console.log('error')
1971 })
1972 }
1973 $('.step-name-update').on('click', step_edit)
1974 })
1975
1976 function getUrlParameter(sParam) {
1977 var sPageURL = window.location.search.substring(1),
1978 sURLVariables = sPageURL.split('&'),
1979 sParameterName,
1980 i
1981
1982 for (i = 0; i < sURLVariables.length; i++) {
1983 sParameterName = sURLVariables[i].split('=')
1984
1985 if (sParameterName[0] === sParam) {
1986 return sParameterName[1] === undefined
1987 ? true
1988 : decodeURIComponent(sParameterName[1])
1989 }
1990 }
1991 }
1992
1993 /**
1994 * settings page tab nav
1995 *
1996 * @since 1.0.0
1997 */
1998 $('.wpfn-settings__nav .nav-li:not(.disabled)').on('click', function (e) {
1999 var dataID = $(this).attr('data-id');
2000
2001 $(this).addClass('active').siblings('.nav-li').removeClass('active');
2002
2003 // Show the selected panel, hide others
2004 $('#' + dataID).show().siblings('.wpfnl-funnel__single-settings').hide();
2005
2006 // Inside the visible panel, activate the first inner-tab
2007 var $container = $('#' + dataID);
2008 $container.find('.inner-tab').removeClass('active');
2009 $container.find('.wpfnl-tab-content').removeClass('active');
2010
2011 var $firstInnerTab = $container.find('.inner-tab').first();
2012 var tabId = $firstInnerTab.data('tab');
2013
2014 $firstInnerTab.addClass('active');
2015 $('#' + tabId).addClass('active');
2016 });
2017
2018
2019 /**
2020 * Checkout Edit Field delete alert modal
2021 *
2022 * @since 1.0.0
2023 */
2024 $(document).on('click', '.delete-checkout-field', function () {
2025 $(this)
2026 .parents('.checkout__single-field')
2027 .find('.wpfnl-delete-alert-wrapper')
2028 .css('display', 'flex')
2029 })
2030
2031 $(document).on('click', '.wpfnl-delete-confirm-btn .cancel', function () {
2032 $(this).parents('.wpfnl-delete-alert-wrapper').hide()
2033 })
2034
2035 /**
2036 * edit-field settings tab
2037 *
2038 * @since 1.0.0
2039 */
2040 $('.edit-field-settings__single-tab-content:first-child').show()
2041
2042 $(document).on('click', '.edit-field-settings__tab-nav a', function (e) {
2043 e.preventDefault()
2044 var dataID = $(this).attr('href')
2045 $(this).parent('li').addClass('active').siblings().removeClass('active')
2046 $(this).parents('.checkout-edit-field-tab__content-wrapper').find(dataID).show()
2047 $(this).parents('.checkout-edit-field-tab__content-wrapper').find(dataID).siblings().hide()
2048 })
2049
2050 /**
2051 * add new checkout field drawer
2052 *
2053 * @since 1.0.0
2054 */
2055 $('.add-new-checkout-field-btn').on('click', function (e) {
2056 e.preventDefault()
2057 $(this)
2058 .parents('.checkout-edit-field-tab__content-wrapper')
2059 .find('.add-checkout-field-wrapper')
2060 .addClass('show-drawer')
2061 })
2062
2063 $('.add-checkout-field-close').on('click', function (e) {
2064 e.preventDefault()
2065 $(this).parents('.add-checkout-field-wrapper').removeClass('show-drawer')
2066 })
2067
2068 /**
2069 * edit checkout field drawer
2070 *
2071 * @since 1.0.0
2072 */
2073 // $('button.edit-field').on('click', function(e) {
2074 $(document).on('click', 'button.edit-field', function (e) {
2075 e.preventDefault()
2076 $(this)
2077 .parents('.checkout-edit-field-tab__content-wrapper')
2078 .find('.edit-checkout-field-wrapper')
2079 .addClass('show-drawer')
2080 })
2081
2082 $('.add-checkout-field-close').on('click', function (e) {
2083 e.preventDefault()
2084 $(this).parents('.edit-checkout-field-wrapper').removeClass('show-drawer')
2085 })
2086
2087 /**
2088 * show edit field type options
2089 *
2090 * @since 1.0.0
2091 */
2092 $('.wpfnl-edit-field-type').on('change', function (e) {
2093 e.preventDefault()
2094 var thisVal = $(this).val()
2095
2096 if (thisVal == 'select') {
2097 $(this).parents('.field-body').find('.field-type-options').show()
2098 } else {
2099 $(this).parents('.field-body').find('.field-type-options').hide()
2100 }
2101 })
2102
2103 jQuery(document).ready(function () {
2104 var selectedType = $('.wpfnl-edit-field-type').val()
2105
2106 if (selectedType == 'select') {
2107 $('.wpfnl-edit-field-type').parents('.field-body').find('.field-type-options').show()
2108 } else {
2109 $('.wpfnl-edit-field-type').parents('.field-body').find('.field-type-options').hide()
2110 }
2111 })
2112
2113 /**
2114 * Step preview permalink copy to clipboard
2115 *
2116 * @since 2.2.5
2117 */
2118 $(document).on('click', '.steps-url-slug .copy-slug-url', function (e) {
2119 e.preventDefault()
2120 $(this).addClass('copy-confirmed')
2121 var $temp = $('<input>')
2122 $(this).parents('.field-group').append($temp)
2123 $temp.val($(this).parents('.field-group').find('#step-preview-link').val()).select()
2124 document.execCommand('copy')
2125 $temp.remove()
2126
2127 setTimeout(function () {
2128 $('.steps-url-slug .copy-slug-url').removeClass('copy-confirmed')
2129 }, 1000)
2130 })
2131
2132 $(document).on('keyup change input', '.wpfnl-set-quantity-limit', function (e) {
2133 // Get the input value
2134 var inputValue = $(this).val()
2135
2136 // If input is blank, default it to 1
2137 if (isNaN(inputValue)) {
2138 inputValue = '1'
2139 }
2140 // Remove any non-numeric characters except '.'
2141 inputValue = inputValue.replace(/[^0-9.]/g, '')
2142
2143 // Split the value into integer and decimal parts
2144 var parts = inputValue.split('.')
2145
2146 // If there are more than one decimal point, consider only the first part
2147 if (parts.length > 2) {
2148 inputValue = parts[0] + '.' + parts.slice(1).join('')
2149 }
2150
2151 // Parse the value into an integer
2152 var quantity = parseInt(inputValue)
2153 // Set the input value to the parsed integer
2154 $(this).val(quantity)
2155
2156 if (quantity < 1) {
2157 $(this).val(1)
2158 }
2159 })
2160
2161 $(document).on('blur', '.wpfnl-set-quantity-limit', function (e) {
2162 var inputValue = $(this).val()
2163 if (inputValue.trim() === '') {
2164 $(this).val('1')
2165 }
2166 })
2167
2168 /**
2169 * AB testing permalink copy to clipboard
2170 *
2171 * @since 3.1.0
2172 */
2173 $(document).on('click', '.copy-ab-url', function (e) {
2174 e.preventDefault()
2175 $(this).addClass('copy-confirmed')
2176 var $temp = $('<input>')
2177 $(this).parents('.header-right').append($temp)
2178 $temp.val($(this).parents('.header-right').find('#ab-testing-link').val()).select()
2179 document.execCommand('copy')
2180 $temp.remove()
2181
2182 setTimeout(function () {
2183 $('.copy-ab-url').removeClass('copy-confirmed')
2184 }, 1000)
2185 })
2186
2187 /**
2188 * rollback feature for WPF
2189 */
2190 $('select#wpfnl-rollback')
2191 .on('change', function () {
2192 var $this = $(this),
2193 $rollbackButton = $this.next('.wpfnl-rollback-button'),
2194 originalHref = $rollbackButton.attr('href'),
2195 selectedVersion = $this.val();
2196
2197 if (originalHref && originalHref.includes('VERSION')) {
2198 var updatedHref = originalHref.replace('VERSION', selectedVersion);
2199 $rollbackButton.attr('href', updatedHref);
2200 }
2201 })
2202 .trigger('change');
2203
2204
2205 $('.wpfnl-rollback-button').on('click', function (event) {
2206 event.preventDefault()
2207 var $this = $(this)
2208 if (confirm('Are you sure?')) {
2209 $this.addClass('show-loader')
2210 $this.addClass('loading')
2211 location.href = $this.attr('href')
2212 }
2213 })
2214
2215 // ---delete promotional-banner notice permanently ------
2216 $(document).on('click', '.gwpf-promotional-notice .close-promotional-banner', function (event) {
2217 event.preventDefault()
2218 $('.gwpf-promotional-notice').attr('style', 'display: none !important');
2219 wpAjaxHelperRequest('delete_promotional_banner')
2220 })
2221
2222 $(document).on('click', '.wpfnl-notification-counter__btn-area', function (event) {
2223 event.preventDefault()
2224 $('.gwpf-promotional-notice').attr('style', 'display: none !important');
2225 wpAjaxHelperRequest('delete_promotional_banner')
2226 })
2227
2228 // ---delete new UI notice permanently ------
2229 $(document).on('click', '.wpfunnels-newui-notice .close-newui-notice', function (event) {
2230 event.preventDefault()
2231 $('.wpfunnels-newui-notice.notice').css('display', 'none')
2232 wpAjaxHelperRequest('delete_new_ui_notice')
2233 })
2234
2235 /**
2236 * Multiple Orderbump Accordion
2237 *
2238 */
2239 $(document).on(
2240 'click',
2241 '.single-order-bump .order-bump-accordion-header .title-area',
2242 function (e) {
2243 e.preventDefault()
2244 $(this).parents('.single-order-bump').siblings().removeClass('expanded-orderbump')
2245 $(this).parents('.single-order-bump').toggleClass('expanded-orderbump')
2246
2247 $(this)
2248 .parents('.single-order-bump')
2249 .siblings()
2250 .find('.order-bump-accordion-content')
2251 .removeClass('show-content')
2252 $(this)
2253 .parents('.single-order-bump')
2254 .find('.order-bump-accordion-content')
2255 .toggleClass('show-content')
2256 },
2257 )
2258
2259 $(document).ready(function () {
2260 const $stickyElement = $('.wpfnl-pvf-table-header');
2261 if($stickyElement.length === 0) return;
2262 const stickyOffset = $stickyElement.offset().top;
2263
2264 $(window).on('scroll', function () {
2265 const scrollTop = $(this).scrollTop();
2266 if (scrollTop >= stickyOffset - 44) {
2267 $stickyElement.addClass('is-sticky');
2268 } else {
2269 $stickyElement.removeClass('is-sticky');
2270 }
2271 });
2272 });
2273
2274
2275 //------expand last orderbump when added a new orderbump----
2276 $(document).on('click', '.order-bump-header .add-new-orderbump', function (e) {
2277 e.preventDefault()
2278 $('.single-order-bump').siblings().removeClass('expanded-orderbump')
2279 $('.single-order-bump:last-child').addClass('expanded-orderbump')
2280
2281 $('.single-order-bump')
2282 .siblings()
2283 .find('.order-bump-accordion-content')
2284 .removeClass('show-content')
2285 $('.single-order-bump:last-child')
2286 .find('.order-bump-accordion-content')
2287 .addClass('show-content')
2288 })
2289
2290 /**
2291 * Automatic winner choose condition dropdown
2292 *
2293 */
2294 $(document).on('click', '.automatic-winner .set-condition .selected-item', function (e) {
2295 e.preventDefault()
2296 e.stopPropagation()
2297 $(this).parents('.wpfnl-selectbox').find('.selectable-option').slideToggle(300)
2298 })
2299 $(document).on('click', 'body', function () {
2300 $('.automatic-winner .set-condition .selectable-option').hide()
2301 })
2302
2303 $(document).on('click', '.automatic-winner .set-condition .selectable-option li', function (e) {
2304 e.preventDefault()
2305 var selected_item_text = $(this).text()
2306 var selected_item_data = $(this).attr('data-value')
2307
2308 $(this).siblings().removeClass('active')
2309 $(this).addClass('active')
2310 $('.automatic-winner .set-condition .selected-item')
2311 .text(selected_item_text)
2312 .attr('data-value', selected_item_data)
2313 })
2314
2315 /**
2316 * Show step control button when clik on step (on drawflow window page)
2317 *
2318 */
2319 $(document).on('click', '.drawflow .drawflow-node .single-node', function (e) {
2320 e.stopPropagation()
2321 $(this)
2322 .parents('.parent-node')
2323 .siblings()
2324 .find('.single-node')
2325 .removeClass('im-selected-node')
2326 $(this).siblings().removeClass('im-selected-node')
2327 $(this)
2328 .parent('.single-node-wrapper')
2329 .siblings()
2330 .find('.single-node')
2331 .removeClass('im-selected-node')
2332 $(this).addClass('im-selected-node')
2333 })
2334
2335 $(document).on('click', 'body', function () {
2336 $('.drawflow .drawflow-node .single-node').removeClass('im-selected-node')
2337 })
2338
2339 /**
2340 * Add list, add tag dropdown show/hide
2341 *
2342 */
2343 $(document).on('click', '.wpfnl-custom-selectbox .selectbox-selected-value', function (e) {
2344 e.stopPropagation()
2345 $(this).parents('.wpfnl-custom-selectbox').toggleClass('show-options')
2346 })
2347
2348 $(document).on('click', '.wpfnl-custom-selectbox .selectbox-options', function (e) {
2349 e.stopPropagation()
2350 })
2351
2352 $(document).on('click', 'body', function () {
2353 $('.wpfnl-custom-selectbox').removeClass('show-options')
2354 })
2355
2356 /**
2357 * Funnel Bulk select action dropdown
2358 *
2359 */
2360 $(document).on('click', '.bulk-delete-toggler', function (e) {
2361 e.stopPropagation()
2362 $(this).toggleClass('show-dropdown')
2363 })
2364
2365 $(document).on('click', '.wpfnl-dropdown', function (e) {
2366 e.stopPropagation()
2367 })
2368
2369 $(document).on('click', 'body', function () {
2370 $('.bulk-delete-toggler').removeClass('show-dropdown')
2371 })
2372
2373 $(document).on('change', 'select#wpfnl_listing_page_offset', updateFunnelListingPageOffset)
2374 function updateFunnelListingPageOffset() {
2375 const offset = $(this).find('option:selected').val()
2376 const queryParams = new URLSearchParams(window.location.search)
2377
2378 // Set new or modify existing parameter value.
2379 queryParams.set('pageno', '1')
2380 queryParams.set('per_page', offset)
2381 // Replace current querystring with the new one.
2382 history.replaceState(null, null, '?' + queryParams.toString())
2383 location.reload()
2384 }
2385
2386 function selectedFunnelIds(params) {
2387 let ids = []
2388 if (params.length > 0) {
2389 for (let key = 0; key < params.length; key++) {
2390 const inputItem = params[key]?.id
2391 const id = inputItem.match(/\d+/)[0]
2392 ids.push(parseInt(id))
2393 }
2394 }
2395 selectedIds = ids
2396 }
2397
2398 /**
2399 * Funnel Bulk select checkbox on change event
2400 *
2401 */
2402 function selectedFunnelCounter() {
2403 let totalSelectedFunnel = $('input[name=funnel-list-select]:checked').length
2404
2405 selectedFunnelIds($('input[name=funnel-list-select]:checked'))
2406
2407 if (totalSelectedFunnel > 0) {
2408 $('.funnel__single-list.list-header .bulk-action-wrapper').css('display', 'flex')
2409 } else {
2410 $('.funnel__single-list.list-header .bulk-action-wrapper').css('display', 'none')
2411 }
2412
2413 if (totalSelectedFunnel > 1) {
2414 $('.funnel__single-list.list-header .bulk-action-wrapper .selected-funnel-count').text(
2415 totalSelectedFunnel + ' Funnels',
2416 )
2417 } else {
2418 $('.funnel__single-list.list-header .bulk-action-wrapper .selected-funnel-count').text(
2419 totalSelectedFunnel + ' Funnel',
2420 )
2421 }
2422 }
2423
2424 $('.funnel__single-list.list-body input[name=funnel-list-select]').on('change', function () {
2425 $('.funnel-list__bulk-select.select-all-funnels input[name=funnel-list__bulk-select]').prop(
2426 'checked',
2427 false,
2428 )
2429 selectedFunnelCounter()
2430 })
2431
2432 $('.funnel-list__bulk-select.select-all-funnels input[name=funnel-list__bulk-select]').on(
2433 'change',
2434 function () {
2435 if ($(this).is(':checked')) {
2436 $('.funnel__single-list.list-body input[name=funnel-list-select]').prop(
2437 'checked',
2438 true,
2439 )
2440 selectedFunnelCounter()
2441 } else {
2442 $('.funnel__single-list.list-header .bulk-action-wrapper').css('display', 'none')
2443 $('.funnel__single-list.list-body input[name=funnel-list-select]').prop(
2444 'checked',
2445 false,
2446 )
2447 }
2448 },
2449 )
2450
2451 /**
2452 * Funnel window page and Empty funnel page help resource show/hide.
2453 *
2454 */
2455 $(document).on('click', '.wpfnl-helper-btn', function (e) {
2456 e.stopPropagation()
2457 $(this).parent('.wpfnl-canvas-helper').toggleClass('show-helpers')
2458 })
2459
2460 $(document).on('click', 'body', function () {
2461 $('.wpfnl-canvas-helper').removeClass('show-helpers')
2462 })
2463
2464 /**
2465 * add new step option dropdown show/hide.
2466 *
2467 */
2468 $(document).on('click', '.addstep .add-step-wrapper .icon', function (e) {
2469 e.stopPropagation()
2470 $(this).parent('.add-step-wrapper').toggleClass('show-options')
2471 })
2472
2473 $(document).on('click', '.option-duplicate', function (e) {
2474 e.stopPropagation()
2475 })
2476
2477 $(document).on('click', 'body', function () {
2478 $('.addstep .add-step-wrapper').removeClass('show-options')
2479 })
2480
2481 /**
2482 * Showmore option hide/show
2483 * Three dot more option hide/show.
2484 *
2485 */
2486 $(document).on('click', '.on-showmore-options', function (e) {
2487 e.stopPropagation()
2488 $(this).toggleClass('show-dropdown')
2489 })
2490 $(document).on('click', 'body', function () {
2491 $('.on-showmore-options').removeClass('show-dropdown')
2492 })
2493
2494 /*----mailmint actions dropdown------ */
2495 $(document).on('click', '.mailmint-automation .add-action > button', function (e) {
2496 e.stopPropagation()
2497
2498 $(this).parents('.logical-decision-box').siblings('.add-action').removeClass('show-actions')
2499 $(this).parents('.single-decision').find('.add-action').removeClass('show-actions')
2500 $(this)
2501 .parents('.single-decision')
2502 .siblings()
2503 .find('.add-action')
2504 .removeClass('show-actions')
2505
2506 $(this)
2507 .parents('.automation-single-step')
2508 .siblings()
2509 .find('.add-action')
2510 .removeClass('show-actions')
2511
2512 $(this).parents('.add-action').toggleClass('show-actions')
2513 })
2514
2515 $(document).on('click', '.mailmint-automation .mailmint-actions', function (e) {
2516 e.stopPropagation()
2517 })
2518
2519 $(document).on('click', 'body, .mailmint-single-action, .automation-start-point', function (e) {
2520 $('.mailmint-automation .add-action').removeClass('show-actions')
2521 })
2522
2523 //----when click first-action plus (+) button------
2524 $(document).on('click', '.mailmint-automation .add-action.first-action > button', function (e) {
2525 $('.automation-single-step .add-action').removeClass('show-actions')
2526 })
2527
2528 //----when click automation-single-step's plus (+) button------
2529 $(document).on('click', '.automation-single-step .add-action > button', function (e) {
2530 $('.selected-trigger .add-action').removeClass('show-actions')
2531 //$('.logical-decision-box .add-action').removeClass('show-actions');
2532 })
2533
2534 //--------select box placeholder color and active color--------
2535 $(document).on('change', 'select.has-placeholder-color', function () {
2536 var thisVal = $(this).find(':selected').val()
2537 if ('' != thisVal) {
2538 $(this).addClass('value-selected')
2539 } else {
2540 $(this).removeClass('value-selected')
2541 }
2542 })
2543
2544 $(document).on('click', '.add-new-webhook', function () {
2545 $('select.has-placeholder-color').removeClass('value-selected')
2546 })
2547
2548 /*----A|B testing modal header's more option's dropdown show/hide------ */
2549 $(document).on('click', '.ab-testing-drawer .header-right .more-options', function (e) {
2550 e.stopPropagation()
2551 $(this).toggleClass('show-options')
2552 })
2553
2554 $(document).on('click', 'body', function () {
2555 $('.ab-testing-drawer .header-right .more-options').removeClass('show-options')
2556 })
2557
2558 /*----A|B testing variations steps more option's dropdown show/hide------ */
2559 $(document).on('click', '.single-ab-step .more-option > button', function (e) {
2560 e.stopPropagation()
2561 $(this)
2562 .parents('.single-ab-step')
2563 .siblings()
2564 .find('.more-option')
2565 .removeClass('show-dorpdown')
2566 $(this).parents('li.more-option').toggleClass('show-dorpdown')
2567 })
2568
2569 $(document).on('click', '.single-ab-step .more-option .options-dropdown', function (e) {
2570 e.stopPropagation()
2571 })
2572
2573 $(document).on('click', 'body', function () {
2574 $('.ab-testing-drawer .single-ab-step li.more-option').removeClass('show-dorpdown')
2575 })
2576
2577 /**
2578 * wpfnl custom selectbox dropdown option hide/show
2579 *
2580 */
2581 $(document).on('click', '.wpfnl-selectbox .selected-option', function (e) {
2582 e.stopPropagation()
2583
2584 $(this)
2585 .parents('.single-rules')
2586 .siblings()
2587 .find('.wpfnl-selectbox')
2588 .removeClass('show-options')
2589 $(this).parents('.rules').siblings().find('.wpfnl-selectbox').removeClass('show-options')
2590
2591 $(this)
2592 .parents('.condition-single-row')
2593 .siblings()
2594 .find('.wpfnl-selectbox')
2595 .removeClass('show-options')
2596 $(this)
2597 .parents('.single-condition')
2598 .siblings()
2599 .find('.wpfnl-selectbox')
2600 .removeClass('show-options')
2601
2602 $(this).parent('.wpfnl-selectbox').toggleClass('show-options')
2603 })
2604 $(document).on('click', 'body', function () {
2605 $('.wpfnl-selectbox').removeClass('show-options')
2606 })
2607
2608 /**
2609 * wpfnl custom selectbox sub dropdown option hide/show
2610 *
2611 */
2612 $(document).on('click', '.single-rules .selectable-options > li', function (e) {
2613 e.stopPropagation()
2614
2615 $(this)
2616 .parents('.single-rules')
2617 .siblings()
2618 .find('.selectable-options > li')
2619 .removeClass('show-options')
2620 $(this)
2621 .parents('.rules')
2622 .siblings()
2623 .find('.selectable-options > li')
2624 .removeClass('show-options')
2625 $(this).siblings().removeClass('show-options')
2626
2627 $(this).toggleClass('show-options')
2628 })
2629 $(document).on('click', 'body', function () {
2630 $('.single-rules .wpfnl-selectbox').removeClass('show-options')
2631 $('.single-rules .selectable-options > li').removeClass('show-options')
2632 })
2633
2634 $(document).on(
2635 'click',
2636 '.single-rules .submenu > li, .rules-is .selectable-options > li',
2637 function () {
2638 $('.single-rules .wpfnl-selectbox').removeClass('show-options')
2639 },
2640 )
2641
2642 //---------------------------
2643 $(document).on('click', '.single-rules .selected-option', function (e) {
2644 $('.single-rules .wpfnl-custom-selectbox').removeClass('show-options')
2645 })
2646
2647 $(document).on('click', '.wpfnl-custom-selectbox .selectbox-selected-value', function (e) {
2648 $('.single-rules .wpfnl-selectbox ').removeClass('show-options')
2649 $(this)
2650 .parents('.single-rules')
2651 .siblings()
2652 .find('.wpfnl-custom-selectbox')
2653 .removeClass('show-options')
2654 })
2655
2656 // ------------------ Pro Modal Open and Close ---------------------- //
2657
2658 // close modal starts
2659 $(document).on('click', '#wpfnl-pro-modal-close', function (e) {
2660 const html = '<strong>Small</strong> <span>License for 1 site</span>';
2661 $('#pro-modal-package-type').html(html)
2662 $('.wpfnl-footer-btn-wrapper .btn-default.confirmed').attr('href', 'https://useraccount.getwpfunnels.com/wpf-small-annual-brand-new/steps/wpf-sa-checkout/');
2663 $('#wpfnl-pro-modal').hide()
2664 })
2665
2666 $(document).on('click', '#wpfnl-pro-modal-close-btn', function (e) {
2667 const html = '<strong>Small</strong> <span>License for 1 site</span>';
2668 $('#pro-modal-package-type').html(html)
2669 $('.wpfnl-footer-btn-wrapper .btn-default.confirmed').attr('href', 'https://useraccount.getwpfunnels.com/wpf-small-annual-brand-new/steps/wpf-sa-checkout/');
2670 $('#wpfnl-pro-modal').hide()
2671 })
2672 // close modal ends
2673
2674 /* Configure the pro modal
2675 * config[object] - parameter
2676 * showSubHeading - boolean
2677 * subHeading - string
2678 * confirmLink - string
2679 * features - Array of Object
2680 * label - String
2681 * value - String
2682 */
2683 const configureProModal = (config) => {
2684 const { showSubHeading, subHeading, confirmLink, features } = config
2685
2686 // Define Ratings and Users
2687 const ratings = 105
2688 const users = 8000
2689
2690 // Define Elements
2691 const modalElement = document.querySelector('#wpfnl-pro-modal')
2692 const subHeadingElement = document.querySelector('#wpfnl-pro-modal .wpfnl-pro-sub-heading')
2693 const confirmBtnElement = document.querySelector('#wpfnl-pro-modal .btn-default.confirmed')
2694 const modalBodyElement = document.querySelector('#wpfnl-pro-modal .wpfnl-pro-modal-body')
2695 const featureFirstColElement = document.querySelector(
2696 '#wpfnl-pro-modal .wpfnl-pro-modal-body .wpfnl-pro-features.first-col',
2697 )
2698 const featureSecondColElement = document.querySelector(
2699 '#wpfnl-pro-modal .wpfnl-pro-modal-body .wpfnl-pro-features.second-col',
2700 )
2701 const footerTextElement = document.querySelector(
2702 '#wpfnl-pro-modal .wpfnl-pro-modal-footer-text span',
2703 )
2704
2705 // Tic Icon for Features
2706 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>`
2707
2708 // Show or hide subheading
2709 if (showSubHeading) {
2710 subHeadingElement.innerHTML = subHeading
2711 } else {
2712 modalElement.removeChild(subHeadingElement)
2713 }
2714
2715 // confirm link setting
2716 if (confirmLink) {
2717 confirmBtnElement.setAttribute('href', confirmLink)
2718 } else {
2719 confirmBtnElement.setAttribute('href', 'https://useraccount.getwpfunnels.com/wpf-small-annual-brand-new/steps/wpf-sa-checkout/')
2720 }
2721
2722 // features setting
2723 if (Array.isArray(features) && features?.length > 0) {
2724 let middle = Math.ceil(features.length / 2)
2725 featureFirstColElement.innerHTML = ''
2726 featureSecondColElement.innerHTML = ''
2727
2728 features.forEach((feature, index) => {
2729 if (index < middle) {
2730 featureFirstColElement.innerHTML += `<li>${ticIcon}<span>${feature.label}</span></li>`
2731 } else {
2732 featureSecondColElement.innerHTML += `<li>${ticIcon}<span>${feature.label}</span></li>`
2733 }
2734 })
2735 } else {
2736 modalElement.removeChild(modalBodyElement)
2737 }
2738
2739 // Set Footer Text
2740 if (footerTextElement)
2741 footerTextElement.innerHTML = `Easiest Funnel Builder: <strong>${users}+</strong> Users, <strong>${ratings}+</strong> Five-Star Reviews</strong>`
2742 }
2743
2744 // modal Open function
2745 const openModal = (config) => {
2746 // configureProModal(config)
2747 $('#wpfnl-pro-modal').css('display', 'flex')
2748 }
2749 // open modal starts
2750 $(document).on('click', '#wpfnl-export-all-pro', function (e) {
2751 const config = {
2752 showSubHeading: true,
2753 subHeading: 'Upgrade to Export Funnels.',
2754 confirmLink: 'https://useraccount.getwpfunnels.com/wpf-small-annual-brand-new/steps/wpf-sa-checkout/',
2755 features: [
2756 {
2757 label: 'Export Funnels',
2758 value: 'export_funnels',
2759 },
2760 {
2761 label: 'Download Funnel as JSON',
2762 value: 'download_funnel_as_json',
2763 },
2764 {
2765 label: 'Export Single Funnel',
2766 value: 'export_single_funnels',
2767 },
2768 {
2769 label: 'Bulk Export',
2770 value: 'bulk_export',
2771 },
2772 ],
2773 }
2774 openModal(config)
2775 })
2776
2777 $(document).on('click', '#wpfnl-import-funnels-pro, .pro-import-button', function (e) {
2778 const config = {
2779 showSubHeading: true,
2780 subHeading: 'Upgrade to Import Funnels.',
2781 confirmLink: 'https://useraccount.getwpfunnels.com/wpf-small-annual-brand-new/steps/wpf-sa-checkout/',
2782 features: [
2783
2784 {
2785 label: 'Import JSON File',
2786 value: 'import_json_to_create_funnel',
2787 },
2788 {
2789 label: 'Import Funnels',
2790 value: 'import_funnels',
2791 },
2792 {
2793 label: 'Bulk Import',
2794 value: 'bulk_import_funnels',
2795 },
2796 ],
2797 }
2798 openModal(config)
2799 })
2800
2801 $(document).on('click', '#wpfnl-offer-settings', function (e) {
2802 const config = {
2803 showSubHeading: true,
2804 subHeading: 'Upgrade to Unlock Offer Settings.',
2805 confirmLink: 'https://useraccount.getwpfunnels.com/wpf-small-annual-brand-new/steps/wpf-sa-checkout/',
2806 features: [
2807 {
2808 label: 'Create Child Order',
2809 value: 'create_child_order',
2810 },
2811 {
2812 label: 'Show Supported Payment Gateway',
2813 value: 'show_supported_payment_gateway',
2814 },
2815 {
2816 label: 'Skip Offer',
2817 value: 'skip_offer',
2818 },
2819 ],
2820 }
2821 openModal(config)
2822 })
2823
2824 $('.duplicate.wpfnl-export-funnel-pro').on('click', function (e) {
2825 const config = {
2826 showSubHeading: true,
2827 subHeading: 'Upgrade to Export Funnels.',
2828 confirmLink: 'https://useraccount.getwpfunnels.com/wpf-small-annual-brand-new/steps/wpf-sa-checkout/',
2829 features: [
2830 {
2831 label: 'Export Funnels',
2832 value: 'export_funnels',
2833 },
2834 {
2835 label: 'Download Funnel as JSON',
2836 value: 'download_funnel_as_json',
2837 },
2838 {
2839 label: 'Export Single Funnel',
2840 value: 'export_single_funnels',
2841 },
2842 {
2843 label: 'Bulk Export',
2844 value: 'bulk_export',
2845 },
2846 ],
2847 }
2848 openModal(config)
2849 })
2850
2851 $('#facebook-pixel-enable-pro').on('click', function (e) {
2852 const config = {
2853 showSubHeading: true,
2854 subHeading:
2855 'This feature is only available in the Pro version. Upgrade Now to continue all these awesome features',
2856 confirmLink: 'https://useraccount.getwpfunnels.com/wpf-small-annual-brand-new/steps/wpf-sa-checkout/',
2857 features: [
2858 {
2859 label: 'Unlimited Contacts k',
2860 value: 'unlimited_contacts',
2861 },
2862 {
2863 label: 'Conditional Prancing k',
2864 value: 'conditional_prancing',
2865 },
2866 {
2867 label: '360 Contacts view',
2868 value: '360_contacts_view',
2869 },
2870 {
2871 label: 'Connect with From Plugins',
2872 value: 'Connect_with_From_Plugins',
2873 },
2874 {
2875 label: 'Over 60+ Integrations',
2876 value: 'Over_60+_Integrations',
2877 },
2878 ],
2879 }
2880 openModal(config)
2881 })
2882
2883 $(document).on('click', '#facebook-pixel-enable-pro', function (e) {
2884 e.preventDefault()
2885 e.target.checked = false
2886 const config = {
2887 showSubHeading: true,
2888 subHeading: 'Upgrade to Pro for FB Pixel Tracking.',
2889 confirmLink: 'https://useraccount.getwpfunnels.com/wpf-small-annual-brand-new/steps/wpf-sa-checkout/',
2890 features: [
2891 {
2892 label: 'FB Pixel Tracking',
2893 value: 'fb_pixel_tracking',
2894 },
2895 {
2896 label: 'Enable/Disable for Single Funnel',
2897 value: 'enable_disable_single_funnel',
2898 },
2899 {
2900 label: 'Purchase Event Tracking',
2901 value: 'purchase_event_tracking',
2902 },
2903 {
2904 label: 'Page View Tracking',
2905 value: 'page_view_tracking',
2906 },
2907 {
2908 label: 'Add to Cart Tracking',
2909 value: 'add_to_cart_tracking',
2910 },
2911 {
2912 label: 'Upsell/Downsell Tracking',
2913 value: 'offer_tracking',
2914 },
2915 ],
2916 }
2917 openModal(config)
2918 })
2919
2920 $(document).on('click', '#gtm-enable-pro', function (e) {
2921 e.preventDefault()
2922 e.target.checked = false
2923 const config = {
2924 showSubHeading: true,
2925 subHeading: 'Upgrade to Pro for GTM Tracking.',
2926 confirmLink: 'https://useraccount.getwpfunnels.com/wpf-small-annual-brand-new/steps/wpf-sa-checkout/',
2927 features: [
2928 {
2929 label: 'GTM Tracking',
2930 value: 'gtm_tracking',
2931 },
2932 {
2933 label: 'Enable/Disable for Single Funnel',
2934 value: 'enable_disable_single_funnel',
2935 },
2936 {
2937 label: 'Purchase Event Tracking',
2938 value: 'purchase_event_tracking',
2939 },
2940 {
2941 label: 'Page View Tracking',
2942 value: 'page_view_tracking',
2943 },
2944 {
2945 label: 'Add to Cart Tracking',
2946 value: 'add_to_cart_tracking',
2947 },
2948 {
2949 label: 'Shipping Info Tracking',
2950 value: 'shipping_tracking',
2951 },
2952 {
2953 label: 'OrderBump Tracking',
2954 value: 'orderbump_tracking',
2955 },
2956 {
2957 label: 'Upsell/Downsell Tracking',
2958 value: 'offer_tracking',
2959 },
2960 ],
2961 }
2962 openModal(config)
2963 })
2964
2965 // open modal ends
2966
2967 // Close Toaster
2968 $(document).on('click', '#wpfnl-toaster-close-btn', function (e) {
2969 $('#wpfnl-toaster-wrapper').hide()
2970 })
2971
2972 // Pro modal
2973 $(document).on('click', '#pro-modal-dropdown-btn', function () {
2974 $('#pro-modal-dropdown-body').toggleClass('show-dropdown')
2975 $('#pro-modal-dropdown-btn').toggleClass('btn-rotate')
2976 })
2977
2978 $(document).on('click', '.wpfnl-pro-modal-dropdown li', function () {
2979 const selectedValue = $(this).attr('value')
2980 const url = $(this).data('url')
2981 const selectedHTML = $(this).html()
2982
2983 $('#pro-modal-package-type').html(selectedHTML)
2984 $('#pro-modal-package-price').html(`<strong>$ ${selectedValue}</strong> <span>/year</span>`)
2985 $('.wpfnl-footer-btn-wrapper .btn-default.confirmed').attr('href', url);
2986 $('#pro-modal-dropdown-body').toggleClass('show-dropdown')
2987 $('#pro-modal-dropdown-btn').toggleClass('btn-rotate')
2988 })
2989
2990
2991 // no funnels screen video popup
2992 $(document).on('click', '.no-funnel-play-button', function () {
2993 const $popup = $('#no-funnel-video-popup');
2994 const $iframe = $('#no-funnel-video-iframe');
2995 const videoSrc = $iframe.data('src');
2996
2997 // Set the iframe src to start video with autoplay
2998 if (videoSrc && !$iframe.attr('src')) {
2999 $iframe.attr('src', videoSrc);
3000 }
3001
3002 $popup.addClass('show');
3003 $('body').css('overflow', 'hidden');
3004 })
3005
3006 $(document).on('click', '#no-funnel-video-popup .video-popup-close, #no-funnel-video-popup', function (e) {
3007 // Only close if clicking the close button or overlay (not the content)
3008 if ($(e.target).is('#no-funnel-video-popup') || $(e.target).closest('.video-popup-close').length) {
3009 const $popup = $('#no-funnel-video-popup');
3010 const $iframe = $('#no-funnel-video-iframe');
3011
3012 // Remove src to stop the video
3013 $iframe.attr('src', '');
3014
3015 $popup.removeClass('show');
3016 $('body').css('overflow', '');
3017 }
3018 })
3019
3020 })(jQuery)
3021