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

2,118 lines 76.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 /**
8 * All of the code for your admin-facing JavaScript source
9 * should reside in this file.
10 *
11 * Note: It has been assumed you will write jQuery code here, so the
12 * $ function reference has been prepared for usage within the scope
13 * of this function.
14 *
15 * This enables you to define handlers, for when the DOM is ready:
16 *
17 * $(function() {
18 *
19 * });
20 *
21 * When the window is loaded:
22 *
23 * $( window ).load(function() {
24 *
25 * });
26 *
27 * ...and/or other possibilities.
28 *
29 * Ideally, it is not considered best practise to attach more than a
30 * single DOM-ready or window-load handler for a particular page.
31 * Although scripts in the WordPress core, Plugins and Themes may be
32 * practising this, we should strive to set a better example in our own work.
33 */
34
35
36 jQuery(document).ready(function($) {
37 //date format
38 function PresentDateForm(date){
39 var date = new Date(date),
40 day = date.getDate(),
41 month = date.getMonth() + 1, //Months are zero based
42 year = date.getFullYear(),
43 date = new Date(year+'-'+month+'-'+day).toDateString();
44 return date;
45
46 }
47
48 function CompareDateForm(date){
49 var date = new Date(date),
50 day = date.getDate(),
51 month = date.getMonth() + 1, //Months are zero based
52 year = date.getFullYear()-1,
53 date = new Date(year+'-'+month+'-'+day).toDateString();
54 return date;
55 }
56
57 // -------analytics line chart filter-------
58 function wpfnlDatePicker() {
59 $(".wpfunnel-datepicker").datepicker({
60 maxDate: 0,
61 changeMonth: true,
62 changeYear: true,
63 showOtherMonths: true,
64 selectOtherMonths: true,
65 beforeShowDay: function(date) {
66 let date1 = $.datepicker.parseDate($.datepicker._defaults.dateFormat, $("#date_from_value").val());
67 let date2 = $.datepicker.parseDate($.datepicker._defaults.dateFormat, $("#date_to_value").val());
68
69 let isStartDate = date1 && date.getTime() === date1.getTime();
70 let isEndDate = date2 && date.getTime() === date2.getTime();
71
72 return [true, (isStartDate || (date2 && date >= date1 && date <= date2)) ? "in-range" : "", isStartDate ? 'Start' : (isEndDate ? 'End' : '')];
73
74 },
75 onSelect: function(dateText, inst) {
76 let date1 = $.datepicker.parseDate($.datepicker._defaults.dateFormat, $("#date_from_value").val());
77 let date2 = $.datepicker.parseDate($.datepicker._defaults.dateFormat, $("#date_to_value").val());
78 let selectedDate = $.datepicker.parseDate($.datepicker._defaults.dateFormat, dateText);
79 const months = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ];
80 const formattedDate = months[selectedDate.getMonth()] + ' ' + selectedDate.getDate() + ', ' + selectedDate.getFullYear();
81
82 if (!date1 || date2) {
83 $("#date-from").val(formattedDate);
84 $("#date_from_value").val(dateText);
85 $("li.select-from-date").text(dateText).css('color', '#2D3149');
86
87 $("#date-to").val("");
88 $("#date_to_value").val("");
89 $(this).datepicker();
90 $('.analytics-header .custom-date-range').show();
91
92 } else if (selectedDate < date1) {
93 $("#date-to").val($("#date-from").val());
94 $("#date_to_value").val($("#date_from_value").val());
95 $("#date-from").val(formattedDate);
96 $("#date_from_value").val(dateText);
97
98 $("li.select-to-date").text($("li.select-from-date").text()).css('color', '#2D3149');
99 $("li.select-from-date").text(dateText).css('color', '#2D3149');
100
101 $(this).datepicker();
102
103 } else {
104 $("#date-to").val(formattedDate);
105 $("#date_to_value").val(dateText);
106 $("li.select-to-date").text(dateText).css('color', '#2D3149');
107 $(this).datepicker();
108 $('.analytics-header .custom-date-range').show();
109 }
110 }
111 });
112
113 }
114
115
116 $(".wpfnl_muliple_select").select2();
117 // edit field error handle
118 $('.wpfnl-section-type-error').hide();
119 $('.wpfnl-field-type-error').hide();
120 $('.wpfnl-name-type-error').hide();
121 $('.wpfnl-label-type-error').hide();
122
123
124
125 //--------show calendar when select as custom filter----------
126 $(document).on("change", "#analytics-filter", function() {
127 let selectedValue = $(this).find(":selected").val();
128
129 if( 'custom' === selectedValue ){
130 var selectedDate = $("#date-from").val();
131 $('.wpfnl-analytics .overlay-click').show();
132 $('.analytics-header .custom-date-range').show()
133 $('.analytics-header .header-right').addClass('show-calendar');
134
135 }else{
136 $('.wpfnl-analytics .overlay-click').hide();
137
138 $('.analytics-header .header-right').removeClass('show-calendar');
139 $('.analytics-header .custom-date-range').hide();
140 }
141 });
142
143
144 //--------hide calendar when click on calender filter button----------
145 $(document).on("click", ".do-filter", function(e) {
146 $('.analytics-header .header-right').removeClass('show-calendar');
147 $('.wpfnl-analytics .overlay-click').hide();
148 });
149
150
151 //--------analytics calendar filter dropdown----------
152 $(document).on("click", ".filter-selectbox", function(e) {
153 e.stopPropagation();
154 $(this).parents('.header-right').toggleClass('show-calendar');
155 $('.wpfnl-analytics .overlay-click').show();
156 });
157 $(document).on("click", ".calendar-dorpdown", function(e) {
158 e.stopPropagation();
159 });
160 $(document).on("click", ".wpfnl-analytics .overlay-click", function() {
161 $(this).hide();
162 $('.analytics-header .header-right').removeClass('show-calendar');
163 });
164
165
166 //--------analytics filter header dropdown----------
167 $(document).on("click", ".funnel-steps > li", function(e) {
168 e.preventDefault();
169 e.stopPropagation();
170 $(this).addClass('active');
171 $(this).siblings('li').removeClass('active');
172 $(this).children('.wpfnl-dropdown').toggleClass('show-dropdown');
173 $(this).siblings('li').children('.wpfnl-dropdown').removeClass('show-dropdown');
174 });
175 $(document).on("click", "body", function() {
176 $('.chart-header .funnel-steps .wpfnl-dropdown').removeClass('show-dropdown');
177 });
178
179
180 // -------show/hide step stats info-------
181 $(document).on("change", "#stats", function(e) {
182 if( $(this).is(':checked') ){
183 $('.node-wrapper .node-stats').show();
184 }else{
185 $('.node-wrapper .node-stats').hide();
186 }
187 });
188
189 var FunnelHandler = function() {
190 this.initStepSortable();
191 this.initProductSortable();
192 $(document.body)
193 .on('submit', '#wpfnl-change-funnel-name', this.changeFunnelName)
194
195 $('.wpfnl-duplicate-funnel').on('click', this.cloneFunnel);
196 $('.wpfnl-delete-funnel').on('click', this.deleteFunnel);
197 $('.wpfnl-update-funnel-status').on('click', this.UpdateFunnelStatus);
198 $('.wpfnl-export-funnel').on('click', this.ExportFunnel);
199 $('.wpfnl-export-all-funnels').on('click', this.ExportAllFunnel);
200 $('#wpfnl-import-funnels').on('submit', this.ImportFunnels);
201 $('#wpfnl-import-funnels').on('change', this.UploadFile);
202 $('.wpfnl-import-funnels').on('click', this.ShowImportFunnelModal);
203 $('.import-funnel-modal .close-modal, .import-funnel-modal .import-funnel-modal-inner').on('click', this.CloseImportFunnelModal);
204 $('.import-funnel-modal .import-funnel-modal-wrapper').on('click', this.PreventImportFunnelModal);
205
206 $(document.body).on('click', '.wpfnl-bulk-delete', this.bulkDeleteFunnel)
207 $(document.body).on('click', '.wpfnl-bulk-export', this.bulkExportFunnel)
208 };
209
210 /**
211 * Select quantity
212 *
213 * @since 1.0.0
214 */
215 $('input[name=quantity]').change(function() {
216 var val = parseInt(this.value);
217 var product = $(this).attr('data-product');
218
219 for (var i in product_option) {
220 if (product_option[i].id == product) {
221 product_option[i].quantity = val;
222 break; //Stop this loop, we found it!
223 }
224 }
225 });
226
227 /**
228 * Subtext Setup
229 *
230 * @since 1.0.0
231 */
232 $('input[name=subtext]').change(function() {
233 var val = $(this).val();
234 var product = $(this).attr('data-product');
235
236 for (var i in product_option) {
237 if (product_option[i].id == product) {
238 product_option[i].subtext = val;
239 break; //Stop this loop, we found it!
240 }
241 }
242 });
243
244 /**
245 * Highlight Text Setup
246 *
247 * @since 1.0.0
248 */
249 $('input[name=text-highlight]').change(function() {
250 var val = $(this).val();
251 var product = $(this).attr('data-product');
252
253 for (var i in product_option) {
254 if (product_option[i].id == product) {
255 product_option[i].text_highlight = val;
256 break; //Stop this loop, we found it!
257 }
258 }
259 });
260
261 /**
262 * Enable Highlight setup
263 *
264 * @since 1.0.0
265 */
266 $('input[name=hide-img-mobile]').change(function() {
267 if (this.checked) {
268 var val = 'on';
269 } else {
270 var val = 'off';
271 }
272
273 var product = $(this).attr('data-product');
274
275 for (var i in product_option) {
276 if (product_option[i].id == product) {
277 product_option[i].enable_highlight = val;
278 break; //Stop this loop, we found it!
279 }
280 }
281 });
282
283
284 /**
285 * Sort step order
286 *
287 * @since 1.0.0
288 */
289 FunnelHandler.prototype.initStepSortable = function() {
290 $("#wpfnl-funnel-step-lists").sortable({
291 axis: "y",
292 start: function(event, ui) {
293
294 },
295 update: function(event, ui) {
296 var order = $("#wpfnl-funnel-step-lists").sortable("toArray");
297
298 var funnel_id = getUrlParameter('id');
299
300 var payload = {
301 funnel_id: funnel_id,
302 order: order,
303 };
304 wpAjaxHelperRequest("funnel-drag-order", payload)
305 .success(function(response) {
306
307 })
308 .error(function(response) {
309 // console.log('error');
310 });
311 }
312 });
313 $("#wpfnl-funnel-step-lists").disableSelection();
314 };
315
316
317 /**
318 * Sort product accordion order
319 *
320 * @since 1.0.0
321 */
322 FunnelHandler.prototype.initProductSortable = function() {
323 $(".product-single-accordion__sortable-wrapper").sortable({
324 axis: "y",
325 start: function(event, ui) {
326
327 },
328 update: function(event, ui) {
329 var product_order = $(".product-single-accordion__sortable-wrapper").sortable("toArray");
330
331 product_option = [];
332 var funnel_id = getUrlParameter('id');
333
334 for (var i in product_order) {
335 var dragger_id = product_order[i];
336 var prod_id = dragger_id.replace("product__single-accordion-", "");
337 var quantity = $('#product-quantity-' + prod_id).val();
338 product_option.push({
339 'id': prod_id,
340 'quantity': quantity
341 });
342 }
343
344 }
345 });
346 $(".product-single-accordion__sortable-wrapper").disableSelection();
347 };
348
349
350 /**
351 *
352 * Ajax handler for duplicate
353 * funnel action
354 *
355 * @param event
356 * @since 1.0.0
357 */
358 FunnelHandler.prototype.cloneFunnel = function(event) {
359 event.preventDefault();
360 var funnel_id = $(this).attr('data-id'),
361 loader = $(this).find('.wpfnl-loader');
362 var payload = {
363 funnel_id: funnel_id
364 };
365
366 $(this).css('pointer-events', 'none');
367 loader.show();
368
369 wpAjaxHelperRequest("clone-funnel", payload)
370 .success(function(response) {
371 window.location.href = response.redirectUrl;
372 loader.hide();
373 })
374 .error(function(response) {
375 loader.hide();
376 });
377 };
378
379
380 /**
381 * delete funnel and all the related
382 * data
383 *
384 * @param event
385 * @since 1.0.0
386 */
387 FunnelHandler.prototype.deleteFunnel = function(event) {
388 event.preventDefault();
389 var funnel_id = $(this).attr('data-id');
390 var payload = {
391 funnel_id: funnel_id
392 };
393 if (confirm("Are you sure?")) {
394 wpAjaxHelperRequest("delete-funnel", payload)
395 .success(function(response) {
396
397 window.location.href = response.redirectUrl;
398 })
399 .error(function(response) {
400
401 });
402 }
403 };
404
405 /**
406 * bulk delete funnel and all the related
407 * data
408 *
409 * @param event
410 * @since 1.0.0
411 */
412 FunnelHandler.prototype.bulkDeleteFunnel = function(event) {
413 event.preventDefault()
414 let funnel_ids = selectedIds
415
416 let payload = {
417 ids: funnel_ids,
418 }
419
420 if (confirm('Are you sure?')) {
421 fetch(
422 `${window.template_library_object.rest_api_url}wpfunnels/v1/funnel-control/bulk-delete-funnel`,
423 {
424 method: 'POST',
425 headers: {
426 'Content-Type': 'application/json',
427 'X-WP-Nonce': wpApiSettings.nonce,
428 },
429 body: JSON.stringify(payload),
430 },
431 )
432 .then((response) => response.json())
433 .then((data) => {
434 if (data.success) {
435 window.location.href = data.redirectUrl
436 }
437 })
438 .catch((error) => {
439 console.error('Error:', error)
440 })
441 }
442 selectedIds = []
443 };
444
445 /**
446 * Update funnel status
447 * data
448 *
449 * @param event
450 * @since 1.0.0
451 */
452 FunnelHandler.prototype.UpdateFunnelStatus = function(event) {
453 event.preventDefault();
454 var funnel_id = $(this).attr('data-id');
455 var new_status = $(this).attr('data-status');
456 var payload = {
457 funnel_id : funnel_id,
458 status :new_status
459 };
460 if (confirm("Are you sure?")) {
461 wpAjaxHelperRequest("update-funnel-status", payload)
462 .success(function(response) {
463 window.location.href = response.redirect_url;
464 })
465 .error(function(response) {
466
467 });
468 }
469 };
470
471
472
473 /**
474 *
475 * Ajax handler for export a single funnel
476 * funnel action
477 *
478 * @param event
479 * @since 2.6.3
480 */
481 FunnelHandler.prototype.ExportFunnel = function(event) {
482 event.preventDefault();
483
484 var funnel_id = $(this).attr('data-id'),
485 loader = $(this).find('.wpfnl-loader');
486 var payload = {
487 funnel_id: funnel_id
488 };
489
490 $(this).css('pointer-events', 'none');
491 loader.show();
492
493 wpAjaxHelperRequest("wpfnl-export-funnel", payload)
494 .success(function(response) {
495 if( response.success ){
496 const jsonData = response.steps;
497 const filename = response.title + '.json';
498 download(JSON.stringify(jsonData), filename, "text/plain");
499 }
500 loader.hide();
501 })
502 .error(function(response) {
503 loader.hide();
504 });
505 };
506
507
508 /**
509 *
510 * Ajax handler for export a single funnel
511 * funnel action
512 *
513 * @param event
514 * @since 2.6.3
515 */
516 FunnelHandler.prototype.ExportAllFunnel = function(event) {
517 event.preventDefault();
518
519 var status = 'all',
520 loader = $(this).find('.wpfnl-loader');
521 var payload = {
522 status: status
523 };
524
525 $(this).css('pointer-events', 'none');
526 loader.show();
527
528 wpAjaxHelperRequest("wpfnl-export-all-funnels", payload)
529 .success(function(response) {
530 if( response.success ){
531 const jsonData = response.data;
532
533 var today = new Date();
534 var dd = String(today.getDate()).padStart(2, '0');
535 var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
536 var yyyy = today.getFullYear();
537 today = mm + '-' + dd + '-' + yyyy;
538 const filename = 'wpfunnels-export-'+today+'-.json';
539
540 download(JSON.stringify(jsonData), filename, "text/plain");
541 }
542 loader.hide();
543 })
544 .error(function(response) {
545 loader.hide();
546 });
547 };
548
549
550 /**
551 *
552 * Ajax handler for export bulk funnels
553 * funnel action
554 *
555 * @param event
556 * @since 2.7.19
557 */
558 FunnelHandler.prototype.bulkExportFunnel = function(event) {
559 event.preventDefault()
560
561 let funnel_ids = selectedIds
562
563 let status = 'all',
564 loader = $(this).find('.wpfnl-loader')
565 let payload = {
566 status: status,
567 ids: funnel_ids,
568 }
569
570 $(this).css('pointer-events', 'none')
571 loader.show()
572
573 fetch(
574 `${window.template_library_object.rest_api_url}wpfunnels/v1/import-export/bulk-export-funnel`,
575 {
576 method: 'POST',
577 headers: {
578 'Content-Type': 'application/json',
579 'X-WP-Nonce': wpApiSettings.nonce,
580 },
581 body: JSON.stringify(payload),
582 },
583 )
584 .then((response) => response.json())
585 .then((data) => {
586 if (data.success) {
587 const jsonData = data.data
588
589 let today = new Date()
590 let dd = String(today.getDate()).padStart(2, '0')
591 let mm = String(today.getMonth() + 1).padStart(2, '0') // January is 0!
592 let yyyy = today.getFullYear()
593 today = mm + '-' + dd + '-' + yyyy
594 const filename = 'wpfunnels-export-' + today + '-.json'
595
596 download(JSON.stringify(jsonData), filename, 'text/plain')
597 }
598 loader.hide()
599 window.location.href = data.redirectUrl
600 })
601 .catch((error) => {
602 console.error('Error:', error)
603 loader.hide()
604 })
605 selectedIds = []
606 };
607
608
609 /**
610 * Show import funnels Modal
611 *
612 * @param event
613 * @since 2.6.3
614 */
615 FunnelHandler.prototype.ShowImportFunnelModal = function(e) {
616 e.stopPropagation();
617 e.preventDefault();
618 $('.import-funnel-modal').addClass('show-modal');
619 };
620
621 /**
622 * Stop Propagation for .import-funnel-modal-wrapper
623 *
624 */
625 FunnelHandler.prototype.PreventImportFunnelModal = function(e) {
626 e.stopPropagation();
627 };
628
629 /**
630 * Close import funnels Modal
631 *
632 * @param event
633 * @since 2.6.3
634 */
635 FunnelHandler.prototype.CloseImportFunnelModal = function(e) {
636 e.preventDefault();
637 $('.import-funnel-modal').removeClass('show-modal');
638 $('#wpfnl-export-import-warning').css('display', 'none');
639 };
640
641 /**
642 * Show import funnels Modal
643 *
644 * @param event
645 * @since 2.6.3
646 */
647 FunnelHandler.prototype.ShowImportFunnelModal = function(e) {
648 e.stopPropagation();
649 e.preventDefault();
650 $('.import-funnel-modal').addClass('show-modal');
651 };
652
653 /**
654 * Stop Propagation for .import-funnel-modal-wrapper
655 *
656 */
657 FunnelHandler.prototype.PreventImportFunnelModal = function(e) {
658 e.stopPropagation();
659 };
660
661 /**
662 * Close import funnels Modal
663 *
664 * @param event
665 * @since 2.6.3
666 */
667 FunnelHandler.prototype.CloseImportFunnelModal = function(e) {
668 e.preventDefault();
669 $('.import-funnel-modal').removeClass('show-modal');
670 $('#wpfnl-export-import-warning').css('display', 'none');
671 };
672
673
674 /**
675 *
676 * Ajax handler for import funnels
677 * funnel action
678 *
679 * @param event
680 * @since 2.6.3
681 */
682 FunnelHandler.prototype.ImportFunnels = function(event) {
683 event.preventDefault();
684 $('#wpfnl-import-funnel .wpfnl-loader').css('display', 'inline-block');
685 $('#wpfnl-export-import-warning').css('display', 'none');
686 let formData = new FormData(this);
687 let importFile = $('#wpfnl-file-import')[0].files[0];
688 if( importFile ){
689 const fileName = importFile?.name;
690 const fileExtension = fileName.split('.').pop();
691 if( 'json' === fileExtension ){
692 formData.append('action', 'wpfnl_import_funnels');
693 formData.append('is_ajax', 'yes');
694 formData.append('uploaded_file', importFile);
695
696 $.ajax( {
697 url: WPFunnelVars.ajaxurl,
698 type: 'post',
699 contentType: false,
700 dataType:'json',
701 processData: false,
702 data: formData,
703 success: function(response) {
704 if(response.success) {
705 window.location.reload();
706 }
707 $('#wpfnl-import-funnel .wpfnl-loader').css('display', 'none');
708 $('.import-funnel-modal').removeClass('show-modal');
709 }
710 }).done( function ( request, status, XHR ) {
711 if(status.success) {
712 // window.location.reload();
713 }
714 $('#wpfnl-import-funnel .wpfnl-loader').css('display', 'none');
715 $('.import-funnel-modal').removeClass('show-modal');
716 });
717 }else{
718 $('#wpfnl-export-import-warning').css('display', 'inline-block');
719 $('#wpfnl-export-import-warning').css('color', '#d63638 !important');
720 $('#wpfnl-import-funnel .wpfnl-loader').css('display', 'none');
721 }
722
723 }else{
724 $('#wpfnl-export-import-warning').css('display', 'inline-block');
725 $('#wpfnl-export-import-warning').css('color', '#d63638 !important');
726 $('#wpfnl-import-funnel .wpfnl-loader').css('display', 'none');
727 }
728
729 };
730
731
732 /**
733 *
734 * Ajax handler for import funnels
735 * funnel action
736 *
737 * @param event
738 * @since 2.6.3
739 */
740 FunnelHandler.prototype.UploadFile = function(event) {
741 event.preventDefault();
742 $('#wpfnl-export-import-warning').css('display', 'none');
743 let importFile = $('#wpfnl-file-import')[0].files[0];
744
745 if( importFile ){
746 const fileName = importFile?.name;
747 const fileExtension = fileName.split('.').pop();
748
749 if( 'json' === fileExtension ){
750 $('#wpfnl-export-import-warning').css('display', 'none');
751 $('.import-funnel-modal .import-label').addClass('file-added');
752 $('.import-funnel-modal .import-label > h4').text('Json file ready for import.');
753 $('.import-funnel-modal .import-label > p').text(fileName);
754 }else{
755 $('.import-funnel-modal .import-label').removeClass('file-added');
756 $('#wpfnl-export-import-warning').css('display', 'inline-block');
757 $('#wpfnl-export-import-warning').css('color', '#d63638 !important');
758
759 $('.import-funnel-modal .import-label > h4').html('Drag & Drop or <span class="primary-color">Choose file</span> to upload.');
760 $('.import-funnel-modal .import-label > p').text('Supported formats: JSON file.');
761 }
762
763 }else{
764 $('.import-funnel-modal .import-label').removeClass('file-added');
765 $('#wpfnl-export-import-warning').css('display', 'inline-block');
766 $('#wpfnl-export-import-warning').css('color', '#d63638 !important');
767
768 $('.import-funnel-modal .import-label > h4').html('Drag & Drop or <span class="primary-color">Choose file</span> to upload.');
769 $('.import-funnel-modal .import-label > p').text('Supported formats: JSON file.');
770 }
771
772 };
773
774
775 /**
776 * Download json file
777 *
778 * @param content
779 * @param fileName
780 * @param contentType
781 *
782 * @since 2.6.3
783 */
784 function download(content, fileName, contentType) {
785 const a = document.createElement("a");
786 const file = new Blob([content], { type: contentType });
787 a.href = URL.createObjectURL(file);
788 a.download = fileName;
789 a.click();
790 }
791
792 /**
793 * Realtime funnel name change on header
794 *
795 * @param event
796 * @since 1.0.0
797 */
798 var fnl_name = '';
799 var fnl_name2 = '';
800 $('.funnel-name-edit').on('click', function(e) {
801 e.preventDefault();
802 fnl_name = $(this).parents('.steps-page__fnl-name').find('.funnel-name').text();
803 $(this).hide();
804 $('.funnel-name-cancel').show();
805 $(this).parents('.steps-page__fnl-name').find('.funnel-name-input').text(fnl_name).show();
806 $(this).parents('.steps-page__fnl-name').find('.funnel-name').hide();
807 $(this).parents('.steps-page__fnl-name').find('.funnel-name-submit').show();
808 });
809
810 $('.funnel-name-input').keyup(function() {
811 $(this).parents('.steps-page__fnl-name').find('.funnel-name').text($(this).val());
812 });
813
814
815 $('.funnel-name-submit').on('click', function(e) {
816 e.preventDefault();
817 fnl_name2 = $(this).parents('.steps-page__fnl-name').find('.funnel-name-input').val();
818 $(this).hide();
819 $('.funnel-name-cancel').hide();
820 $(this).parents('.steps-page__fnl-name').find('.funnel-name-input').val(fnl_name2).hide();
821 $(this).parents('.steps-page__fnl-name').find('.funnel-name').text(fnl_name2).show();
822 $(this).parents('.steps-page__fnl-name').find('.funnel-name-edit').show();
823 });
824
825 $('.funnel-name-cancel').on('click', function(e) {
826 e.preventDefault();
827 $(this).hide();
828 $('.funnel-name-cancel').hide();
829 $(this).parents('.steps-page__fnl-name').find('.funnel-name-input').val(fnl_name).hide();
830 $(this).parents('.steps-page__fnl-name').find('.funnel-name').text(fnl_name).show();
831 $(this).parents('.steps-page__fnl-name').find('.funnel-name-submit').hide();
832 $(this).parents('.steps-page__fnl-name').find('.funnel-name-edit').show();
833 });
834
835
836 /**
837 * Realtime automation name change on automation drawer
838 *
839 * @param event
840 * @since 1.0.0
841 */
842 var automation_name = '';
843 var automation_name2 = '';
844 $(document).on("click", ".automation-name-edit", function(e) {
845 e.preventDefault();
846
847 automation_name = $(this).parents('.automation-name-wrapper').find('.automation-name-preview').text();
848 $(this).hide();
849 $('.automation-name-cancel').css('display', 'flex');
850 $(this).parents('.automation-name-wrapper').find('.automation-name-input').val(automation_name).css('display', 'flex');
851 $(this).parents('.automation-name-wrapper').find('.automation-name-preview').hide();
852 $(this).parents('.automation-name-wrapper').find('.automation-name-submit').css('display', 'flex');
853 });
854
855 // $(document).on("click", ".automation-name-edit", function(e) {
856 $('.automation-name-input').keyup(function() {
857 $(this).parents('.automation-name-wrapper').find('.automation-name-preview').text($(this).val());
858 });
859
860 $(document).on("click", ".automation-name-submit", function(e) {
861 e.preventDefault();
862 automation_name2 = $(this).parents('.automation-name-wrapper').find('.automation-name-input').val();
863 $(this).hide();
864 $('.automation-name-cancel').hide();
865 $(this).parents('.automation-name-wrapper').find('.automation-name-input').val(automation_name2).hide();
866 $(this).parents('.automation-name-wrapper').find('.automation-name-preview').text(automation_name2).css('display', 'flex');
867 $(this).parents('.automation-name-wrapper').find('.automation-name-edit').css('display', 'flex');
868 });
869
870 $(document).on("click", ".automation-name-cancel", function(e) {
871 e.preventDefault();
872 $(this).hide();
873 $('.automation-name-cancel').hide();
874 $(this).parents('.automation-name-wrapper').find('.automation-name-input').val(automation_name).hide();
875 $(this).parents('.automation-name-wrapper').find('.automation-name-preview').text(automation_name).css('display', 'flex');
876 $(this).parents('.automation-name-wrapper').find('.automation-name-submit').hide();
877 $(this).parents('.automation-name-wrapper').find('.automation-name-edit').css('display', 'flex');
878 });
879
880 $(document).on("click", "#save_automation", function(e) {
881 e.preventDefault();
882 $('.event-trigger').each(function(){
883 if( $(this).children("option:selected").val() == '' ){
884 $(this).parents('.wpfnl-form-group').addClass( 'field-required' );
885 }else{
886 $(this).parents('.wpfnl-form-group').removeClass( 'field-required' );
887 }
888 })
889 $('.list-trigger').each(function(){
890 if( $(this).children("option:selected").val() == '' ){
891 $(this).parents('.wpfnl-form-group').addClass( 'field-required' );
892 }else{
893 $(this).parents('.wpfnl-form-group').removeClass( 'field-required' );
894 }
895 })
896 $('.tag-trigger').each(function(){
897 if( $(this).children("option:selected").val() == '' ){
898 $(this).parents('.wpfnl-form-group').addClass( 'field-required' );
899
900 }else{
901 $(this).parents('.wpfnl-form-group').removeClass( 'field-required' );
902 }
903 })
904
905 });
906
907 //-----remove "field-required" class when data selected-------
908 $(document).on("change", ".single-trigger .selectbox-wrapper select", function(e) {
909 if( $(this).children("option:selected").val() != '' ){
910 $(this).parents('.wpfnl-form-group').removeClass( 'field-required' );
911 }
912 });
913
914
915
916 /**
917 * change funnel name
918 *
919 * @param event
920 * @since 1.0.0
921 */
922 FunnelHandler.prototype.changeFunnelName = function(event) {
923 event.preventDefault();
924 var payload = {
925 data: $(this).serialize(),
926 },
927 button = $(this).find('.funnel-name-submit');
928 button.hide();
929 button.parents('.steps-page__fnl-name').find('.funnel-name-input').hide();
930 button.parents('.steps-page__fnl-name').find('.funnel-name').show();
931 button.parents('.steps-page__fnl-name').find('.funnel-name-edit').show();
932 wpAjaxHelperRequest("funnel-name-change", payload)
933 .success(function(response) {
934 location.reload();
935 })
936 .error(function(response) {
937
938 });
939 };
940
941
942 var StepHandler = function() {
943 $(document.body)
944 .on('click', '#wpfnl-delete-step', this.deleteStep)
945 .on('click', '#wpfnl-update-checkout-product-tab', this.updateCheckoutProduct)
946 .on('click', '#wpfnl-update-thank-you-settings', this.updateThankYouSettings)
947 .on('click', '#wpfnl-update-upsell-settings', this.updateUpsellSettings)
948 .on('click', '#wpfnl-update-downsell-settings', this.updateDownsellSettings)
949 .on('change', '#wpfnl-choose-step-type', this.stepTypeChange)
950 // .on('click', '#wpfnl-add-product', this.addProduct)
951 };
952
953
954
955 /**
956 * add product
957 * @param event
958 */
959 StepHandler.prototype.addProduct = function(event) {
960 event.preventDefault();
961 var _prObj = $('#wpfnl-checkout-products').select2('data')[0],
962 step_id = $(this).attr('data-id');
963 if (_prObj) {
964 product_option.push({
965 'id': _prObj.id,
966 'quantity': 1
967 });
968 var payload = {
969 id: _prObj.id,
970 step_id: step_id,
971 products: JSON.stringify(product_option),
972 index: parseInt($('.product__single-accordion').length)
973 },
974 that = $(this);
975
976 wpAjaxHelperRequest("wpfnl-add-product", payload)
977 .success(function(response) {
978 if (response.success) {
979 $('.no-product-notice').hide();
980 $('.accordion-head').show();
981 // $('.product-accordion__wrapper').append(response.html);
982 $('.product-single-accordion__sortable-wrapper').append(response.html);
983 $('#wpfnl-checkout-products').val(null).trigger('change');
984 if (product_option.length) that.html('Add product');
985 // $('.product__single-accordion:nth-child(2)').addClass('active');
986 }
987 console.log("Woohoo!");
988 console.log(response);
989 $('#setp-list-' + step_id + ' span').css('color', 'black');
990
991 $(".product-single-accordion__sortable-wrapper").sortable({
992 axis: "y",
993 start: function(event, ui) {
994
995 },
996 update: function(event, ui) {
997 var product_order = $(".product-single-accordion__sortable-wrapper").sortable("toArray");
998
999 product_option = [];
1000 var funnel_id = getUrlParameter('id');
1001
1002 for (var i in product_order) {
1003 var dragger_id = product_order[i];
1004 var prod_id = dragger_id.replace("product__single-accordion-", "");
1005 var quantity = $('#product-quantity-' + prod_id).val();
1006 product_option.push({
1007 'id': prod_id,
1008 'quantity': quantity
1009 });
1010 }
1011 }
1012 });
1013 $(".product-single-accordion__sortable-wrapper").disableSelection();
1014
1015 })
1016 .error(function(response) {
1017
1018 });
1019 }
1020
1021 };
1022
1023
1024 /**
1025 * delete product from checkout
1026 *
1027 * @param event
1028 */
1029 StepHandler.prototype.deleteproduct = function(event) {
1030 event.preventDefault();
1031 var index = $(this).attr('data-index');
1032 product_option.splice(index, 1);
1033 var payload = {
1034 step_id: $(this).attr('data-id'),
1035 products: JSON.stringify(product_option),
1036 };
1037 wpAjaxHelperRequest("wpfnl-update-checkout-product-tab", payload)
1038 .success(function(response) {
1039 if (response.success) {
1040 location.reload();
1041 return false;
1042 }
1043 console.log("Woohoo!");
1044 console.log(response);
1045 })
1046 .error(function(response) {
1047
1048 });
1049 };
1050
1051 /**
1052 * save function for checkout steps
1053 * product tab
1054 *
1055 * @param event
1056 * @since 1.0.0
1057 */
1058 StepHandler.prototype.updateCheckoutProduct = function(event) {
1059 event.preventDefault();
1060 var thisLoader = $(this).find('.wpfnl-loader');
1061 var thisAlert = $(this).siblings('.wpfnl-alert');
1062
1063 //=== Enable additional checkout fields===//
1064 var coupon = 'no';
1065 if ($('#enable-checkout-coupon').prop("checked") == true) {
1066 coupon = 'yes';
1067 } else if ($('#enable-checkout-coupon').prop("checked") == false) {
1068 coupon = 'no';
1069 }
1070
1071 //=== Enable additional checkout fields===//
1072
1073 thisLoader.fadeIn();
1074 var payload = {
1075 step_id: $(this).attr('data-id'),
1076 coupon: coupon,
1077 products: JSON.stringify(product_option),
1078 // discount: $(".wpfnl-checkout-discount").val(),
1079 };
1080 wpAjaxHelperRequest("wpfnl-update-checkout-product-tab", payload)
1081 .success(function(response) {
1082 thisLoader.fadeOut();
1083 thisAlert.text('Saved Successfully').addClass('box wpfnl-success').fadeIn();
1084
1085 setTimeout(function() {
1086 thisAlert.fadeOut().text('').removeClass('box wpfnl-success');
1087 }, 2000);
1088
1089 console.log("Woohoo!");
1090 console.log(response);
1091 })
1092 .error(function(response) {
1093 console.log("Uh, oh!");
1094 console.log(response.statusText);
1095
1096 thisLoader.fadeOut();
1097 thisAlert.text('Erorr occurred').addClass('box wpfnl-error').fadeIn();
1098 setTimeout(function() {
1099 thisAlert.fadeOut().text('').removeClass('box wpfnl-error');
1100 }, 2000);
1101 });
1102 };
1103
1104 /**
1105 * Set minimum time for custom redirection in thankyou page
1106 *
1107 * @param event
1108 *
1109 */
1110 $(document).on("keyup", "#set-time", function() {
1111 if( $("#set-time").val() && $("#set-time").val() < 1 ){
1112 $("#set-time").val(1)
1113 }
1114 })
1115
1116 /**
1117 * save thankyou settings
1118 * options
1119 *
1120 * @param event
1121 * @since 1.0.0
1122 */
1123 StepHandler.prototype.updateThankYouSettings = function(event) {
1124 event.preventDefault();
1125 var thisLoader = $(this).find('.wpfnl-loader');
1126 var thisAlert = $(this).siblings('.wpfnl-alert');
1127 thisLoader.fadeIn()
1128 var payload = {
1129 step_id: $(this).attr('data-id'),
1130 text: $(".thankyou-page-text").val(),
1131 redirect_link: $(".thankyou-redirect-link").val(),
1132 order_overview: $("#enable-order-overview").is(':checked') ? 'on' : 'off',
1133 order_details: $("#enable-order-details").is(':checked') ? 'on' : 'off',
1134 billing_details: $("#enable-billing-details").is(':checked') ? 'on' : 'off',
1135 shipping_details: $("#enable-shipping-details").is(':checked') ? 'on' : 'off',
1136 is_custom_redirect: $("#enable-custom-redirect").is(':checked') ? 'on' : 'off',
1137
1138 is_direct_redirect: $("#direct-custom-redirect").is(':checked') ? 'on' : 'off',
1139 set_time: $("#set-time").val(),
1140 custom_redirect_url: $("#custom-redirect-url").val(),
1141 };
1142
1143 wpAjaxHelperRequest("update-thankyou-settings", payload)
1144 .success(function(response) {
1145 thisLoader.fadeOut();
1146 thisAlert.text('Saved Successfully').addClass('box wpfnl-success').fadeIn();
1147 setTimeout(function() {
1148 thisAlert.fadeOut().text('').removeClass('box wpfnl-success');
1149 }, 2000);
1150 console.log("Woohoo!");
1151 console.log(response);
1152 })
1153 .error(function(response) {
1154 console.log("Uh, oh!");
1155 console.log(response.statusText);
1156 thisLoader.fadeOut();
1157 thisAlert.text('Erorr occurred').addClass('box wpfnl-error').fadeIn();
1158 setTimeout(function() {
1159 thisAlert.fadeOut().text('').removeClass('box wpfnl-error');
1160 }, 2000);
1161 });
1162 };
1163
1164 /**
1165 * save upsell settings
1166 * options
1167 *
1168 * @param event
1169 * @since 1.0.0
1170 */
1171 StepHandler.prototype.updateUpsellSettings = function(event) {
1172 event.preventDefault();
1173 var thisLoader = $(this).find('.wpfnl-loader');
1174 var thisAlert = $(this).siblings('.wpfnl-alert');
1175 thisLoader.fadeIn()
1176 var payload = {
1177 step_id: $(this).attr('data-id'),
1178 product: $(".wpfnl-product-search").val(),
1179 quantity: $("#upsell-product-quantity").val(),
1180 product_price: $("#upsell-original-price").val(),
1181 product_sale_price: $("#upsell-sale-price").val(),
1182 discount_type: $("#upsell-discount-type").val(),
1183 discount_value: $("#upsell-discount-value").val(),
1184 hide_image: $("#img-hide-mobile").prop('checked') ? 'on' : 'off',
1185 next_step_yes: $("#next-step-yes").val(),
1186 next_step_no: $("#next-step-no").val(),
1187 };
1188 wpAjaxHelperRequest("update-upsell-settings", payload)
1189 .success(function(response) {
1190 thisLoader.fadeOut();
1191 thisAlert.text('Saved Successfully').addClass('box wpfnl-success').fadeIn();
1192 setTimeout(function() {
1193 thisAlert.fadeOut().text('').removeClass('box wpfnl-success');
1194 }, 2000);
1195 console.log("Woohoo!");
1196 console.log(response);
1197 })
1198 .error(function(response) {
1199 console.log("Uh, oh!");
1200 console.log(response.statusText);
1201 thisLoader.fadeOut();
1202 thisAlert.text('Erorr occurred').addClass('box wpfnl-error').fadeIn();
1203 setTimeout(function() {
1204 thisAlert.fadeOut().text('').removeClass('box wpfnl-error');
1205 }, 2000);
1206 });
1207 };
1208
1209
1210
1211 /**
1212 * save downsell settings
1213 * options
1214 *
1215 * @param event
1216 * @since 1.0.0
1217 */
1218 StepHandler.prototype.updateDownsellSettings = function(event) {
1219 event.preventDefault();
1220 var thisLoader = $(this).find('.wpfnl-loader');
1221 var thisAlert = $(this).siblings('.wpfnl-alert');
1222 thisLoader.fadeIn()
1223 var payload = {
1224 step_id: $(this).attr('data-id'),
1225 product: $(".wpfnl-product-search").val(),
1226 quantity: $("#downsell-product-quantity").val(),
1227 product_price: $("#downsell-original-price").val(),
1228 product_sale_price: $("#downsell-sale-price").val(),
1229 discount_type: $("#downsell-discount-type").val(),
1230 discount_value: $("#downsell-discount-value").val(),
1231 hide_image: $("#img-hide-mobile").prop('checked') ? 'on' : 'off',
1232 next_step_yes: $("#next-step-yes").val(),
1233 next_step_no: $("#next-step-no").val(),
1234 };
1235 wpAjaxHelperRequest("update-downsell-settings", payload)
1236 .success(function(response) {
1237 thisLoader.fadeOut();
1238 thisAlert.text('Saved Successfully').addClass('box wpfnl-success').fadeIn();
1239 setTimeout(function() {
1240 thisAlert.fadeOut().text('').removeClass('box wpfnl-success');
1241 }, 2000);
1242 console.log("Woohoo!");
1243 console.log(response);
1244 })
1245 .error(function(response) {
1246 console.log("Uh, oh!");
1247 console.log(response.statusText);
1248 thisLoader.fadeOut();
1249 thisAlert.text('Erorr occurred').addClass('box wpfnl-error').fadeIn();
1250 setTimeout(function() {
1251 thisAlert.fadeOut().text('').removeClass('box wpfnl-error');
1252 }, 2000);
1253 });
1254 };
1255
1256
1257
1258 /**
1259 * Ajax handler for step
1260 * deletion action
1261 *
1262 * @param event
1263 */
1264 StepHandler.prototype.deleteStep = function(event) {
1265 event.preventDefault();
1266 var step_id = $(this).attr('data-id');
1267 var payload = {
1268 step_id: step_id
1269 };
1270 if (confirm("Are you sure?")) {
1271 wpAjaxHelperRequest("delete-step", payload)
1272 .success(function(response) {
1273 console.log("Woohoo!");
1274 console.log(response);
1275 window.location.href = response.redirectUrl;
1276 })
1277 .error(function(response) {
1278 console.log("Uh, oh!");
1279 console.log(response.statusText);
1280 });
1281 }
1282 };
1283
1284
1285 /**
1286 * Ajax handler for step
1287 * creation
1288 *
1289 * @param e
1290 * @since 1.0.0
1291 */
1292 StepHandler.prototype.createStep = function(e) {
1293 e.preventDefault();
1294 var thisLoader = $(this).find('.wpfnl-loader');
1295 var thisAlert = $(this).siblings('.wpfnl-alert');
1296
1297 thisLoader.fadeIn();
1298
1299 var wrapper = $('#create-step-form'),
1300 type = $(this).attr('data-step-type'),
1301 funnelId = $(this).attr('data-funnel-id'),
1302 stepListWrapper = $('#wpfnl-funnel-step-lists');
1303
1304 var payload = {
1305 funnel_id: funnelId,
1306 step_type: type,
1307 };
1308 wpAjaxHelperRequest("create-step", payload)
1309 .success(function(response) {
1310 console.log('success');
1311 thisLoader.fadeOut();
1312 thisAlert.text('Successfully Step Created').addClass('box wpfnl-success').fadeIn();
1313
1314 setTimeout(function() {
1315 thisAlert.fadeOut().text('').removeClass('box wpfnl-success');
1316 }, 2000);
1317
1318 if (response.success) {
1319 window.location.href = response.redirectUrl;
1320 } else {
1321 console.log(response);
1322 }
1323
1324 })
1325 .error(function(response) {
1326 thisLoader.fadeOut();
1327 thisAlert.text('Erorr Occurred').addClass('box wpfnl-error').fadeIn();
1328
1329 setTimeout(function() {
1330 thisAlert.fadeOut().text('').removeClass('box wpfnl-error');
1331 }, 2000);
1332 });
1333 };
1334
1335
1336
1337 StepHandler.prototype.stepTypeChange = function(event) {
1338 event.preventDefault();
1339 var wrapper = $('.choose-step-type'),
1340 step_type = $(this).find(":selected").val(),
1341 saveBtn = $('#wpfnl-create-step');
1342 if (WPFunnelVars.is_wc_installed === 'no' && (step_type === 'checkout' || step_type === 'upsell' || step_type === 'downsell')) {
1343 $('.wpfnl-modal__body').find('p').remove();
1344 wrapper.after("<p style='text-align: center; color: red'>You need install and active WooCommerce to use this step type. </p>");
1345 saveBtn.addClass('disabled').css('pointer-events', 'none');
1346 return;
1347 } else {
1348 $('.wpfnl-modal__body').find('p').remove();
1349 saveBtn.removeClass('disabled').css('pointer-events', 'inherit');
1350 }
1351 };
1352
1353
1354
1355 var DataSerachHandler = function() {
1356 this.initProductSearch();
1357 this.initCouponSearch();
1358 };
1359
1360 /**
1361 * initialize product search
1362 * for checkout
1363 *
1364 * @param event
1365 * @since 1.0.0
1366 */
1367 DataSerachHandler.prototype.initProductSearch = function(event) {
1368 var select2Args = {
1369 minimumInputLength: 3,
1370 allowClear: true,
1371 maximumSelectionLength: 1,
1372 ajax: {
1373 url: WPFunnelVars.ajaxurl,
1374 dataType: 'json',
1375 delay: 250,
1376 data: function(params) {
1377 return {
1378 term: params.term,
1379 action: 'wpfnl_product_search',
1380 security: WPFunnelVars.security,
1381 };
1382 },
1383 processResults: function(data) {
1384 var terms = [];
1385 if (data) {
1386 $.each(data, function(id, value) {
1387 terms.push({
1388 id: id,
1389 text: value.name,
1390 price: value.price,
1391 sale_price: value.sale_price
1392 });
1393 });
1394 }
1395 return {
1396 results: terms
1397 };
1398 },
1399 cache: true
1400 }
1401 };
1402
1403 $('.wpfnl-product-search').on('select2:select', function(e) {
1404 var data = e.params.data;
1405 $('#upsell-original-price').val(data.price);
1406 $('#upsell-sale-price').val(data.sale_price);
1407
1408 $('#downsell-original-price').val(data.price);
1409 $('#downsell-sale-price').val(data.sale_price);
1410 });
1411 $('.wpfnl-product-search').select2(select2Args);
1412 };
1413
1414
1415 /**
1416 * initialize coupon search
1417 * for checkout
1418 *
1419 * @param event
1420 * @since 1.0.0
1421 */
1422 DataSerachHandler.prototype.initCouponSearch = function(event) {
1423 var select2Args = {
1424 minimumInputLength: 3,
1425 allowClear: true,
1426 ajax: {
1427 url: WPFunnelVars.ajaxurl,
1428 dataType: 'json',
1429 delay: 250,
1430 data: function(params) {
1431 return {
1432 term: params.term,
1433 action: 'wpfnl_coupon_search',
1434 security: WPFunnelVars.security,
1435 };
1436 },
1437 processResults: function(data) {
1438 var terms = [];
1439 if (data) {
1440 $.each(data, function(id, text) {
1441 terms.push({
1442 id: id,
1443 text: text
1444 });
1445 });
1446 }
1447 return {
1448 results: terms
1449 };
1450 },
1451 cache: true
1452 }
1453 }
1454 $('.wpfnl-discount-search').select2(select2Args);
1455 };
1456
1457
1458
1459 var AdminNotices = function() {
1460 $(document.body)
1461 .on('click', '#wpfnl-install-plugin', this.installPlugin)
1462 .on('wp-plugin-install-success', this.installSuccess)
1463 $( document ).on(
1464 'wp-plugin-install-success',
1465 self._installSuccess
1466 );
1467 };
1468 AdminNotices.prototype.installPlugin = function(e) {
1469 e.preventDefault();
1470 let slug = $(this).attr('data-slug');
1471 wp.updates.queue.push( {
1472 action: 'install-plugin', // Required action.
1473 data: {
1474 slug: slug,
1475 },
1476 } );
1477 wp.updates.queueChecker();
1478 }
1479 AdminNotices.prototype.installSuccess = function(event, response) {
1480 event.preventDefault();
1481 console.log(response)
1482 }
1483
1484
1485 new FunnelHandler();
1486 new StepHandler();
1487 new DataSerachHandler();
1488 new AdminNotices();
1489
1490 /**
1491 * funnel list show more action on click
1492 *
1493 * @since 1.0.0
1494 */
1495 $('body').on('click', function() {
1496 $('.funnel-list__more-action').removeClass('show-actions');
1497 });
1498
1499 $('.funnel-list__more-action').on('click', function(e) {
1500 e.stopPropagation();
1501 $(this).toggleClass('show-actions');
1502 $(this).parents('.funnel__single-list').siblings().find('.funnel-list__more-action').removeClass('show-actions');
1503 });
1504
1505 $('.funnel-list__more-action .wpfnl-dropdown').on('click', function(e) {
1506 e.stopPropagation();
1507 });
1508
1509
1510 /**
1511 * copy to clipboard
1512 *
1513 * @since 1.0.0
1514 */
1515 $('.wpfnl-copy-clipboard').on('click', function() {
1516 var getID = $(this).attr('data-id');
1517 var getText = $('#' + getID).val();
1518 CopyToClipboard(getText);
1519
1520 $(this).siblings('.copied-msg').text('Copied').fadeIn(500);
1521
1522 setTimeout(function() {
1523 $('.copied-msg').fadeOut('slow');
1524 }, 2500);
1525
1526 });
1527
1528 /**
1529 * copy to clipboard helper function
1530 *
1531 * @since 1.0.0
1532 */
1533 function CopyToClipboard(text) {
1534 if (window.clipboardData && window.clipboardData.setData) {
1535 return clipboardData.setData("Text", text);
1536
1537 } else if (document.queryCommandSupported && document.queryCommandSupported("copy")) {
1538 var textarea = document.createElement("textarea");
1539 textarea.textContent = text;
1540 textarea.style.position = "fixed";
1541 document.body.appendChild(textarea);
1542 textarea.select();
1543
1544 try {
1545 return document.execCommand("copy");
1546 } catch (ex) {
1547 console.warn("Copy to clipboard failed.", ex);
1548 return false;
1549 } finally {
1550 document.body.removeChild(textarea);
1551 }
1552 }
1553 }
1554
1555
1556
1557 /**
1558 * open modal when add new step
1559 *
1560 * @param event
1561 * @since 1.0.0
1562 */
1563 // $('body').on('click', function(){
1564 // $('.wpfnl-modal').fadeOut(200);
1565 // });
1566
1567 // $('#create-first-step, #add-new-step').on('click', function(e){
1568 // e.preventDefault();
1569 // e.stopPropagation();
1570 // $(this).parents('.wpfnl').find('.wpfnl-modal').fadeIn(200);
1571 // });
1572
1573 $('.wpfnl-modal-close').on('click', function(e) {
1574 e.preventDefault();
1575 $(this).parents('.wpfnl-modal').fadeOut(200);
1576 });
1577
1578 $('.wpfnl-modal__wrapper').on('click', function(e) {
1579 e.stopPropagation();
1580 });
1581
1582
1583 /**
1584 * step name change on step page
1585 *
1586 * @param event
1587 * @since 1.0.0
1588 */
1589 var stepName = '';
1590 $('.step-name-edit').on('click', function(e) {
1591 e.preventDefault();
1592 $(this).hide();
1593 stepName = $(this).parents('.title-area').find('.step-name-input').val();
1594 $(this).parents('.title-area').find('.step-name-input').show();
1595 $(this).parents('.title-area').find('.step-name-noupdate').show();
1596 $(this).parents('.title-area').find('.step-name').hide();
1597 $(this).parents('.title-area').find('.step-name-update').show();
1598 });
1599
1600 $('.step-name-update').on('click', function(e) {
1601 e.preventDefault();
1602 $(this).hide();
1603 $(this).parents('.title-area').find('.step-name-input').hide();
1604 $(this).parents('.title-area').find('.step-name-noupdate').hide();
1605 $(this).parents('.title-area').find('.step-name').show();
1606 $(this).parents('.title-area').find('.step-name-edit').show();
1607 });
1608
1609 $('.step-name-noupdate').on('click', function(e) {
1610 e.preventDefault();
1611 $(this).hide();
1612 $(this).parents('.title-area').find('.step-name-input').val(stepName).hide();
1613 $(this).parents('.title-area').find('.step-name-update').hide();
1614 $(this).parents('.title-area').find('.step-name').text(stepName).show();
1615 $(this).parents('.title-area').find('.step-name-edit').show();
1616 });
1617
1618 $('.step-name-input').keyup(function() {
1619 $(this).parents('.title-area').find('.step-name').text($(this).val());
1620 });
1621
1622
1623 /**
1624 * step settings tab
1625 *
1626 * @since 1.0.0
1627 */
1628 $('.step-settings__single-tab-content:first-child').show();
1629
1630 $(document).on("click", ".steps-settings__tab-nav:not(.ab-nav) a", function(e) {
1631 if( ! $(this).parent('li').hasClass('disabled') ){
1632 e.preventDefault();
1633 var dataID = $(this).attr('href');
1634
1635 $(this).parent('li').addClass('active').siblings().removeClass('active');
1636 $(this).parents('.steps-settings').find(dataID).show();
1637 $(this).parents('.steps-settings').find(dataID).siblings().hide();
1638 }
1639
1640 });
1641
1642
1643 /**
1644 * step settings product options tab
1645 *
1646 * @since 1.0.0
1647 */
1648 $('.product-options__tab-nav a').on('click', function(e) {
1649 e.preventDefault();
1650
1651 var dataID = $(this).attr('href');
1652 $(this).parent('li').addClass('active').siblings().removeClass('active');
1653
1654 $(this).parents('.wpfnl-product-options').find(dataID).show();
1655 $(this).parents('.wpfnl-product-options').find(dataID).siblings().hide();
1656
1657 });
1658
1659
1660 /**
1661 * wpfnl accordion
1662 *
1663 * @since 1.0.0
1664 */
1665 $('.wpfnl__accordion-content').hide();
1666 $('.wpfnl__single-accordion:first-child .wpfnl__accordion-content').show();
1667 $('.wpfnl__accordion-title').on('click', function(e) {
1668 e.preventDefault();
1669
1670 var dataID = $(this).attr('href');
1671
1672 $(this).parent('.wpfnl__single-accordion').find(dataID).slideToggle();
1673 $(this).parents('.wpfnl__single-accordion').siblings().find('.wpfnl__accordion-content').slideUp();
1674
1675 });
1676
1677
1678 /**
1679 * steps-header-hamburger toggle menu
1680 *
1681 * @since 1.0.0
1682 */
1683 $('body').on('click', function() {
1684 $('#steps-header-hamburger').removeClass('show');
1685 });
1686 // $(document).on("click", "#steps-header-hamburger", function(e) {
1687 $('#steps-header-hamburger').on('click', function(e) {
1688 e.stopPropagation();
1689 if( !$(this).hasClass( "show" ) ){
1690 $(this).removeClass('show');
1691 }else{
1692 $(this).addClass('show');
1693 }
1694
1695 wpfnlDatePicker();
1696 });
1697
1698
1699
1700 /**
1701 * wpfnl step title edit
1702 *
1703 * @param event
1704 * @since 1.0.0
1705 */
1706 function step_edit(e) {
1707 e.preventDefault();
1708 var step_id = $(this).attr("data-id");
1709 var input = $('#step-name-input-' + step_id).val();
1710 var payload = {
1711 step_id: step_id,
1712 input: input,
1713 };
1714 wpAjaxHelperRequest("step-edit", payload)
1715 .success(function(response) {
1716 $('#setp-list-' + step_id + ' .title-txt').text(input);
1717
1718 if (response.success) {
1719 console.log('success');
1720 } else {
1721 console.log(response);
1722 }
1723
1724 })
1725 .error(function(response) {
1726 console.log('error');
1727 });
1728 }
1729 $('.step-name-update').on('click', step_edit);
1730
1731 });
1732
1733 function getUrlParameter(sParam) {
1734 var sPageURL = window.location.search.substring(1),
1735 sURLVariables = sPageURL.split('&'),
1736 sParameterName,
1737 i;
1738
1739 for (i = 0; i < sURLVariables.length; i++) {
1740 sParameterName = sURLVariables[i].split('=');
1741
1742 if (sParameterName[0] === sParam) {
1743 return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
1744 }
1745 }
1746 }
1747
1748
1749 /**
1750 * settings page tab nav
1751 *
1752 * @since 1.0.0
1753 */
1754 $('.wpfn-settings__nav .nav-li:not(.disabled)').on('click', function(e) {
1755 var dataID = $(this).attr('data-id');
1756 $(this).addClass('active');
1757 $(this).siblings('.nav-li').removeClass('active');
1758
1759 $('#' + dataID).show();
1760 $('#' + dataID).siblings('.wpfnl-funnel__single-settings').hide();
1761 });
1762
1763
1764 /**
1765 * Checkout Edit Field delete alert modal
1766 *
1767 * @since 1.0.0
1768 */
1769 $(document).on("click", ".delete-checkout-field", function() {
1770 $(this).parents('.checkout__single-field').find('.wpfnl-delete-alert-wrapper').css('display', 'flex');
1771 });
1772
1773 $(document).on("click", ".wpfnl-delete-confirm-btn .cancel", function() {
1774 $(this).parents('.wpfnl-delete-alert-wrapper').hide();
1775 });
1776
1777
1778 /**
1779 * edit-field settings tab
1780 *
1781 * @since 1.0.0
1782 */
1783 $('.edit-field-settings__single-tab-content:first-child').show();
1784
1785 $(document).on("click", ".edit-field-settings__tab-nav a", function(e) {
1786 e.preventDefault();
1787 var dataID = $(this).attr('href');
1788 $(this).parent('li').addClass('active').siblings().removeClass('active');
1789 $(this).parents('.checkout-edit-field-tab__content-wrapper').find(dataID).show();
1790 $(this).parents('.checkout-edit-field-tab__content-wrapper').find(dataID).siblings().hide();
1791 });
1792
1793
1794 /**
1795 * add new checkout field drawer
1796 *
1797 * @since 1.0.0
1798 */
1799 $('.add-new-checkout-field-btn').on('click', function(e) {
1800 e.preventDefault();
1801 $(this).parents('.checkout-edit-field-tab__content-wrapper').find('.add-checkout-field-wrapper').addClass('show-drawer');
1802 });
1803
1804 $('.add-checkout-field-close').on('click', function(e) {
1805 e.preventDefault();
1806 $(this).parents('.add-checkout-field-wrapper').removeClass('show-drawer');
1807 });
1808
1809
1810 /**
1811 * edit checkout field drawer
1812 *
1813 * @since 1.0.0
1814 */
1815 // $('button.edit-field').on('click', function(e) {
1816 $(document).on("click", "button.edit-field", function(e) {
1817 e.preventDefault();
1818 $(this).parents('.checkout-edit-field-tab__content-wrapper').find('.edit-checkout-field-wrapper').addClass('show-drawer');
1819 });
1820
1821 $('.add-checkout-field-close').on('click', function(e) {
1822 e.preventDefault();
1823 $(this).parents('.edit-checkout-field-wrapper').removeClass('show-drawer');
1824 });
1825
1826
1827 /**
1828 * show edit field type options
1829 *
1830 * @since 1.0.0
1831 */
1832 $('.wpfnl-edit-field-type').on('change', function(e) {
1833 e.preventDefault();
1834 var thisVal = $(this).val();
1835
1836 if (thisVal == 'select') {
1837 $(this).parents('.field-body').find('.field-type-options').show();
1838 } else {
1839 $(this).parents('.field-body').find('.field-type-options').hide();
1840 }
1841 });
1842
1843
1844 jQuery(document).ready(function() {
1845 var selectedType = $('.wpfnl-edit-field-type').val();
1846
1847 if (selectedType == 'select') {
1848 $('.wpfnl-edit-field-type').parents('.field-body').find('.field-type-options').show();
1849 } else {
1850 $('.wpfnl-edit-field-type').parents('.field-body').find('.field-type-options').hide();
1851 }
1852
1853 });
1854
1855
1856 /**
1857 * Step preview permalink copy to clipboard
1858 *
1859 * @since 2.2.5
1860 */
1861 $(document).on("click", ".wpfnl-drawing-window .funnel-name-edit-wrapper .hints", function(e) {
1862 e.preventDefault();
1863 $(this).addClass('copy-confirmed');
1864 var $temp = $("<input>");
1865 $(this).parent('.field-group').append($temp);
1866 $temp.val($(this).parent('.field-group').find('#step-preview-link').val()).select();
1867 document.execCommand("copy");
1868 $temp.remove();
1869
1870 setTimeout(function() {
1871 $('.wpfnl-drawing-window .funnel-name-edit-wrapper .hints').removeClass('copy-confirmed');
1872 }, 1000);
1873
1874 });
1875
1876
1877 /**
1878 * rollback feature for WPF
1879 */
1880 $('select#wpfnl-rollback').on('change', function () {
1881 var $this = $(this),
1882 $rollbackButton = $this.next('.wpfnl-rollback-button'),
1883 placeholderText = $rollbackButton.data('placeholder-text'),
1884 placeholderUrl = $rollbackButton.data('placeholder-url');
1885 $rollbackButton.html(placeholderText.replace('{VERSION}', $this.val()));
1886 $rollbackButton.attr('href', placeholderUrl.replace('VERSION', $this.val()));
1887 }).trigger('change');
1888
1889
1890 $('.wpfnl-rollback-button').on('click', function (event) {
1891 event.preventDefault();
1892 var $this = $(this);
1893 if ( confirm("Are you sure?") ) {
1894 $this.addClass('show-loader');
1895 $this.addClass('loading');
1896 location.href = $this.attr('href');
1897 }
1898 });
1899
1900 // ---delete promotional-banner notice permanently ------
1901 $(document).on("click", ".wpfnl-promotional-banner .close-promotional-banner", function(event) {
1902 event.preventDefault();
1903 $('.wpfnl-promotional-banner').css('display','none');
1904 wpAjaxHelperRequest("delete_promotional_banner")
1905 });
1906
1907
1908
1909 /**
1910 * Multiple Orderbump Accordion
1911 *
1912 */
1913 $(document).on("click", ".single-order-bump .order-bump-accordion-header .title-area", function(e) {
1914 e.preventDefault();
1915 $(this).parents('.single-order-bump').siblings().removeClass('expanded-orderbump');
1916 $(this).parents('.single-order-bump').toggleClass('expanded-orderbump');
1917
1918 $(this).parents('.single-order-bump').siblings().find('.order-bump-accordion-content').removeClass('show-content');
1919 $(this).parents('.single-order-bump').find('.order-bump-accordion-content').toggleClass('show-content');
1920 });
1921
1922 //------expand last orderbump when added a new orderbump----
1923 $(document).on("click", ".order-bump-header .add-new-orderbump", function(e) {
1924 e.preventDefault();
1925 $('.single-order-bump').siblings().removeClass('expanded-orderbump');
1926 $('.single-order-bump:last-child').addClass('expanded-orderbump');
1927
1928 $('.single-order-bump').siblings().find('.order-bump-accordion-content').removeClass('show-content');
1929 $('.single-order-bump:last-child').find('.order-bump-accordion-content').addClass('show-content');
1930 });
1931
1932
1933 /**
1934 * Automatic winner choose condition dropdown
1935 *
1936 */
1937 $(document).on("click", ".automatic-winner .set-condition .selected-item", function(e) {
1938 e.preventDefault();
1939 e.stopPropagation();
1940 $(this).parents('.wpfnl-selectbox').find('.selectable-option').slideToggle(300);
1941 });
1942 $(document).on("click", "body", function() {
1943 $('.automatic-winner .set-condition .selectable-option').hide();
1944 });
1945
1946 $(document).on("click", ".automatic-winner .set-condition .selectable-option li", function(e) {
1947 e.preventDefault();
1948 var selected_item_text = $(this).text();
1949 var selected_item_data = $(this).attr('data-value');
1950
1951 $(this).siblings().removeClass('active');
1952 $(this).addClass('active');
1953 $('.automatic-winner .set-condition .selected-item').text(selected_item_text).attr('data-value', selected_item_data);
1954 });
1955
1956
1957 /**
1958 * Show step control button when clik on step (on drawflow window page)
1959 *
1960 */
1961 $(document).on("click", ".drawflow .drawflow-node .single-node", function(e) {
1962 e.stopPropagation();
1963 $(this).parents('.parent-node').siblings().find('.single-node').removeClass('im-selected-node');
1964 $(this).siblings().removeClass('im-selected-node');
1965 $(this).parent('.single-node-wrapper').siblings().find('.single-node').removeClass('im-selected-node');
1966 $(this).addClass('im-selected-node');
1967 });
1968
1969 $(document).on("click", "body", function() {
1970 $('.drawflow .drawflow-node .single-node').removeClass('im-selected-node');
1971 });
1972
1973 /**
1974 * Add list, add tag dropdown show/hide
1975 *
1976 */
1977 $(document).on("click", ".wpfnl-custom-selectbox .selectbox-selected-value", function(e) {
1978 e.stopPropagation();
1979 $(this).parents('.wpfnl-custom-selectbox').toggleClass('show-options');
1980 });
1981
1982 $(document).on("click", ".wpfnl-custom-selectbox .selectbox-options", function(e) {
1983 e.stopPropagation();
1984 });
1985
1986 $(document).on("click", "body", function() {
1987 $('.wpfnl-custom-selectbox').removeClass('show-options');
1988 });
1989
1990
1991 /**
1992 * mintmrm automation show remove icon when click on step box
1993 *
1994 */
1995 $(document).on("click", ".mintmrm-automation-step", function(e) {
1996 e.stopPropagation();
1997 $(this).siblings().removeClass('selected-step');
1998 $(this).addClass('selected-step');
1999 });
2000
2001 $(document).on("click", "body", function() {
2002 $('.mintmrm-automation-step').removeClass('selected-step');
2003 });
2004
2005
2006 /**
2007 * mintmrm automation click on step box add action
2008 *
2009 */
2010 $(document).on("click", ".add-new-action-btn", function(e) {
2011 e.stopPropagation();
2012 $(this).parents('.mintmrm-automation-step').siblings().find('.add-new-action').css('z-index', 2);
2013 // $(this).parents('.mintmrm-automation-step').siblings().find('.mrm-trigger-action-dropdown').hide();
2014 // $(this).parent('.add-new-action').find('.mrm-trigger-action-dropdown').toggle();
2015 $(this).parent('.add-new-action').css('z-index', 4);
2016 });
2017
2018
2019 /**
2020 * Funnel Bulk select action dropdown
2021 *
2022 */
2023 $(document).on("click", ".bulk-delete-toggler", function(e) {
2024 e.stopPropagation();
2025 $(this).toggleClass('show-dropdown');
2026 });
2027
2028 $(document).on("click", ".wpfnl-dropdown", function(e) {
2029 e.stopPropagation();
2030 });
2031
2032 $(document).on("click", "body", function() {
2033 $('.bulk-delete-toggler').removeClass('show-dropdown');
2034 });
2035
2036
2037 $( document ).on( 'change', 'select#wpfnl_listing_page_offset', updateFunnelListingPageOffset );
2038 function updateFunnelListingPageOffset() {
2039 const offset = $( this ).find( 'option:selected' ).val();
2040 const queryParams = new URLSearchParams(window.location.search);
2041
2042 // Set new or modify existing parameter value.
2043 queryParams.set("pageno", "1");
2044 queryParams.set("per_page", offset);
2045 // Replace current querystring with the new one.
2046 history.replaceState(null, null, "?"+queryParams.toString());
2047 location.reload();
2048 }
2049
2050 function selectedFunnelIds(params) {
2051 let ids = [];
2052 if (params.length > 0) {
2053 for (let key = 0; key < params.length; key++){
2054 const inputItem = params[key]?.id;
2055 const id = inputItem.match(/\d+/)[0]
2056 ids.push(parseInt(id))
2057 }
2058 }
2059 selectedIds = ids;
2060 }
2061
2062 /**
2063 * Funnel Bulk select checkbox on change event
2064 *
2065 */
2066 function selectedFunnelCounter(){
2067 let totalSelectedFunnel = $('input[name=funnel-list-select]:checked').length;
2068
2069 selectedFunnelIds($('input[name=funnel-list-select]:checked'));
2070
2071 if (totalSelectedFunnel > 0) {
2072 $('.funnel__single-list.list-header .bulk-action-wrapper').css('display', 'flex')
2073 } else {
2074 $('.funnel__single-list.list-header .bulk-action-wrapper').css('display', 'none')
2075 }
2076
2077 if(totalSelectedFunnel > 1){
2078 $('.funnel__single-list.list-header .bulk-action-wrapper .selected-funnel-count').text(totalSelectedFunnel + ' Funnels');
2079 }else {
2080 $('.funnel__single-list.list-header .bulk-action-wrapper .selected-funnel-count').text(totalSelectedFunnel + ' Funnel');
2081 }
2082 }
2083
2084 $(".funnel__single-list.list-body input[name=funnel-list-select]").on('change', function(){
2085 $('.funnel-list__bulk-select.select-all-funnels input[name=funnel-list__bulk-select]').prop('checked', false);
2086 selectedFunnelCounter();
2087 });
2088
2089 $(".funnel-list__bulk-select.select-all-funnels input[name=funnel-list__bulk-select]").on('change', function(){
2090 if ($(this).is(':checked')){
2091 $('.funnel__single-list.list-body input[name=funnel-list-select]').prop('checked', true);
2092 selectedFunnelCounter();
2093 }else {
2094 $('.funnel__single-list.list-header .bulk-action-wrapper').css('display', 'none');
2095 $('.funnel__single-list.list-body input[name=funnel-list-select]').prop('checked', false);
2096 }
2097 });
2098
2099
2100 /**
2101 * empty funnel page help resource show/hide.
2102 *
2103 */
2104 $(document).on("click", ".wpfnl-helpe-guide .helper-btn", function(e) {
2105 e.stopPropagation();
2106 $(this).parent('.wpfnl-canvas-helper').toggleClass('show-helpers');
2107 });
2108
2109 $(document).on("click", "body", function() {
2110 $('.wpfnl-helpe-guide .wpfnl-canvas-helper').removeClass('show-helpers');
2111 });
2112
2113
2114
2115 })(jQuery);
2116
2117
2118