wfonboarding.1699289814.js
4.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
(function($) {
$(function() {
function showRegistrationModal(id, message) {
console.log("Registration error message: ", message);
var content = $("#wf-onboarding-registration-" + id + "-template").clone().attr('id', null);
if (message)
content.find('.message').empty().text(message);
$.wfcolorbox({
width: (wordfenceExt.isSmallScreen ? '300px' : '500px'),
html: content[0].outerHTML,
overlayClose: false,
closeButton: false,
className: 'wf-modal'
});
}
function toggleInstallType(event) {
event.preventDefault();
event.stopPropagation();
$(event.target).parents('.wf-onboarding-registration-prompt').find('.wf-onboarding-install-type').toggle();
$.wfcolorbox.resize();
}
$(document).on('click', '.wf-onboarding-install-type-toggle', toggleInstallType);
$('.wf-onboarding-install-type-toggle').on('click', toggleInstallType);
$(document).on('input', '#wf-onboarding-email-input,#wf-onboarding-license-input', function(event) {
var context = $(event.target).parents('.wf-onboarding-registration-prompt');
context.find('.wf-onboarding-consent-group').show();
context.find('#wf-onboarding-consent-input').prop('checked', false);
});
var subscriptionOptionSelector = '.wf-onboarding-subscription-options li';
function handleSubscriptionOptionClick(event) {
var target = $(event.target);
target.parent().find('li').removeClass('wf-active').attr('aria-checked', 'false');
target.addClass('wf-active').attr('aria-checked', 'true');
event.stopPropagation();
};
$(subscriptionOptionSelector).on('click', handleSubscriptionOptionClick);
$(document).on('click', subscriptionOptionSelector, handleSubscriptionOptionClick);
$(document).on('keyup keydown', subscriptionOptionSelector, function (event) {
if (event.which == 32) {
event.preventDefault();
event.stopPropagation();
if (event.type == 'keyup')
$(event.target).trigger('click');
}
});
$(document).on('submit', '.wf-onboarding-form', function(event) {
event.preventDefault();
var context = $(this);
if (context.data('submitting'))
return;
context.data('submitting', true);
var button = context.find('button');
button.prop('disabled', true);
var enable = function (result) {
context.data('submitting', false);
button.prop('disabled', false);
if (typeof result !== 'undefined')
return result;
};
var email = context.find('#wf-onboarding-email-input').val();
var licenseKey = context.find('#wf-onboarding-license-input').val();
var subscriptionWarning = context.find('.wf-onboarding-subscription-option-required').hide();
var subscribe = false;
if (context.find('.wf-onboarding-subscription-options:visible').length) {
var subscriptionOption = context.find(subscriptionOptionSelector).filter('.wf-active');
if (!subscriptionOption.length) {
subscriptionWarning.show();
return enable(false);
}
subscribe = !!parseInt(subscriptionOption.data('value'));
}
var consent = context.find('#wf-onboarding-consent-input').prop('checked');
if (!consent)
return enable(false);
var attempt = context.data('attempt');
var optionKey = 'onboardingAttempt' + attempt;
var optionValueEmail = context.data('option-value-email');
var optionValueLicense = context.data('option-value-license');
wordfenceExt.onboardingInstallLicense(
licenseKey,
function(licenseResponse) {
wordfenceExt.setOption(
optionKey,
optionValueLicense,
function(optionResponse) {
wordfenceExt.onboardingProcessEmails(
[
email
],
subscribe,
!!consent,
function(success, error) {
if (!success) {
showRegistrationModal('error', error);
enable();
return;
}
if (licenseResponse.isPaid) {
var modalType;
if (licenseResponse.type === 'care' || licenseResponse.type === 'response') {
modalType = licenseResponse.type;
}
else {
modalType = 'premium';
}
showRegistrationModal('success-' + modalType);
}
else {
showRegistrationModal('success-free');
}
enable();
}
);
},
function() {
showRegistrationModal('error');
enable();
}
);
},
function(error) {
showRegistrationModal('error', (typeof error === 'string') ? error : null);
enable();
}
);
});
$(document).on('click', '#wf-onboarding-delay', function() {
wordfenceExt.setOption(
'onboardingDelayedAt',
$('#wf-onboarding-delay').data('timestamp'),
function() {
$('#wf-onboarding-banner').hide();
showRegistrationModal('delayed');
},
function() {
showRegistrationModal('delayed-error');
}
);
});
});
})(jQuery);