@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
package/dist/app.js
ADDED
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
import { DonationAmount, DonationFrequency, EnForm, ProcessingFees, Country, } from "./events";
|
|
2
|
+
import { AmountLabel, Loader, ProgressBar, UpsellLightbox, ENGrid, OptionsDefaults, setRecurrFreq, PageBackground, MediaAttribution, ApplePay, A11y, CapitalizeFields, Ecard, ClickToExpand, Advocacy, DataAttributes, LiveVariables, iFrame, InputPlaceholders, InputHasValueAndFocus, ShowHideRadioCheckboxes, AutoCountrySelect, SkipToMainContentLink, SrcDefer, NeverBounce, AutoYear, Autocomplete, RememberMe, TranslateFields, ShowIfAmount, EngridLogger, OtherAmount, MinMaxAmount, Ticker, DataReplace, DataHide, AddNameToMessage, ExpandRegionName, AppVersion, UrlToForm, RequiredIfVisible, TidyContact, DataLayer, LiveCurrency, Autosubmit, EventTickets, SwapAmounts, DebugPanel, DebugHiddenFields, FreshAddress, BrandingHtml, CountryDisable, PremiumGift, DigitalWallets, MobileCTA, LiveFrequency, UniversalOptIn, Plaid, GiveBySelect, UrlParamsToBodyAttrs, ExitIntentLightbox, SupporterHub, FastFormFill, SetAttr, ShowIfPresent, ENValidators, CustomCurrency, VGS, PostalCodeValidator, CountryRedirect, WelcomeBack, EcardToTarget, UsOnlyForm, ThankYouPageConditionalContent, EmbeddedEcard, } from ".";
|
|
3
|
+
export class App extends ENGrid {
|
|
4
|
+
constructor(options) {
|
|
5
|
+
super();
|
|
6
|
+
// Events
|
|
7
|
+
this._form = EnForm.getInstance();
|
|
8
|
+
this._fees = ProcessingFees.getInstance();
|
|
9
|
+
this._amount = DonationAmount.getInstance("transaction.donationAmt", "transaction.donationAmt.other");
|
|
10
|
+
this._frequency = DonationFrequency.getInstance();
|
|
11
|
+
this._country = Country.getInstance();
|
|
12
|
+
this.logger = new EngridLogger("App", "black", "white", "🍏");
|
|
13
|
+
const loader = new Loader();
|
|
14
|
+
this.options = Object.assign(Object.assign({}, OptionsDefaults), options);
|
|
15
|
+
// Add Options to window
|
|
16
|
+
window.EngridOptions = this.options;
|
|
17
|
+
this._dataLayer = DataLayer.getInstance();
|
|
18
|
+
// If there's a ?pbedit query string, redirect to the page builder to edit on EN
|
|
19
|
+
if (ENGrid.getUrlParameter("pbedit") === true ||
|
|
20
|
+
ENGrid.getUrlParameter("pbedit") === "true") {
|
|
21
|
+
window.location.href = `https://${ENGrid.getDataCenter()}.engagingnetworks.app/index.html#pages/${ENGrid.getPageID()}/edit`;
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (loader.reload())
|
|
25
|
+
return;
|
|
26
|
+
// Turn Debug ON if you use local assets
|
|
27
|
+
if (ENGrid.getBodyData("assets") === "local" &&
|
|
28
|
+
ENGrid.getUrlParameter("debug") !== "false" &&
|
|
29
|
+
ENGrid.getUrlParameter("debug") !== "log") {
|
|
30
|
+
window.EngridOptions.Debug = true;
|
|
31
|
+
}
|
|
32
|
+
// Document Load
|
|
33
|
+
if (document.readyState !== "loading") {
|
|
34
|
+
this.run();
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
document.addEventListener("DOMContentLoaded", () => {
|
|
38
|
+
this.run();
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
// Window Resize
|
|
42
|
+
window.onresize = () => {
|
|
43
|
+
this.onResize();
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
run() {
|
|
47
|
+
if (!ENGrid.checkNested(window.EngagingNetworks, "require", "_defined", "enjs")) {
|
|
48
|
+
this.logger.danger("Engaging Networks JS Framework NOT FOUND");
|
|
49
|
+
setTimeout(() => {
|
|
50
|
+
this.run();
|
|
51
|
+
}, 100);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
// If there's an option object on the page, override the defaults
|
|
55
|
+
if (window.hasOwnProperty("EngridPageOptions")) {
|
|
56
|
+
this.options = Object.assign(Object.assign({}, this.options), window.EngridPageOptions);
|
|
57
|
+
// Add Options to window
|
|
58
|
+
window.EngridOptions = this.options;
|
|
59
|
+
}
|
|
60
|
+
// If there's no pageJson.pageType, add a big red warning to the console
|
|
61
|
+
if (!ENGrid.checkNested(window, "pageJson", "pageType")) {
|
|
62
|
+
window.setTimeout(() => {
|
|
63
|
+
console.log("%c ⛔️ pageJson.pageType NOT FOUND - Go to the Account Settings and Expose the Transaction Details %s", "background-color: red; color: white; font-size: 22px; font-weight: bold;", "https://knowledge.engagingnetworks.net/datareports/expose-transaction-details-pagejson");
|
|
64
|
+
}, 2000);
|
|
65
|
+
}
|
|
66
|
+
if (this.options.Debug || App.getUrlParameter("debug") == "true")
|
|
67
|
+
// Enable debug if available is the first thing
|
|
68
|
+
App.setBodyData("debug", "");
|
|
69
|
+
new Advocacy();
|
|
70
|
+
new InputPlaceholders();
|
|
71
|
+
new InputHasValueAndFocus();
|
|
72
|
+
new ShowHideRadioCheckboxes("transaction.giveBySelect", "giveBySelect-");
|
|
73
|
+
new ShowHideRadioCheckboxes("transaction.inmem", "inmem-");
|
|
74
|
+
new ShowHideRadioCheckboxes("transaction.recurrpay", "recurrpay-");
|
|
75
|
+
// Automatically show/hide all radios
|
|
76
|
+
let radioFields = [];
|
|
77
|
+
const allRadios = document.querySelectorAll("input[type=radio]");
|
|
78
|
+
allRadios.forEach((radio) => {
|
|
79
|
+
if ("name" in radio && radioFields.includes(radio.name) === false) {
|
|
80
|
+
radioFields.push(radio.name);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
radioFields.forEach((field) => {
|
|
84
|
+
new ShowHideRadioCheckboxes(field, "engrid__" + field.replace(/\./g, "") + "-");
|
|
85
|
+
});
|
|
86
|
+
// Automatically show/hide all checkboxes
|
|
87
|
+
const allCheckboxes = document.querySelectorAll("input[type=checkbox]");
|
|
88
|
+
allCheckboxes.forEach((checkbox) => {
|
|
89
|
+
if ("name" in checkbox) {
|
|
90
|
+
new ShowHideRadioCheckboxes(checkbox.name, "engrid__" + checkbox.name.replace(/\./g, "") + "-");
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
// Client onSubmit and onError functions
|
|
94
|
+
this._form.onSubmit.subscribe(() => this.onSubmit());
|
|
95
|
+
this._form.onError.subscribe(() => this.onError());
|
|
96
|
+
this._form.onValidate.subscribe(() => this.onValidate());
|
|
97
|
+
// Event Listener Examples
|
|
98
|
+
this._amount.onAmountChange.subscribe((s) => this.logger.success(`Live Amount: ${s}`));
|
|
99
|
+
this._frequency.onFrequencyChange.subscribe((s) => {
|
|
100
|
+
this.logger.success(`Live Frequency: ${s}`);
|
|
101
|
+
setTimeout(() => {
|
|
102
|
+
this._amount.load();
|
|
103
|
+
}, 150);
|
|
104
|
+
});
|
|
105
|
+
this._form.onSubmit.subscribe((s) => this.logger.success("Submit: " + JSON.stringify(s)));
|
|
106
|
+
this._form.onError.subscribe((s) => this.logger.danger("Error: " + JSON.stringify(s)));
|
|
107
|
+
this._country.onCountryChange.subscribe((s) => this.logger.success(`Country: ${s}`));
|
|
108
|
+
window.enOnSubmit = () => {
|
|
109
|
+
this._form.submit = true;
|
|
110
|
+
this._form.submitPromise = false;
|
|
111
|
+
this._form.dispatchSubmit();
|
|
112
|
+
ENGrid.watchForError(ENGrid.enableSubmit);
|
|
113
|
+
if (!this._form.submit)
|
|
114
|
+
return false;
|
|
115
|
+
if (this._form.submitPromise)
|
|
116
|
+
return this._form.submitPromise;
|
|
117
|
+
this.logger.success("enOnSubmit Success");
|
|
118
|
+
// If all validation passes, we'll watch for Digital Wallets Errors, which
|
|
119
|
+
// will not reload the page (thanks EN), so we will enable the submit button if
|
|
120
|
+
// an error is programmatically thrown by the Digital Wallets
|
|
121
|
+
return true;
|
|
122
|
+
};
|
|
123
|
+
window.enOnError = () => {
|
|
124
|
+
this._form.dispatchError();
|
|
125
|
+
};
|
|
126
|
+
window.enOnValidate = () => {
|
|
127
|
+
this._form.validate = true;
|
|
128
|
+
this._form.validatePromise = false;
|
|
129
|
+
this._form.dispatchValidate();
|
|
130
|
+
if (!this._form.validate)
|
|
131
|
+
return false;
|
|
132
|
+
if (this._form.validatePromise)
|
|
133
|
+
return this._form.validatePromise;
|
|
134
|
+
this.logger.success("Validation Passed");
|
|
135
|
+
return true;
|
|
136
|
+
};
|
|
137
|
+
new DataAttributes();
|
|
138
|
+
// Country Redirect
|
|
139
|
+
new CountryRedirect();
|
|
140
|
+
// iFrame Logic
|
|
141
|
+
new iFrame();
|
|
142
|
+
// Live Variables
|
|
143
|
+
new LiveVariables(this.options);
|
|
144
|
+
// Dynamically set Recurrency Frequency
|
|
145
|
+
new setRecurrFreq();
|
|
146
|
+
// Upsell Lightbox
|
|
147
|
+
new UpsellLightbox();
|
|
148
|
+
// Amount Labels
|
|
149
|
+
new AmountLabel();
|
|
150
|
+
// Engrid Data Replacement
|
|
151
|
+
new DataReplace();
|
|
152
|
+
// ENgrid Hide Script
|
|
153
|
+
new DataHide();
|
|
154
|
+
// Autosubmit script
|
|
155
|
+
new Autosubmit();
|
|
156
|
+
// Adjust display of event tickets.
|
|
157
|
+
new EventTickets();
|
|
158
|
+
// Swap Amounts
|
|
159
|
+
new SwapAmounts();
|
|
160
|
+
// On the end of the script, after all subscribers defined, let's load the current frequency
|
|
161
|
+
// The amount will be loaded by the frequency change event
|
|
162
|
+
// This timeout is needed because when you have alternative amounts, EN is slower than Engrid
|
|
163
|
+
// about 20% of the time and we get a race condition if the client is also using the SwapAmounts feature
|
|
164
|
+
window.setTimeout(() => {
|
|
165
|
+
this._frequency.load();
|
|
166
|
+
}, 1000);
|
|
167
|
+
// Fast Form Fill
|
|
168
|
+
new FastFormFill();
|
|
169
|
+
// Currency Related Components
|
|
170
|
+
new LiveCurrency();
|
|
171
|
+
new CustomCurrency();
|
|
172
|
+
// Auto Country Select
|
|
173
|
+
new AutoCountrySelect();
|
|
174
|
+
// Add Image Attribution
|
|
175
|
+
if (this.options.MediaAttribution)
|
|
176
|
+
new MediaAttribution();
|
|
177
|
+
// Apple Pay
|
|
178
|
+
if (this.options.applePay)
|
|
179
|
+
new ApplePay();
|
|
180
|
+
// Capitalize Fields
|
|
181
|
+
if (this.options.CapitalizeFields)
|
|
182
|
+
new CapitalizeFields();
|
|
183
|
+
// Auto Year Class
|
|
184
|
+
if (this.options.AutoYear)
|
|
185
|
+
new AutoYear();
|
|
186
|
+
// Autocomplete Class
|
|
187
|
+
new Autocomplete();
|
|
188
|
+
// Ecard Class
|
|
189
|
+
new Ecard();
|
|
190
|
+
// Click To Expand
|
|
191
|
+
if (this.options.ClickToExpand)
|
|
192
|
+
new ClickToExpand();
|
|
193
|
+
if (this.options.SkipToMainContentLink)
|
|
194
|
+
new SkipToMainContentLink();
|
|
195
|
+
if (this.options.SrcDefer)
|
|
196
|
+
new SrcDefer();
|
|
197
|
+
// Progress Bar
|
|
198
|
+
if (this.options.ProgressBar)
|
|
199
|
+
new ProgressBar();
|
|
200
|
+
// RememberMe
|
|
201
|
+
try {
|
|
202
|
+
// Accessing window.localStorage will throw an exception if it isn't permitted due to security reasons
|
|
203
|
+
// For example, this happens in Firefox when cookies are disabled. If it isn't available, we shouldn't
|
|
204
|
+
// bother with enabling RememberMe
|
|
205
|
+
if (this.options.RememberMe &&
|
|
206
|
+
typeof this.options.RememberMe === "object" &&
|
|
207
|
+
window.localStorage) {
|
|
208
|
+
new RememberMe(this.options.RememberMe);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
catch (e) { }
|
|
212
|
+
if (this.options.NeverBounceAPI)
|
|
213
|
+
new NeverBounce(this.options.NeverBounceAPI, this.options.NeverBounceDateField, this.options.NeverBounceStatusField, this.options.NeverBounceDateFormat);
|
|
214
|
+
// FreshAddress
|
|
215
|
+
if (this.options.FreshAddress)
|
|
216
|
+
new FreshAddress();
|
|
217
|
+
new ShowIfAmount();
|
|
218
|
+
new OtherAmount();
|
|
219
|
+
new MinMaxAmount();
|
|
220
|
+
new Ticker();
|
|
221
|
+
new A11y();
|
|
222
|
+
new AddNameToMessage();
|
|
223
|
+
new ExpandRegionName();
|
|
224
|
+
// Page Background
|
|
225
|
+
new PageBackground();
|
|
226
|
+
// Url Params to Form Fields
|
|
227
|
+
new UrlToForm();
|
|
228
|
+
// Required if Visible Fields
|
|
229
|
+
new RequiredIfVisible();
|
|
230
|
+
// EN Custom Validators (behind a feature flag, off by default)
|
|
231
|
+
new ENValidators();
|
|
232
|
+
//Debug hidden fields
|
|
233
|
+
if (this.options.Debug)
|
|
234
|
+
new DebugHiddenFields();
|
|
235
|
+
// TidyContact
|
|
236
|
+
if (this.options.TidyContact)
|
|
237
|
+
new TidyContact();
|
|
238
|
+
// Translate Fields
|
|
239
|
+
if (this.options.TranslateFields)
|
|
240
|
+
new TranslateFields();
|
|
241
|
+
// Country Disable
|
|
242
|
+
new CountryDisable();
|
|
243
|
+
// Premium Gift Features
|
|
244
|
+
new PremiumGift();
|
|
245
|
+
// Supporter Hub Features
|
|
246
|
+
new SupporterHub();
|
|
247
|
+
// Digital Wallets Features
|
|
248
|
+
if (ENGrid.getPageType() === "DONATION") {
|
|
249
|
+
new DigitalWallets();
|
|
250
|
+
}
|
|
251
|
+
// Mobile CTA
|
|
252
|
+
new MobileCTA();
|
|
253
|
+
// Live Frequency
|
|
254
|
+
new LiveFrequency();
|
|
255
|
+
// Universal Opt In
|
|
256
|
+
new UniversalOptIn();
|
|
257
|
+
// Plaid
|
|
258
|
+
if (this.options.Plaid)
|
|
259
|
+
new Plaid();
|
|
260
|
+
// Give By Select
|
|
261
|
+
new GiveBySelect();
|
|
262
|
+
//Exit Intent Lightbox
|
|
263
|
+
new ExitIntentLightbox();
|
|
264
|
+
new UrlParamsToBodyAttrs();
|
|
265
|
+
new SetAttr();
|
|
266
|
+
new ShowIfPresent();
|
|
267
|
+
new PostalCodeValidator();
|
|
268
|
+
// Very Good Security
|
|
269
|
+
new VGS();
|
|
270
|
+
new WelcomeBack();
|
|
271
|
+
new EcardToTarget();
|
|
272
|
+
new UsOnlyForm();
|
|
273
|
+
new ThankYouPageConditionalContent();
|
|
274
|
+
new EmbeddedEcard();
|
|
275
|
+
//Debug panel
|
|
276
|
+
let showDebugPanel = this.options.Debug;
|
|
277
|
+
try {
|
|
278
|
+
// accessing storage can throw an exception if it isn't available in Firefox
|
|
279
|
+
if (!showDebugPanel &&
|
|
280
|
+
window.sessionStorage.hasOwnProperty(DebugPanel.debugSessionStorageKey)) {
|
|
281
|
+
showDebugPanel = true;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
catch (e) { }
|
|
285
|
+
if (showDebugPanel) {
|
|
286
|
+
new DebugPanel(this.options.PageLayouts);
|
|
287
|
+
}
|
|
288
|
+
if (ENGrid.getUrlParameter("development") === "branding") {
|
|
289
|
+
new BrandingHtml().show();
|
|
290
|
+
}
|
|
291
|
+
ENGrid.setBodyData("data-engrid-js-loading", "finished");
|
|
292
|
+
window.EngridVersion = AppVersion;
|
|
293
|
+
this.logger.success(`VERSION: ${AppVersion}`);
|
|
294
|
+
// Window Load
|
|
295
|
+
let onLoad = typeof window.onload === "function" ? window.onload : null;
|
|
296
|
+
if (document.readyState !== "loading") {
|
|
297
|
+
this.onLoad();
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
window.onload = (e) => {
|
|
301
|
+
this.onLoad();
|
|
302
|
+
if (onLoad) {
|
|
303
|
+
onLoad.bind(window, e);
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
onLoad() {
|
|
309
|
+
if (this.options.onLoad) {
|
|
310
|
+
this.options.onLoad();
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
onResize() {
|
|
314
|
+
if (this.options.onResize) {
|
|
315
|
+
this.options.onResize();
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
onValidate() {
|
|
319
|
+
if (this.options.onValidate) {
|
|
320
|
+
this.logger.log("Client onValidate Triggered");
|
|
321
|
+
this.options.onValidate();
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
onSubmit() {
|
|
325
|
+
if (this.options.onSubmit) {
|
|
326
|
+
this.logger.log("Client onSubmit Triggered");
|
|
327
|
+
this.options.onSubmit();
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
onError() {
|
|
331
|
+
if (this.options.onError) {
|
|
332
|
+
this.logger.danger("Client onError Triggered");
|
|
333
|
+
this.options.onError();
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
static log(message) {
|
|
337
|
+
const logger = new EngridLogger("Client", "brown", "aliceblue", "🍪");
|
|
338
|
+
logger.log(message);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { EnForm, DonationAmount, ProcessingFees } from ".";
|
|
2
|
+
export declare class ApplePay {
|
|
3
|
+
applePay: HTMLInputElement;
|
|
4
|
+
_amount: DonationAmount;
|
|
5
|
+
_fees: ProcessingFees;
|
|
6
|
+
_form: EnForm;
|
|
7
|
+
constructor();
|
|
8
|
+
private checkApplePay;
|
|
9
|
+
performValidation(url: string): Promise<unknown>;
|
|
10
|
+
private log;
|
|
11
|
+
sendPaymentToken(token: any): Promise<unknown>;
|
|
12
|
+
private onPayClicked;
|
|
13
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { EnForm, DonationAmount, ENGrid, ProcessingFees } from ".";
|
|
11
|
+
/*global window */
|
|
12
|
+
const ApplePaySession = window.ApplePaySession;
|
|
13
|
+
const merchantIdentifier = window.merchantIdentifier;
|
|
14
|
+
const merchantDomainName = window.merchantDomainName;
|
|
15
|
+
const merchantDisplayName = window.merchantDisplayName;
|
|
16
|
+
const merchantSessionIdentifier = window.merchantSessionIdentifier;
|
|
17
|
+
const merchantNonce = window.merchantNonce;
|
|
18
|
+
const merchantEpochTimestamp = window.merchantEpochTimestamp;
|
|
19
|
+
const merchantSignature = window.merchantSignature;
|
|
20
|
+
const merchantCountryCode = window.merchantCountryCode;
|
|
21
|
+
const merchantCurrencyCode = window.merchantCurrencyCode;
|
|
22
|
+
const merchantSupportedNetworks = window.merchantSupportedNetworks;
|
|
23
|
+
const merchantCapabilities = window.merchantCapabilities;
|
|
24
|
+
const merchantTotalLabel = window.merchantTotalLabel;
|
|
25
|
+
export class ApplePay {
|
|
26
|
+
constructor() {
|
|
27
|
+
this.applePay = document.querySelector('.en__field__input.en__field__input--radio[value="applepay"]');
|
|
28
|
+
this._amount = DonationAmount.getInstance();
|
|
29
|
+
this._fees = ProcessingFees.getInstance();
|
|
30
|
+
this._form = EnForm.getInstance();
|
|
31
|
+
this.checkApplePay();
|
|
32
|
+
}
|
|
33
|
+
checkApplePay() {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
const pageform = document.querySelector("form.en__component--page");
|
|
36
|
+
if (!this.applePay || !window.hasOwnProperty("ApplePaySession")) {
|
|
37
|
+
const applePayContainer = document.querySelector(".en__field__item.applepay");
|
|
38
|
+
if (applePayContainer)
|
|
39
|
+
applePayContainer.remove();
|
|
40
|
+
if (ENGrid.debug)
|
|
41
|
+
console.log("Apple Pay DISABLED");
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
const promise = ApplePaySession.canMakePaymentsWithActiveCard(merchantIdentifier);
|
|
45
|
+
let applePayEnabled = false;
|
|
46
|
+
yield promise.then((canMakePayments) => {
|
|
47
|
+
applePayEnabled = canMakePayments;
|
|
48
|
+
if (canMakePayments) {
|
|
49
|
+
let input = document.createElement("input");
|
|
50
|
+
input.setAttribute("type", "hidden");
|
|
51
|
+
input.setAttribute("name", "PkPaymentToken");
|
|
52
|
+
input.setAttribute("id", "applePayToken");
|
|
53
|
+
pageform.appendChild(input);
|
|
54
|
+
this._form.onSubmit.subscribe(() => this.onPayClicked());
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
if (ENGrid.debug)
|
|
58
|
+
console.log("applePayEnabled", applePayEnabled);
|
|
59
|
+
let applePayWrapper = this.applePay.closest(".en__field__item");
|
|
60
|
+
if (applePayEnabled) {
|
|
61
|
+
// Set Apple Pay Class
|
|
62
|
+
applePayWrapper === null || applePayWrapper === void 0 ? void 0 : applePayWrapper.classList.add("applePayWrapper");
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
// Hide Apple Pay Wrapper
|
|
66
|
+
if (applePayWrapper)
|
|
67
|
+
applePayWrapper.style.display = "none";
|
|
68
|
+
}
|
|
69
|
+
return applePayEnabled;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
performValidation(url) {
|
|
73
|
+
return new Promise(function (resolve, reject) {
|
|
74
|
+
var merchantSession = {};
|
|
75
|
+
merchantSession.merchantIdentifier = merchantIdentifier;
|
|
76
|
+
merchantSession.merchantSessionIdentifier = merchantSessionIdentifier;
|
|
77
|
+
merchantSession.nonce = merchantNonce;
|
|
78
|
+
merchantSession.domainName = merchantDomainName;
|
|
79
|
+
merchantSession.epochTimestamp = merchantEpochTimestamp;
|
|
80
|
+
merchantSession.signature = merchantSignature;
|
|
81
|
+
var validationData = "&merchantIdentifier=" +
|
|
82
|
+
merchantIdentifier +
|
|
83
|
+
"&merchantDomain=" +
|
|
84
|
+
merchantDomainName +
|
|
85
|
+
"&displayName=" +
|
|
86
|
+
merchantDisplayName;
|
|
87
|
+
var validationUrl = "/ea-dataservice/rest/applepay/validateurl?url=" + url + validationData;
|
|
88
|
+
var xhr = new XMLHttpRequest();
|
|
89
|
+
xhr.onload = function () {
|
|
90
|
+
var data = JSON.parse(this.responseText);
|
|
91
|
+
if (ENGrid.debug)
|
|
92
|
+
console.log("Apple Pay Validation", data);
|
|
93
|
+
resolve(data);
|
|
94
|
+
};
|
|
95
|
+
xhr.onerror = reject;
|
|
96
|
+
xhr.open("GET", validationUrl);
|
|
97
|
+
xhr.send();
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
log(name, msg) {
|
|
101
|
+
var xhr = new XMLHttpRequest();
|
|
102
|
+
xhr.open("GET", "/ea-dataservice/rest/applepay/log?name=" + name + "&msg=" + msg);
|
|
103
|
+
xhr.send();
|
|
104
|
+
}
|
|
105
|
+
sendPaymentToken(token) {
|
|
106
|
+
return new Promise(function (resolve, reject) {
|
|
107
|
+
resolve(true);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
onPayClicked() {
|
|
111
|
+
if (!this._form.submit)
|
|
112
|
+
return;
|
|
113
|
+
const enFieldPaymentType = document.querySelector("#en__field_transaction_paymenttype");
|
|
114
|
+
const applePayToken = document.getElementById("applePayToken");
|
|
115
|
+
const formClass = this._form;
|
|
116
|
+
// Only work if Payment Type is Apple Pay
|
|
117
|
+
if (enFieldPaymentType.value == "applepay" && applePayToken.value == "") {
|
|
118
|
+
try {
|
|
119
|
+
let donationAmount = this._amount.amount + this._fees.fee;
|
|
120
|
+
var request = {
|
|
121
|
+
supportedNetworks: merchantSupportedNetworks,
|
|
122
|
+
merchantCapabilities: merchantCapabilities,
|
|
123
|
+
countryCode: merchantCountryCode,
|
|
124
|
+
currencyCode: merchantCurrencyCode,
|
|
125
|
+
total: {
|
|
126
|
+
label: merchantTotalLabel,
|
|
127
|
+
amount: donationAmount,
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
var session = new ApplePaySession(1, request);
|
|
131
|
+
var thisClass = this;
|
|
132
|
+
session.onvalidatemerchant = function (event) {
|
|
133
|
+
thisClass
|
|
134
|
+
.performValidation(event.validationURL)
|
|
135
|
+
.then(function (merchantSession) {
|
|
136
|
+
if (ENGrid.debug)
|
|
137
|
+
console.log("Apple Pay merchantSession", merchantSession);
|
|
138
|
+
session.completeMerchantValidation(merchantSession);
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
session.onpaymentauthorized = function (event) {
|
|
142
|
+
thisClass
|
|
143
|
+
.sendPaymentToken(event.payment.token)
|
|
144
|
+
.then(function (success) {
|
|
145
|
+
if (ENGrid.debug)
|
|
146
|
+
console.log("Apple Pay Token", event.payment.token);
|
|
147
|
+
document.getElementById("applePayToken").value = JSON.stringify(event.payment.token);
|
|
148
|
+
formClass.submitForm();
|
|
149
|
+
});
|
|
150
|
+
};
|
|
151
|
+
session.oncancel = function (event) {
|
|
152
|
+
if (ENGrid.debug)
|
|
153
|
+
console.log("Cancelled", event);
|
|
154
|
+
alert("You cancelled. Sorry it didn't work out.");
|
|
155
|
+
formClass.dispatchError();
|
|
156
|
+
};
|
|
157
|
+
session.begin();
|
|
158
|
+
this._form.submit = false;
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
catch (e) {
|
|
162
|
+
alert("Developer mistake: '" + e.message + "'");
|
|
163
|
+
formClass.dispatchError();
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
this._form.submit = true;
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// This class works when the user has added ".simple_country_select" as a class in page builder for the Country select
|
|
2
|
+
import * as cookie from "./cookie";
|
|
3
|
+
import { ENGrid, Country } from ".";
|
|
4
|
+
export class AutoCountrySelect {
|
|
5
|
+
constructor() {
|
|
6
|
+
this._countryEvent = Country.getInstance();
|
|
7
|
+
this.countryWrapper = document.querySelector(".simple_country_select");
|
|
8
|
+
this.countrySelect = this._countryEvent
|
|
9
|
+
.countryField;
|
|
10
|
+
this.country = null;
|
|
11
|
+
const engridAutofill = cookie.get("engrid-autofill");
|
|
12
|
+
const submissionFailed = !!(ENGrid.checkNested(window.EngagingNetworks, "require", "_defined", "enjs", "checkSubmissionFailed") && window.EngagingNetworks.require._defined.enjs.checkSubmissionFailed());
|
|
13
|
+
const hasIntlSupport = !!ENGrid.checkNested(window.Intl, "DisplayNames");
|
|
14
|
+
// Only run if there's no engrid-autofill cookie && if it has Intl support && no country data in url
|
|
15
|
+
const locationDataInUrl = ENGrid.getUrlParameter("supporter.country") ||
|
|
16
|
+
ENGrid.getUrlParameter("supporter.region") ||
|
|
17
|
+
(ENGrid.getUrlParameter("ea.url.id") &&
|
|
18
|
+
!ENGrid.getUrlParameter("forwarded"));
|
|
19
|
+
if (!engridAutofill &&
|
|
20
|
+
!submissionFailed &&
|
|
21
|
+
hasIntlSupport &&
|
|
22
|
+
!locationDataInUrl) {
|
|
23
|
+
fetch(`https://${window.location.hostname}/cdn-cgi/trace`)
|
|
24
|
+
.then((res) => res.text())
|
|
25
|
+
.then((t) => {
|
|
26
|
+
let data = t.replace(/[\r\n]+/g, '","').replace(/\=+/g, '":"');
|
|
27
|
+
data = '{"' + data.slice(0, data.lastIndexOf('","')) + '"}';
|
|
28
|
+
const jsondata = JSON.parse(data);
|
|
29
|
+
this.country = jsondata.loc;
|
|
30
|
+
this.init();
|
|
31
|
+
// console.log("Country:", this.country);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
this.init();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
init() {
|
|
39
|
+
if (this.countrySelect) {
|
|
40
|
+
if (this.country) {
|
|
41
|
+
const countriesNames = new Intl.DisplayNames(["en"], {
|
|
42
|
+
type: "region",
|
|
43
|
+
});
|
|
44
|
+
// We are setting the country by Name because the ISO code is not always the same. They have 2 and 3 letter codes.
|
|
45
|
+
this.setCountryByName(countriesNames.of(this.country));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
setCountryByName(countryName) {
|
|
50
|
+
if (this.countrySelect) {
|
|
51
|
+
let countrySelectOptions = this.countrySelect.options;
|
|
52
|
+
for (let i = 0; i < countrySelectOptions.length; i++) {
|
|
53
|
+
if (countrySelectOptions[i].innerHTML.toLowerCase() ==
|
|
54
|
+
countryName.toLowerCase()) {
|
|
55
|
+
this.countrySelect.selectedIndex = i;
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const event = new Event("change", { bubbles: true });
|
|
60
|
+
this.countrySelect.dispatchEvent(event);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// This class changes the Credit Card Expiration Year Field Options to
|
|
2
|
+
// include the current year and the next 19 years.
|
|
3
|
+
export class AutoYear {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.yearField = document.querySelector("select[name='transaction.ccexpire']:not(#en__field_transaction_ccexpire)");
|
|
6
|
+
this.years = 20;
|
|
7
|
+
this.yearLength = 2;
|
|
8
|
+
if (this.yearField) {
|
|
9
|
+
this.clearFieldOptions();
|
|
10
|
+
for (let i = 0; i < this.years; i++) {
|
|
11
|
+
const year = new Date().getFullYear() + i;
|
|
12
|
+
const newOption = document.createElement("option");
|
|
13
|
+
const optionText = document.createTextNode(year.toString());
|
|
14
|
+
newOption.appendChild(optionText);
|
|
15
|
+
newOption.value =
|
|
16
|
+
this.yearLength == 2 ? year.toString().substr(-2) : year.toString();
|
|
17
|
+
this.yearField.appendChild(newOption);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
clearFieldOptions() {
|
|
22
|
+
if (this.yearField) {
|
|
23
|
+
this.yearLength =
|
|
24
|
+
this.yearField.options[this.yearField.options.length - 1].value.length;
|
|
25
|
+
[...this.yearField.options].forEach((option) => {
|
|
26
|
+
var _a;
|
|
27
|
+
if (option.value !== "" && !isNaN(Number(option.value))) {
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
const index = [...this.yearField.options].findIndex((i) => i.value === option.value);
|
|
30
|
+
(_a = this.yearField) === null || _a === void 0 ? void 0 : _a.remove(index);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|