@4site/engrid-scripts 0.19.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierrc.js +226 -0
- package/LICENSE +24 -0
- package/dist/a11y.d.ts +6 -0
- package/dist/a11y.js +46 -0
- package/dist/add-name-to-message.d.ts +5 -0
- package/dist/add-name-to-message.js +49 -0
- package/dist/advocacy.d.ts +7 -0
- package/dist/advocacy.js +34 -0
- package/dist/amount-label.d.ts +6 -0
- package/dist/amount-label.js +29 -0
- package/dist/app.d.ts +19 -0
- package/dist/app.js +340 -0
- package/dist/apple-pay.d.ts +13 -0
- package/dist/apple-pay.js +169 -0
- package/dist/auto-country-select.d.ts +10 -0
- package/dist/auto-country-select.js +63 -0
- package/dist/auto-year.d.ts +7 -0
- package/dist/auto-year.js +35 -0
- package/dist/autocomplete.d.ts +5 -0
- package/dist/autocomplete.js +38 -0
- package/dist/autosubmit.d.ts +5 -0
- package/dist/autosubmit.js +14 -0
- package/dist/branding-html.d.ts +14 -0
- package/dist/branding-html.js +70 -0
- package/dist/capitalize-fields.d.ts +7 -0
- package/dist/capitalize-fields.js +22 -0
- package/dist/click-to-expand.d.ts +4 -0
- package/dist/click-to-expand.js +39 -0
- package/dist/cookie.d.ts +53 -0
- package/dist/cookie.js +76 -0
- package/dist/country-disable.d.ts +4 -0
- package/dist/country-disable.js +22 -0
- package/dist/country-redirect.d.ts +7 -0
- package/dist/country-redirect.js +61 -0
- package/dist/custom-currency.d.ts +9 -0
- package/dist/custom-currency.js +112 -0
- package/dist/data-attributes.d.ts +5 -0
- package/dist/data-attributes.js +122 -0
- package/dist/data-hide.d.ts +15 -0
- package/dist/data-hide.js +66 -0
- package/dist/data-layer.d.ts +23 -0
- package/dist/data-layer.js +312 -0
- package/dist/data-replace.d.ts +26 -0
- package/dist/data-replace.js +76 -0
- package/dist/debug-hidden-fields.d.ts +4 -0
- package/dist/debug-hidden-fields.js +42 -0
- package/dist/debug-panel.d.ts +27 -0
- package/dist/debug-panel.js +508 -0
- package/dist/deprecated.d.ts +5 -0
- package/dist/deprecated.js +40 -0
- package/dist/digital-wallets.d.ts +8 -0
- package/dist/digital-wallets.js +143 -0
- package/dist/ecard-to-target.d.ts +11 -0
- package/dist/ecard-to-target.js +73 -0
- package/dist/ecard.d.ts +8 -0
- package/dist/ecard.js +61 -0
- package/dist/embedded-ecard.d.ts +18 -0
- package/dist/embedded-ecard.js +267 -0
- package/dist/en-validators.d.ts +10 -0
- package/dist/en-validators.js +89 -0
- package/dist/engrid.d.ts +49 -0
- package/dist/engrid.js +547 -0
- package/dist/event-tickets.d.ts +3 -0
- package/dist/event-tickets.js +24 -0
- package/dist/events/country.d.ts +12 -0
- package/dist/events/country.js +42 -0
- package/dist/events/donation-amount.d.ts +16 -0
- package/dist/events/donation-amount.js +119 -0
- package/dist/events/donation-frequency.d.ts +17 -0
- package/dist/events/donation-frequency.js +115 -0
- package/dist/events/en-form.d.ts +20 -0
- package/dist/events/en-form.js +52 -0
- package/dist/events/index.d.ts +6 -0
- package/dist/events/index.js +6 -0
- package/dist/events/processing-fees.d.ts +20 -0
- package/dist/events/processing-fees.js +92 -0
- package/dist/events/remember-me-events.d.ts +18 -0
- package/dist/events/remember-me-events.js +36 -0
- package/dist/exit-intent-lightbox.d.ts +14 -0
- package/dist/exit-intent-lightbox.js +145 -0
- package/dist/expand-region-name.d.ts +7 -0
- package/dist/expand-region-name.js +44 -0
- package/dist/fast-form-fill.d.ts +8 -0
- package/dist/fast-form-fill.js +75 -0
- package/dist/freshaddress.d.ts +18 -0
- package/dist/freshaddress.js +204 -0
- package/dist/give-by-select.d.ts +9 -0
- package/dist/give-by-select.js +82 -0
- package/dist/iframe.d.ts +16 -0
- package/dist/iframe.js +217 -0
- package/dist/index.d.ts +82 -0
- package/dist/index.js +84 -0
- package/dist/input-has-value-and-focus.d.ts +9 -0
- package/dist/input-has-value-and-focus.js +50 -0
- package/dist/input-placeholders.d.ts +7 -0
- package/dist/input-placeholders.js +82 -0
- package/dist/interfaces/ecard-to-target-options.d.ts +9 -0
- package/dist/interfaces/ecard-to-target-options.js +8 -0
- package/dist/interfaces/embedded-ecard-options.d.ts +8 -0
- package/dist/interfaces/embedded-ecard-options.js +7 -0
- package/dist/interfaces/exit-intent-options.d.ts +13 -0
- package/dist/interfaces/exit-intent-options.js +13 -0
- package/dist/interfaces/options.d.ts +147 -0
- package/dist/interfaces/options.js +50 -0
- package/dist/interfaces/translate-options.d.ts +7 -0
- package/dist/interfaces/translate-options.js +42 -0
- package/dist/interfaces/upsell-options.d.ts +24 -0
- package/dist/interfaces/upsell-options.js +33 -0
- package/dist/live-currency.d.ts +15 -0
- package/dist/live-currency.js +140 -0
- package/dist/live-frequency.d.ts +13 -0
- package/dist/live-frequency.js +109 -0
- package/dist/live-variables.d.ts +21 -0
- package/dist/live-variables.js +147 -0
- package/dist/loader.d.ts +10 -0
- package/dist/loader.js +175 -0
- package/dist/logger.d.ts +16 -0
- package/dist/logger.js +84 -0
- package/dist/media-attribution.d.ts +4 -0
- package/dist/media-attribution.js +66 -0
- package/dist/menu.d.ts +0 -0
- package/dist/menu.js +1 -0
- package/dist/min-max-amount.d.ts +13 -0
- package/dist/min-max-amount.js +71 -0
- package/dist/mobile-cta.d.ts +9 -0
- package/dist/mobile-cta.js +71 -0
- package/dist/modal.d.ts +19 -0
- package/dist/modal.js +129 -0
- package/dist/neverbounce.d.ts +23 -0
- package/dist/neverbounce.js +244 -0
- package/dist/other-amount.d.ts +6 -0
- package/dist/other-amount.js +70 -0
- package/dist/page-background.d.ts +7 -0
- package/dist/page-background.js +55 -0
- package/dist/plaid.d.ts +6 -0
- package/dist/plaid.js +49 -0
- package/dist/postal-code-validator.d.ts +20 -0
- package/dist/postal-code-validator.js +118 -0
- package/dist/premium-gift.d.ts +10 -0
- package/dist/premium-gift.js +115 -0
- package/dist/progress-bar.d.ts +3 -0
- package/dist/progress-bar.js +40 -0
- package/dist/remember-me.d.ts +61 -0
- package/dist/remember-me.js +358 -0
- package/dist/required-if-visible.d.ts +8 -0
- package/dist/required-if-visible.js +60 -0
- package/dist/set-attr.d.ts +4 -0
- package/dist/set-attr.js +31 -0
- package/dist/set-recurr-freq.d.ts +7 -0
- package/dist/set-recurr-freq.js +70 -0
- package/dist/show-hide-radio-checkboxes.d.ts +13 -0
- package/dist/show-hide-radio-checkboxes.js +161 -0
- package/dist/show-if-amount.d.ts +15 -0
- package/dist/show-if-amount.js +117 -0
- package/dist/show-if-present.d.ts +7 -0
- package/dist/show-if-present.js +79 -0
- package/dist/skip-link.d.ts +4 -0
- package/dist/skip-link.js +36 -0
- package/dist/src-defer.d.ts +6 -0
- package/dist/src-defer.js +70 -0
- package/dist/supporter-hub.d.ts +9 -0
- package/dist/supporter-hub.js +75 -0
- package/dist/swap-amounts.d.ts +45 -0
- package/dist/swap-amounts.js +81 -0
- package/dist/thank-you-page-conditional-content.d.ts +8 -0
- package/dist/thank-you-page-conditional-content.js +46 -0
- package/dist/ticker.d.ts +11 -0
- package/dist/ticker.js +66 -0
- package/dist/tidycontact.d.ts +46 -0
- package/dist/tidycontact.js +1202 -0
- package/dist/translate-fields.d.ts +12 -0
- package/dist/translate-fields.js +548 -0
- package/dist/universal-opt-in.d.ts +7 -0
- package/dist/universal-opt-in.js +91 -0
- package/dist/upsell-lightbox.d.ts +31 -0
- package/dist/upsell-lightbox.js +363 -0
- package/dist/url-params-to-body-attrs.d.ts +5 -0
- package/dist/url-params-to-body-attrs.js +14 -0
- package/dist/url-to-form.d.ts +7 -0
- package/dist/url-to-form.js +32 -0
- package/dist/us-only-form.d.ts +4 -0
- package/dist/us-only-form.js +30 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +1 -0
- package/dist/vgs.d.ts +16 -0
- package/dist/vgs.js +250 -0
- package/dist/welcome-back.d.ts +10 -0
- package/dist/welcome-back.js +112 -0
- package/package.json +32 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ProcessingFees } from ".";
|
|
2
|
+
import { DonationAmount } from "./events";
|
|
3
|
+
export declare class UpsellLightbox {
|
|
4
|
+
private options;
|
|
5
|
+
private overlay;
|
|
6
|
+
private _form;
|
|
7
|
+
_amount: DonationAmount;
|
|
8
|
+
_fees: ProcessingFees;
|
|
9
|
+
private _frequency;
|
|
10
|
+
private _dataLayer;
|
|
11
|
+
private _suggestAmount;
|
|
12
|
+
private logger;
|
|
13
|
+
constructor();
|
|
14
|
+
private renderLightbox;
|
|
15
|
+
private shouldRun;
|
|
16
|
+
private shouldSkip;
|
|
17
|
+
private popupOtherField;
|
|
18
|
+
private liveAmounts;
|
|
19
|
+
private liveFrequency;
|
|
20
|
+
private getUpsellAmount;
|
|
21
|
+
private shouldOpen;
|
|
22
|
+
private freqAllowed;
|
|
23
|
+
private open;
|
|
24
|
+
private setOriginalAmount;
|
|
25
|
+
private continue;
|
|
26
|
+
private close;
|
|
27
|
+
private getAmountTxt;
|
|
28
|
+
private getFrequencyTxt;
|
|
29
|
+
private checkOtherAmount;
|
|
30
|
+
private renderConversionField;
|
|
31
|
+
}
|
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
import { ENGrid, EngridLogger, ProcessingFees, UpsellOptionsDefaults, DataLayer, } from ".";
|
|
2
|
+
import { DonationAmount, DonationFrequency, EnForm } from "./events";
|
|
3
|
+
export class UpsellLightbox {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.overlay = document.createElement("div");
|
|
6
|
+
this._form = EnForm.getInstance();
|
|
7
|
+
this._amount = DonationAmount.getInstance();
|
|
8
|
+
this._fees = ProcessingFees.getInstance();
|
|
9
|
+
this._frequency = DonationFrequency.getInstance();
|
|
10
|
+
this._dataLayer = DataLayer.getInstance();
|
|
11
|
+
this._suggestAmount = 0;
|
|
12
|
+
this.logger = new EngridLogger("UpsellLightbox", "black", "pink", "🪟");
|
|
13
|
+
let options = "EngridUpsell" in window ? window.EngridUpsell : {};
|
|
14
|
+
this.options = Object.assign(Object.assign({}, UpsellOptionsDefaults), options);
|
|
15
|
+
//Disable for "applepay" via Vantiv payment method. Adding it to the array like this so it persists
|
|
16
|
+
//even if the client provides custom options.
|
|
17
|
+
this.options.disablePaymentMethods.push("applepay");
|
|
18
|
+
if (!this.shouldRun()) {
|
|
19
|
+
this.logger.log("Upsell script should NOT run");
|
|
20
|
+
// If we're not on a Donation Page, get out
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
this.overlay.id = "enModal";
|
|
24
|
+
this.overlay.classList.add("is-hidden");
|
|
25
|
+
this.overlay.classList.add("image-" + this.options.imagePosition);
|
|
26
|
+
this.renderLightbox();
|
|
27
|
+
this._form.onSubmit.subscribe(() => this.open());
|
|
28
|
+
}
|
|
29
|
+
renderLightbox() {
|
|
30
|
+
const title = this.options.title
|
|
31
|
+
.replace("{new-amount}", "<span class='upsell_suggestion'></span>")
|
|
32
|
+
.replace("{old-amount}", "<span class='upsell_amount'></span>")
|
|
33
|
+
.replace("{old-frequency}", "<span class='upsell_frequency'></span>");
|
|
34
|
+
const paragraph = this.options.paragraph
|
|
35
|
+
.replace("{new-amount}", "<span class='upsell_suggestion'></span>")
|
|
36
|
+
.replace("{old-amount}", "<span class='upsell_amount'></span>")
|
|
37
|
+
.replace("{old-frequency}", "<span class='upsell_frequency'></span>");
|
|
38
|
+
const yes = this.options.yesLabel
|
|
39
|
+
.replace("{new-amount}", "<span class='upsell_suggestion'></span>")
|
|
40
|
+
.replace("{old-amount}", "<span class='upsell_amount'></span>")
|
|
41
|
+
.replace("{old-frequency}", "<span class='upsell_frequency'></span>");
|
|
42
|
+
const no = this.options.noLabel
|
|
43
|
+
.replace("{new-amount}", "<span class='upsell_suggestion'></span>")
|
|
44
|
+
.replace("{old-amount}", "<span class='upsell_amount'></span>")
|
|
45
|
+
.replace("{old-frequency}", "<span class='upsell_frequency'></span>");
|
|
46
|
+
const markup = `
|
|
47
|
+
<div class="upsellLightboxContainer" id="goMonthly">
|
|
48
|
+
<!-- ideal image size is 480x650 pixels -->
|
|
49
|
+
<div class="background" style="background-image: url('${this.options.image}');"></div>
|
|
50
|
+
<div class="upsellLightboxContent">
|
|
51
|
+
${this.options.canClose ? `<span id="goMonthlyClose"></span>` : ``}
|
|
52
|
+
<h1>
|
|
53
|
+
${title}
|
|
54
|
+
</h1>
|
|
55
|
+
${this.options.otherAmount
|
|
56
|
+
? `
|
|
57
|
+
<div class="upsellOtherAmount">
|
|
58
|
+
<div class="upsellOtherAmountLabel">
|
|
59
|
+
<p>
|
|
60
|
+
${this.options.otherLabel}
|
|
61
|
+
</p>
|
|
62
|
+
</div>
|
|
63
|
+
<div class="upsellOtherAmountInput">
|
|
64
|
+
<input href="#" id="secondOtherField" name="secondOtherField" type="text" value="" inputmode="decimal" aria-label="Enter your custom donation amount" autocomplete="off" data-lpignore="true" aria-required="true" size="12">
|
|
65
|
+
<small>Minimum ${this.getAmountTxt(this.options.minAmount)}</small>
|
|
66
|
+
</div>
|
|
67
|
+
</div>
|
|
68
|
+
`
|
|
69
|
+
: ``}
|
|
70
|
+
|
|
71
|
+
<p>
|
|
72
|
+
${paragraph}
|
|
73
|
+
</p>
|
|
74
|
+
<!-- YES BUTTON -->
|
|
75
|
+
<div id="upsellYesButton">
|
|
76
|
+
<a class="pseduo__en__submit_button" href="#">
|
|
77
|
+
<div>
|
|
78
|
+
<span class='loader-wrapper'><span class='loader loader-quart'></span></span>
|
|
79
|
+
<span class='label'>${yes}</span>
|
|
80
|
+
</div>
|
|
81
|
+
</a>
|
|
82
|
+
</div>
|
|
83
|
+
<!-- NO BUTTON -->
|
|
84
|
+
<div id="upsellNoButton">
|
|
85
|
+
<button title="Close (Esc)" type="button">
|
|
86
|
+
<div>
|
|
87
|
+
<span class='loader-wrapper'><span class='loader loader-quart'></span></span>
|
|
88
|
+
<span class='label'>${no}</span>
|
|
89
|
+
</div>
|
|
90
|
+
</button>
|
|
91
|
+
</div>
|
|
92
|
+
</div>
|
|
93
|
+
</div>
|
|
94
|
+
`;
|
|
95
|
+
this.overlay.innerHTML = markup;
|
|
96
|
+
const closeButton = this.overlay.querySelector("#goMonthlyClose");
|
|
97
|
+
const yesButton = this.overlay.querySelector("#upsellYesButton a");
|
|
98
|
+
const noButton = this.overlay.querySelector("#upsellNoButton button");
|
|
99
|
+
yesButton.addEventListener("click", this.continue.bind(this));
|
|
100
|
+
noButton.addEventListener("click", this.continue.bind(this));
|
|
101
|
+
if (closeButton)
|
|
102
|
+
closeButton.addEventListener("click", this.close.bind(this));
|
|
103
|
+
this.overlay.addEventListener("click", (e) => {
|
|
104
|
+
if (e.target instanceof Element &&
|
|
105
|
+
e.target.id == this.overlay.id &&
|
|
106
|
+
this.options.canClose) {
|
|
107
|
+
this.close(e);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
document.addEventListener("keyup", (e) => {
|
|
111
|
+
if (e.key === "Escape" && closeButton) {
|
|
112
|
+
closeButton.click();
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
document.body.appendChild(this.overlay);
|
|
116
|
+
const otherField = document.querySelector("#secondOtherField");
|
|
117
|
+
if (otherField) {
|
|
118
|
+
otherField.addEventListener("keyup", this.popupOtherField.bind(this));
|
|
119
|
+
}
|
|
120
|
+
this.logger.log("Upsell script rendered");
|
|
121
|
+
}
|
|
122
|
+
// Should we run the script?
|
|
123
|
+
shouldRun() {
|
|
124
|
+
// if it's a first page of a Donation page
|
|
125
|
+
return (
|
|
126
|
+
// !hideModal &&
|
|
127
|
+
!this.shouldSkip() &&
|
|
128
|
+
"EngridUpsell" in window &&
|
|
129
|
+
!!window.pageJson &&
|
|
130
|
+
window.pageJson.pageNumber == 1 &&
|
|
131
|
+
["donation", "premiumgift"].includes(window.pageJson.pageType));
|
|
132
|
+
}
|
|
133
|
+
shouldSkip() {
|
|
134
|
+
if ("EngridUpsell" in window && window.EngridUpsell.skipUpsell) {
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
return this.options.skipUpsell;
|
|
138
|
+
}
|
|
139
|
+
popupOtherField() {
|
|
140
|
+
var _a, _b;
|
|
141
|
+
const value = parseFloat((_b = (_a = this.overlay.querySelector("#secondOtherField")) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : "");
|
|
142
|
+
const live_upsell_amount = document.querySelectorAll("#upsellYesButton .upsell_suggestion");
|
|
143
|
+
const upsellAmount = this.getUpsellAmount();
|
|
144
|
+
if (!isNaN(value) && value > 0) {
|
|
145
|
+
this.checkOtherAmount(value);
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
this.checkOtherAmount(upsellAmount);
|
|
149
|
+
}
|
|
150
|
+
live_upsell_amount.forEach((elem) => (elem.innerHTML = this.getAmountTxt(upsellAmount + this._fees.calculateFees(upsellAmount))));
|
|
151
|
+
}
|
|
152
|
+
liveAmounts() {
|
|
153
|
+
const live_upsell_amount = document.querySelectorAll(".upsell_suggestion");
|
|
154
|
+
const live_amount = document.querySelectorAll(".upsell_amount");
|
|
155
|
+
const upsellAmount = this.getUpsellAmount();
|
|
156
|
+
const suggestedAmount = upsellAmount + this._fees.calculateFees(upsellAmount);
|
|
157
|
+
live_upsell_amount.forEach((elem) => (elem.innerHTML = this.getAmountTxt(suggestedAmount)));
|
|
158
|
+
live_amount.forEach((elem) => (elem.innerHTML = this.getAmountTxt(this._amount.amount + this._fees.fee)));
|
|
159
|
+
}
|
|
160
|
+
liveFrequency() {
|
|
161
|
+
const live_upsell_frequency = document.querySelectorAll(".upsell_frequency");
|
|
162
|
+
live_upsell_frequency.forEach((elem) => (elem.innerHTML = this.getFrequencyTxt()));
|
|
163
|
+
}
|
|
164
|
+
// Return the Suggested Upsell Amount
|
|
165
|
+
getUpsellAmount() {
|
|
166
|
+
var _a, _b;
|
|
167
|
+
const amount = this._amount.amount;
|
|
168
|
+
const otherAmount = parseFloat((_b = (_a = this.overlay.querySelector("#secondOtherField")) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : "");
|
|
169
|
+
if (otherAmount > 0) {
|
|
170
|
+
return otherAmount > this.options.minAmount
|
|
171
|
+
? otherAmount
|
|
172
|
+
: this.options.minAmount;
|
|
173
|
+
}
|
|
174
|
+
let upsellAmount = 0;
|
|
175
|
+
for (let i = 0; i < this.options.amountRange.length; i++) {
|
|
176
|
+
let val = this.options.amountRange[i];
|
|
177
|
+
if (upsellAmount == 0 && amount <= val.max) {
|
|
178
|
+
upsellAmount = val.suggestion;
|
|
179
|
+
if (upsellAmount === 0)
|
|
180
|
+
return 0;
|
|
181
|
+
if (typeof upsellAmount !== "number") {
|
|
182
|
+
const suggestionMath = upsellAmount.replace("amount", amount.toFixed(2));
|
|
183
|
+
upsellAmount = parseFloat(Function('"use strict";return (' + suggestionMath + ")")());
|
|
184
|
+
}
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return upsellAmount > this.options.minAmount
|
|
189
|
+
? upsellAmount
|
|
190
|
+
: this.options.minAmount;
|
|
191
|
+
}
|
|
192
|
+
shouldOpen() {
|
|
193
|
+
const upsellAmount = this.getUpsellAmount();
|
|
194
|
+
const paymenttype = ENGrid.getFieldValue("transaction.paymenttype") || "";
|
|
195
|
+
this._suggestAmount = upsellAmount;
|
|
196
|
+
// If frequency is not onetime or
|
|
197
|
+
// the modal is already opened or
|
|
198
|
+
// there's no suggestion for this donation amount,
|
|
199
|
+
// we should not open
|
|
200
|
+
if (this.freqAllowed() &&
|
|
201
|
+
!this.shouldSkip() &&
|
|
202
|
+
!this.options.disablePaymentMethods.includes(paymenttype.toLowerCase()) &&
|
|
203
|
+
!this.overlay.classList.contains("is-submitting") &&
|
|
204
|
+
upsellAmount > 0) {
|
|
205
|
+
this.logger.log("Upsell Frequency " + this._frequency.frequency);
|
|
206
|
+
this.logger.log("Upsell Amount " + this._amount.amount);
|
|
207
|
+
this.logger.log("Upsell Suggested Amount " + upsellAmount);
|
|
208
|
+
return true;
|
|
209
|
+
}
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
// Return true if the current frequency is allowed by the options
|
|
213
|
+
freqAllowed() {
|
|
214
|
+
const freq = this._frequency.frequency;
|
|
215
|
+
const allowed = [];
|
|
216
|
+
if (this.options.oneTime)
|
|
217
|
+
allowed.push("onetime");
|
|
218
|
+
if (this.options.annual)
|
|
219
|
+
allowed.push("annual");
|
|
220
|
+
return allowed.includes(freq);
|
|
221
|
+
}
|
|
222
|
+
open() {
|
|
223
|
+
this.logger.log("Upsell script opened");
|
|
224
|
+
if (!this.shouldOpen()) {
|
|
225
|
+
// In the circumstance when the form fails to validate via server-side validation, the page will reload
|
|
226
|
+
// When that happens, we should place the original amount saved in sessionStorage into the upsell original amount field
|
|
227
|
+
let original = window.sessionStorage.getItem("original");
|
|
228
|
+
if (original &&
|
|
229
|
+
document.querySelectorAll(".en__errorList .en__error").length > 0) {
|
|
230
|
+
this.setOriginalAmount(original);
|
|
231
|
+
}
|
|
232
|
+
// Returning true will give the "go ahead" to submit the form
|
|
233
|
+
this._form.submit = true;
|
|
234
|
+
return true;
|
|
235
|
+
}
|
|
236
|
+
this.liveAmounts();
|
|
237
|
+
this.liveFrequency();
|
|
238
|
+
this.overlay.classList.remove("is-hidden");
|
|
239
|
+
this._form.submit = false;
|
|
240
|
+
ENGrid.setBodyData("has-lightbox", "");
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
// Set the original amount into a hidden field using the upsellOriginalGiftAmountFieldName, if provided
|
|
244
|
+
setOriginalAmount(original) {
|
|
245
|
+
if (this.options.upsellOriginalGiftAmountFieldName) {
|
|
246
|
+
let enFieldUpsellOriginalAmount = document.querySelector(".en__field__input.en__field__input--hidden[name='" +
|
|
247
|
+
this.options.upsellOriginalGiftAmountFieldName +
|
|
248
|
+
"']");
|
|
249
|
+
if (!enFieldUpsellOriginalAmount) {
|
|
250
|
+
let pageform = document.querySelector("form.en__component--page");
|
|
251
|
+
if (pageform) {
|
|
252
|
+
let input = document.createElement("input");
|
|
253
|
+
input.setAttribute("type", "hidden");
|
|
254
|
+
input.setAttribute("name", this.options.upsellOriginalGiftAmountFieldName);
|
|
255
|
+
input.classList.add("en__field__input", "en__field__input--hidden");
|
|
256
|
+
pageform.appendChild(input);
|
|
257
|
+
enFieldUpsellOriginalAmount = document.querySelector('.en__field__input.en__field__input--hidden[name="' +
|
|
258
|
+
this.options.upsellOriginalGiftAmountFieldName +
|
|
259
|
+
'"]');
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
if (enFieldUpsellOriginalAmount) {
|
|
263
|
+
// save it to a session variable just in case this page reloaded due to server-side validation error
|
|
264
|
+
window.sessionStorage.setItem("original", original);
|
|
265
|
+
enFieldUpsellOriginalAmount.setAttribute("value", original);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
// Proceed to the next page (upsold or not)
|
|
270
|
+
continue(e) {
|
|
271
|
+
var _a;
|
|
272
|
+
e.preventDefault();
|
|
273
|
+
if (e.target instanceof Element &&
|
|
274
|
+
((_a = document.querySelector("#upsellYesButton")) === null || _a === void 0 ? void 0 : _a.contains(e.target))) {
|
|
275
|
+
this.logger.success("Upsold");
|
|
276
|
+
this.setOriginalAmount(this._amount.amount.toString());
|
|
277
|
+
const upsoldAmount = this.getUpsellAmount();
|
|
278
|
+
const originalAmount = this._amount.amount;
|
|
279
|
+
this._frequency.setFrequency("monthly");
|
|
280
|
+
this._amount.setAmount(upsoldAmount);
|
|
281
|
+
this._dataLayer.addEndOfGiftProcessEvent("ENGRID_UPSELL", {
|
|
282
|
+
eventValue: true,
|
|
283
|
+
originalAmount: originalAmount,
|
|
284
|
+
upsoldAmount: upsoldAmount,
|
|
285
|
+
frequency: "monthly",
|
|
286
|
+
});
|
|
287
|
+
this._dataLayer.addEndOfGiftProcessVariable("ENGRID_UPSELL", true);
|
|
288
|
+
this._dataLayer.addEndOfGiftProcessVariable("ENGRID_UPSELL_ORIGINAL_AMOUNT", originalAmount);
|
|
289
|
+
this._dataLayer.addEndOfGiftProcessVariable("ENGRID_UPSELL_DONATION_FREQUENCY", "MONTHLY");
|
|
290
|
+
this.renderConversionField("upsellSuccess", "onetime", originalAmount, "monthly", this._suggestAmount, "monthly", upsoldAmount);
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
this.setOriginalAmount("");
|
|
294
|
+
window.sessionStorage.removeItem("original");
|
|
295
|
+
this._dataLayer.addEndOfGiftProcessVariable("ENGRID_UPSELL", false);
|
|
296
|
+
this._dataLayer.addEndOfGiftProcessVariable("ENGRID_UPSELL_DONATION_FREQUENCY", "ONE-TIME");
|
|
297
|
+
this.renderConversionField("upsellFail", this._frequency.frequency, this._amount.amount, "monthly", this._suggestAmount, this._frequency.frequency, this._amount.amount);
|
|
298
|
+
}
|
|
299
|
+
this._form.submitForm();
|
|
300
|
+
}
|
|
301
|
+
// Close the lightbox
|
|
302
|
+
close(e) {
|
|
303
|
+
e.preventDefault();
|
|
304
|
+
this.overlay.classList.add("is-hidden");
|
|
305
|
+
ENGrid.setBodyData("has-lightbox", false);
|
|
306
|
+
if (this.options.submitOnClose) {
|
|
307
|
+
this.renderConversionField("upsellFail", this._frequency.frequency, this._amount.amount, "monthly", this._suggestAmount, this._frequency.frequency, this._amount.amount);
|
|
308
|
+
this._form.submitForm();
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
this._form.dispatchError();
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
getAmountTxt(amount = 0) {
|
|
315
|
+
var _a, _b, _c, _d;
|
|
316
|
+
const symbol = (_a = ENGrid.getCurrencySymbol()) !== null && _a !== void 0 ? _a : "$";
|
|
317
|
+
const dec_separator = (_b = ENGrid.getOption("DecimalSeparator")) !== null && _b !== void 0 ? _b : ".";
|
|
318
|
+
const thousands_separator = (_c = ENGrid.getOption("ThousandsSeparator")) !== null && _c !== void 0 ? _c : "";
|
|
319
|
+
const dec_places = amount % 1 == 0 ? 0 : (_d = ENGrid.getOption("DecimalPlaces")) !== null && _d !== void 0 ? _d : 2;
|
|
320
|
+
const amountTxt = ENGrid.formatNumber(amount, dec_places, dec_separator, thousands_separator);
|
|
321
|
+
return amount > 0 ? symbol + amountTxt : "";
|
|
322
|
+
}
|
|
323
|
+
getFrequencyTxt() {
|
|
324
|
+
const freqTxt = {
|
|
325
|
+
onetime: "one-time",
|
|
326
|
+
monthly: "monthly",
|
|
327
|
+
annual: "annual",
|
|
328
|
+
};
|
|
329
|
+
const frequency = this._frequency.frequency;
|
|
330
|
+
return frequency in freqTxt ? freqTxt[frequency] : frequency;
|
|
331
|
+
}
|
|
332
|
+
checkOtherAmount(value) {
|
|
333
|
+
const otherInput = document.querySelector(".upsellOtherAmountInput");
|
|
334
|
+
if (otherInput) {
|
|
335
|
+
if (value >= this.options.minAmount) {
|
|
336
|
+
otherInput.classList.remove("is-invalid");
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
otherInput.classList.add("is-invalid");
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
renderConversionField(event, // The event that triggered the conversion
|
|
344
|
+
freq, // The frequency of the donation (onetime, monthly, annual)
|
|
345
|
+
amt, // The original amount of the donation (before the upsell)
|
|
346
|
+
sugFreq, // The suggested frequency of the upsell (monthly)
|
|
347
|
+
sugAmt, // The suggested amount of the upsell
|
|
348
|
+
subFreq, // The submitted frequency of the upsell (onetime, monthly, annual)
|
|
349
|
+
subAmt // The submitted amount of the upsell
|
|
350
|
+
) {
|
|
351
|
+
if (this.options.conversionField === "")
|
|
352
|
+
return;
|
|
353
|
+
const conversionField = document.querySelector("input[name='" + this.options.conversionField + "']") ||
|
|
354
|
+
ENGrid.createHiddenInput(this.options.conversionField);
|
|
355
|
+
if (!conversionField) {
|
|
356
|
+
this.logger.error("Could not find or create the conversion field");
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
const conversionValue = `event:${event},freq:${freq},amt:${amt},sugFreq:${sugFreq},sugAmt:${sugAmt},subFreq:${subFreq},subAmt:${subAmt}`;
|
|
360
|
+
conversionField.value = conversionValue;
|
|
361
|
+
this.logger.log(`Conversion Field ${event}`, conversionValue);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//This component adds any url parameters that begin with "data-engrid-" to the body as attributes.
|
|
2
|
+
import { ENGrid, EngridLogger } from ".";
|
|
3
|
+
export class UrlParamsToBodyAttrs {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.logger = new EngridLogger("UrlParamsToBodyAttrs", "white", "magenta", "📌");
|
|
6
|
+
this.urlParams = new URLSearchParams(document.location.search);
|
|
7
|
+
this.urlParams.forEach((value, key) => {
|
|
8
|
+
if (key.startsWith("data-engrid-")) {
|
|
9
|
+
ENGrid.setBodyData(key.split("data-engrid-")[1], value);
|
|
10
|
+
this.logger.log(`Set "${key}" on body to "${value}" from URL params`);
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Component that allows to set a field value from URL parameters
|
|
2
|
+
// Workflow:
|
|
3
|
+
// 1. Loop through all the URL parameters
|
|
4
|
+
// 2. Check if there's a match with the field name
|
|
5
|
+
// 3. If there's a match AND the field is empty, set the value
|
|
6
|
+
import { ENGrid, EngridLogger } from ".";
|
|
7
|
+
export class UrlToForm {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.logger = new EngridLogger("UrlToForm", "white", "magenta", "🔗");
|
|
10
|
+
this.urlParams = new URLSearchParams(document.location.search);
|
|
11
|
+
if (!this.shouldRun())
|
|
12
|
+
return;
|
|
13
|
+
this.urlParams.forEach((value, key) => {
|
|
14
|
+
const field = document.getElementsByName(key)[0];
|
|
15
|
+
if (field) {
|
|
16
|
+
if (!["text", "textarea"].includes(field.type) || !field.value) {
|
|
17
|
+
ENGrid.setFieldValue(key, value);
|
|
18
|
+
this.logger.log(`Set: ${key} to ${value}`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
shouldRun() {
|
|
24
|
+
return !!document.location.search && this.hasFields();
|
|
25
|
+
}
|
|
26
|
+
hasFields() {
|
|
27
|
+
const ret = [...this.urlParams.keys()].map((key) => {
|
|
28
|
+
return document.getElementsByName(key).length > 0;
|
|
29
|
+
});
|
|
30
|
+
return ret.includes(true);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This class disables the country field and fixes the country to "United States"
|
|
3
|
+
*/
|
|
4
|
+
import { ENGrid } from ".";
|
|
5
|
+
export class UsOnlyForm {
|
|
6
|
+
constructor() {
|
|
7
|
+
if (!this.shouldRun())
|
|
8
|
+
return;
|
|
9
|
+
if (!document.querySelector(".en__field--country .en__field__notice")) {
|
|
10
|
+
ENGrid.addHtml('<div class="en__field__notice"><em>Note: This action is limited to U.S. addresses.</em></div>', ".us-only-form .en__field--country .en__field__element", "after");
|
|
11
|
+
}
|
|
12
|
+
const countrySelect = ENGrid.getField("supporter.country");
|
|
13
|
+
countrySelect.setAttribute("disabled", "disabled");
|
|
14
|
+
let countryValue = "United States";
|
|
15
|
+
if ([...countrySelect.options].some((o) => o.value === "US")) {
|
|
16
|
+
countryValue = "US";
|
|
17
|
+
}
|
|
18
|
+
else if ([...countrySelect.options].some((o) => o.value === "USA")) {
|
|
19
|
+
countryValue = "USA";
|
|
20
|
+
}
|
|
21
|
+
ENGrid.setFieldValue("supporter.country", countryValue);
|
|
22
|
+
ENGrid.createHiddenInput("supporter.country", countryValue);
|
|
23
|
+
countrySelect.addEventListener("change", () => {
|
|
24
|
+
countrySelect.value = countryValue;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
shouldRun() {
|
|
28
|
+
return !!document.querySelector(".en__component--formblock.us-only-form .en__field--country");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const AppVersion = "0.19.1";
|
package/dist/version.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const AppVersion = "0.19.1";
|
package/dist/vgs.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare class VGS {
|
|
2
|
+
private logger;
|
|
3
|
+
private vgsField;
|
|
4
|
+
private options;
|
|
5
|
+
private paymentTypeField;
|
|
6
|
+
private _form;
|
|
7
|
+
private field_expiration_month;
|
|
8
|
+
private field_expiration_year;
|
|
9
|
+
constructor();
|
|
10
|
+
shouldRun(): boolean;
|
|
11
|
+
setDefaults(): void;
|
|
12
|
+
setPaymentType(): void;
|
|
13
|
+
dumpGlobalVar(): void;
|
|
14
|
+
private handleExpUpdate;
|
|
15
|
+
private validate;
|
|
16
|
+
}
|