| 1 |
(function ($, window) { |
| 2 |
'use strict'; |
| 3 |
|
| 4 |
var data = window.wpfnlReviewPromptData || {}; |
| 5 |
var minChars = parseInt(data.minChars, 10); |
| 6 |
|
| 7 |
if (isNaN(minChars) || minChars <= 0) { |
| 8 |
minChars = 50; |
| 9 |
} |
| 10 |
|
| 11 |
var errorMessage = data.errorMessage || ('Please share at least ' + minChars + ' characters so we can understand what needs improvement and make things better for you and other users.'); |
| 12 |
var ajaxUrl = data.ajaxUrl || (typeof window.ajaxurl !== 'undefined' ? window.ajaxurl : ''); |
| 13 |
|
| 14 |
$(function () { |
| 15 |
var selectedFeedbackType = ''; |
| 16 |
|
| 17 |
setTimeout(function () { |
| 18 |
$('#wpfnl-review-prompt').fadeIn(); |
| 19 |
}, 2000); |
| 20 |
|
| 21 |
function sendAction(actionType, feedback, feedbackType) { |
| 22 |
if (!ajaxUrl) { |
| 23 |
return; |
| 24 |
} |
| 25 |
|
| 26 |
$.post(ajaxUrl, { |
| 27 |
action: 'wpfnl_review_action', |
| 28 |
wpfnl_action_type: actionType, |
| 29 |
feedback: feedback || '', |
| 30 |
feedback_type: feedbackType || '', |
| 31 |
nonce: data.nonce || '' |
| 32 |
}); |
| 33 |
} |
| 34 |
|
| 35 |
$('#wpfnl-review-close').on('click', function () { |
| 36 |
$('#wpfnl-review-prompt').fadeOut(); |
| 37 |
sendAction('snooze'); |
| 38 |
}); |
| 39 |
|
| 40 |
$('#wpfnl-review-yes').on('click', function () { |
| 41 |
$('#wpfnl-review-prompt').fadeOut(); |
| 42 |
sendAction('completed'); |
| 43 |
}); |
| 44 |
|
| 45 |
$('#wpfnl-review-okay, #wpfnl-review-no').on('click', function () { |
| 46 |
$(this).addClass('selected').siblings().removeClass('selected'); |
| 47 |
$('#wpfnl-review-text').text('Sorry to hear that! What could we do better?'); |
| 48 |
$('#wpfnl-feedback-form').fadeIn(); |
| 49 |
selectedFeedbackType = $(this).attr('data-feedback-type') || ''; |
| 50 |
}); |
| 51 |
|
| 52 |
$('#wpfnl-feedback-cancel').on('click', function () { |
| 53 |
$('#wpfnl-feedback-form').hide(); |
| 54 |
$('#wpfnl-review-options').fadeIn(); |
| 55 |
$('#wpfnl-review-text').text('Is WPFunnels helping you grow your WooCommerce store?'); |
| 56 |
$('#wpfnl-feedback-text').val(''); |
| 57 |
$('#wpfnl-char-count').text('0'); |
| 58 |
$('#wpfnl-char-counter').css('color', '#58151c'); |
| 59 |
$('#wpfnl-feedback-error').remove(); |
| 60 |
$('.wpfnl-review-btn').removeClass('selected'); |
| 61 |
selectedFeedbackType = ''; |
| 62 |
}); |
| 63 |
|
| 64 |
$('#wpfnl-feedback-text').on('input', function () { |
| 65 |
var len = $(this).val().trim().length; |
| 66 |
$('#wpfnl-char-count').text(len); |
| 67 |
$('#wpfnl-feedback-error').hide(); |
| 68 |
|
| 69 |
if (len >= minChars) { |
| 70 |
$('#wpfnl-char-counter').css('color', '#00a32a'); |
| 71 |
} else { |
| 72 |
$('#wpfnl-char-counter').css('color', '#d14957'); |
| 73 |
} |
| 74 |
}); |
| 75 |
|
| 76 |
$('#wpfnl-feedback-submit').on('click', function () { |
| 77 |
var feedback = $('#wpfnl-feedback-text').val(); |
| 78 |
|
| 79 |
if (feedback.trim().length < minChars) { |
| 80 |
if ($('#wpfnl-feedback-error').length === 0) { |
| 81 |
$('#wpfnl-char-counter').after('<div id="wpfnl-feedback-error" style="background-color: #fcf0f1; border-left: 3px solid #d63638; padding: 10px 12px; font-size: 12px; color: #d63638; line-height: 1.4; margin-bottom: 12px; border-radius: 0 3px 3px 0; margin-top: 3px;">' + errorMessage + '</div>'); |
| 82 |
} else { |
| 83 |
$('#wpfnl-feedback-error').text(errorMessage).show(); |
| 84 |
} |
| 85 |
|
| 86 |
return; |
| 87 |
} |
| 88 |
|
| 89 |
$(this).text('Submitting...').prop('disabled', true); |
| 90 |
sendAction('feedback', feedback, selectedFeedbackType); |
| 91 |
|
| 92 |
setTimeout(function () { |
| 93 |
$('#wpfnl-review-prompt').fadeOut(); |
| 94 |
}, 500); |
| 95 |
}); |
| 96 |
}); |
| 97 |
})(jQuery, window); |
| 98 |
|