@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.
Files changed (189) hide show
  1. package/.prettierrc.js +226 -0
  2. package/LICENSE +24 -0
  3. package/dist/a11y.d.ts +6 -0
  4. package/dist/a11y.js +46 -0
  5. package/dist/add-name-to-message.d.ts +5 -0
  6. package/dist/add-name-to-message.js +49 -0
  7. package/dist/advocacy.d.ts +7 -0
  8. package/dist/advocacy.js +34 -0
  9. package/dist/amount-label.d.ts +6 -0
  10. package/dist/amount-label.js +29 -0
  11. package/dist/app.d.ts +19 -0
  12. package/dist/app.js +340 -0
  13. package/dist/apple-pay.d.ts +13 -0
  14. package/dist/apple-pay.js +169 -0
  15. package/dist/auto-country-select.d.ts +10 -0
  16. package/dist/auto-country-select.js +63 -0
  17. package/dist/auto-year.d.ts +7 -0
  18. package/dist/auto-year.js +35 -0
  19. package/dist/autocomplete.d.ts +5 -0
  20. package/dist/autocomplete.js +38 -0
  21. package/dist/autosubmit.d.ts +5 -0
  22. package/dist/autosubmit.js +14 -0
  23. package/dist/branding-html.d.ts +14 -0
  24. package/dist/branding-html.js +70 -0
  25. package/dist/capitalize-fields.d.ts +7 -0
  26. package/dist/capitalize-fields.js +22 -0
  27. package/dist/click-to-expand.d.ts +4 -0
  28. package/dist/click-to-expand.js +39 -0
  29. package/dist/cookie.d.ts +53 -0
  30. package/dist/cookie.js +76 -0
  31. package/dist/country-disable.d.ts +4 -0
  32. package/dist/country-disable.js +22 -0
  33. package/dist/country-redirect.d.ts +7 -0
  34. package/dist/country-redirect.js +61 -0
  35. package/dist/custom-currency.d.ts +9 -0
  36. package/dist/custom-currency.js +112 -0
  37. package/dist/data-attributes.d.ts +5 -0
  38. package/dist/data-attributes.js +122 -0
  39. package/dist/data-hide.d.ts +15 -0
  40. package/dist/data-hide.js +66 -0
  41. package/dist/data-layer.d.ts +23 -0
  42. package/dist/data-layer.js +312 -0
  43. package/dist/data-replace.d.ts +26 -0
  44. package/dist/data-replace.js +76 -0
  45. package/dist/debug-hidden-fields.d.ts +4 -0
  46. package/dist/debug-hidden-fields.js +42 -0
  47. package/dist/debug-panel.d.ts +27 -0
  48. package/dist/debug-panel.js +508 -0
  49. package/dist/deprecated.d.ts +5 -0
  50. package/dist/deprecated.js +40 -0
  51. package/dist/digital-wallets.d.ts +8 -0
  52. package/dist/digital-wallets.js +143 -0
  53. package/dist/ecard-to-target.d.ts +11 -0
  54. package/dist/ecard-to-target.js +73 -0
  55. package/dist/ecard.d.ts +8 -0
  56. package/dist/ecard.js +61 -0
  57. package/dist/embedded-ecard.d.ts +18 -0
  58. package/dist/embedded-ecard.js +267 -0
  59. package/dist/en-validators.d.ts +10 -0
  60. package/dist/en-validators.js +89 -0
  61. package/dist/engrid.d.ts +49 -0
  62. package/dist/engrid.js +547 -0
  63. package/dist/event-tickets.d.ts +3 -0
  64. package/dist/event-tickets.js +24 -0
  65. package/dist/events/country.d.ts +12 -0
  66. package/dist/events/country.js +42 -0
  67. package/dist/events/donation-amount.d.ts +16 -0
  68. package/dist/events/donation-amount.js +119 -0
  69. package/dist/events/donation-frequency.d.ts +17 -0
  70. package/dist/events/donation-frequency.js +115 -0
  71. package/dist/events/en-form.d.ts +20 -0
  72. package/dist/events/en-form.js +52 -0
  73. package/dist/events/index.d.ts +6 -0
  74. package/dist/events/index.js +6 -0
  75. package/dist/events/processing-fees.d.ts +20 -0
  76. package/dist/events/processing-fees.js +92 -0
  77. package/dist/events/remember-me-events.d.ts +18 -0
  78. package/dist/events/remember-me-events.js +36 -0
  79. package/dist/exit-intent-lightbox.d.ts +14 -0
  80. package/dist/exit-intent-lightbox.js +145 -0
  81. package/dist/expand-region-name.d.ts +7 -0
  82. package/dist/expand-region-name.js +44 -0
  83. package/dist/fast-form-fill.d.ts +8 -0
  84. package/dist/fast-form-fill.js +75 -0
  85. package/dist/freshaddress.d.ts +18 -0
  86. package/dist/freshaddress.js +204 -0
  87. package/dist/give-by-select.d.ts +9 -0
  88. package/dist/give-by-select.js +82 -0
  89. package/dist/iframe.d.ts +16 -0
  90. package/dist/iframe.js +217 -0
  91. package/dist/index.d.ts +82 -0
  92. package/dist/index.js +84 -0
  93. package/dist/input-has-value-and-focus.d.ts +9 -0
  94. package/dist/input-has-value-and-focus.js +50 -0
  95. package/dist/input-placeholders.d.ts +7 -0
  96. package/dist/input-placeholders.js +82 -0
  97. package/dist/interfaces/ecard-to-target-options.d.ts +9 -0
  98. package/dist/interfaces/ecard-to-target-options.js +8 -0
  99. package/dist/interfaces/embedded-ecard-options.d.ts +8 -0
  100. package/dist/interfaces/embedded-ecard-options.js +7 -0
  101. package/dist/interfaces/exit-intent-options.d.ts +13 -0
  102. package/dist/interfaces/exit-intent-options.js +13 -0
  103. package/dist/interfaces/options.d.ts +147 -0
  104. package/dist/interfaces/options.js +50 -0
  105. package/dist/interfaces/translate-options.d.ts +7 -0
  106. package/dist/interfaces/translate-options.js +42 -0
  107. package/dist/interfaces/upsell-options.d.ts +24 -0
  108. package/dist/interfaces/upsell-options.js +33 -0
  109. package/dist/live-currency.d.ts +15 -0
  110. package/dist/live-currency.js +140 -0
  111. package/dist/live-frequency.d.ts +13 -0
  112. package/dist/live-frequency.js +109 -0
  113. package/dist/live-variables.d.ts +21 -0
  114. package/dist/live-variables.js +147 -0
  115. package/dist/loader.d.ts +10 -0
  116. package/dist/loader.js +175 -0
  117. package/dist/logger.d.ts +16 -0
  118. package/dist/logger.js +84 -0
  119. package/dist/media-attribution.d.ts +4 -0
  120. package/dist/media-attribution.js +66 -0
  121. package/dist/menu.d.ts +0 -0
  122. package/dist/menu.js +1 -0
  123. package/dist/min-max-amount.d.ts +13 -0
  124. package/dist/min-max-amount.js +71 -0
  125. package/dist/mobile-cta.d.ts +9 -0
  126. package/dist/mobile-cta.js +71 -0
  127. package/dist/modal.d.ts +19 -0
  128. package/dist/modal.js +129 -0
  129. package/dist/neverbounce.d.ts +23 -0
  130. package/dist/neverbounce.js +244 -0
  131. package/dist/other-amount.d.ts +6 -0
  132. package/dist/other-amount.js +70 -0
  133. package/dist/page-background.d.ts +7 -0
  134. package/dist/page-background.js +55 -0
  135. package/dist/plaid.d.ts +6 -0
  136. package/dist/plaid.js +49 -0
  137. package/dist/postal-code-validator.d.ts +20 -0
  138. package/dist/postal-code-validator.js +118 -0
  139. package/dist/premium-gift.d.ts +10 -0
  140. package/dist/premium-gift.js +115 -0
  141. package/dist/progress-bar.d.ts +3 -0
  142. package/dist/progress-bar.js +40 -0
  143. package/dist/remember-me.d.ts +61 -0
  144. package/dist/remember-me.js +358 -0
  145. package/dist/required-if-visible.d.ts +8 -0
  146. package/dist/required-if-visible.js +60 -0
  147. package/dist/set-attr.d.ts +4 -0
  148. package/dist/set-attr.js +31 -0
  149. package/dist/set-recurr-freq.d.ts +7 -0
  150. package/dist/set-recurr-freq.js +70 -0
  151. package/dist/show-hide-radio-checkboxes.d.ts +13 -0
  152. package/dist/show-hide-radio-checkboxes.js +161 -0
  153. package/dist/show-if-amount.d.ts +15 -0
  154. package/dist/show-if-amount.js +117 -0
  155. package/dist/show-if-present.d.ts +7 -0
  156. package/dist/show-if-present.js +79 -0
  157. package/dist/skip-link.d.ts +4 -0
  158. package/dist/skip-link.js +36 -0
  159. package/dist/src-defer.d.ts +6 -0
  160. package/dist/src-defer.js +70 -0
  161. package/dist/supporter-hub.d.ts +9 -0
  162. package/dist/supporter-hub.js +75 -0
  163. package/dist/swap-amounts.d.ts +45 -0
  164. package/dist/swap-amounts.js +81 -0
  165. package/dist/thank-you-page-conditional-content.d.ts +8 -0
  166. package/dist/thank-you-page-conditional-content.js +46 -0
  167. package/dist/ticker.d.ts +11 -0
  168. package/dist/ticker.js +66 -0
  169. package/dist/tidycontact.d.ts +46 -0
  170. package/dist/tidycontact.js +1202 -0
  171. package/dist/translate-fields.d.ts +12 -0
  172. package/dist/translate-fields.js +548 -0
  173. package/dist/universal-opt-in.d.ts +7 -0
  174. package/dist/universal-opt-in.js +91 -0
  175. package/dist/upsell-lightbox.d.ts +31 -0
  176. package/dist/upsell-lightbox.js +363 -0
  177. package/dist/url-params-to-body-attrs.d.ts +5 -0
  178. package/dist/url-params-to-body-attrs.js +14 -0
  179. package/dist/url-to-form.d.ts +7 -0
  180. package/dist/url-to-form.js +32 -0
  181. package/dist/us-only-form.d.ts +4 -0
  182. package/dist/us-only-form.js +30 -0
  183. package/dist/version.d.ts +1 -0
  184. package/dist/version.js +1 -0
  185. package/dist/vgs.d.ts +16 -0
  186. package/dist/vgs.js +250 -0
  187. package/dist/welcome-back.d.ts +10 -0
  188. package/dist/welcome-back.js +112 -0
  189. 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,5 @@
1
+ export declare class UrlParamsToBodyAttrs {
2
+ private logger;
3
+ private urlParams;
4
+ constructor();
5
+ }
@@ -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,7 @@
1
+ export declare class UrlToForm {
2
+ private logger;
3
+ private urlParams;
4
+ constructor();
5
+ private shouldRun;
6
+ private hasFields;
7
+ }
@@ -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,4 @@
1
+ export declare class UsOnlyForm {
2
+ constructor();
3
+ private shouldRun;
4
+ }
@@ -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";
@@ -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
+ }