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

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