@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/plaid.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Component with a helper to auto-click on the Plaid link
|
|
2
|
+
// when that payment method is selected
|
|
3
|
+
import { ENGrid, EngridLogger, EnForm } from ".";
|
|
4
|
+
export class Plaid {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.logger = new EngridLogger("Plaid", "peru", "yellow", "🔗");
|
|
7
|
+
this._form = EnForm.getInstance();
|
|
8
|
+
this.logger.log("Enabled");
|
|
9
|
+
this._form.onSubmit.subscribe(() => this.submit());
|
|
10
|
+
}
|
|
11
|
+
submit() {
|
|
12
|
+
const plaidLink = document.querySelector("#plaid-link-button");
|
|
13
|
+
if (plaidLink && plaidLink.textContent === "Link Account") {
|
|
14
|
+
// Click the Plaid Link button
|
|
15
|
+
this.logger.log("Clicking Link");
|
|
16
|
+
plaidLink.click();
|
|
17
|
+
this._form.submit = false;
|
|
18
|
+
// Create a observer to watch the Link ID #plaid-link-button for a new Text Node
|
|
19
|
+
const observer = new MutationObserver((mutations) => {
|
|
20
|
+
mutations.forEach((mutation) => {
|
|
21
|
+
if (mutation.type === "childList") {
|
|
22
|
+
mutation.addedNodes.forEach((node) => {
|
|
23
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
24
|
+
// If the Text Node is "Link Account" then the Link has failed
|
|
25
|
+
if (node.nodeValue === "Account Linked") {
|
|
26
|
+
this.logger.log("Plaid Linked");
|
|
27
|
+
this._form.submit = true;
|
|
28
|
+
this._form.submitForm();
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
this._form.submit = true;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
// Start observing the Link ID #plaid-link-button
|
|
39
|
+
observer.observe(plaidLink, {
|
|
40
|
+
childList: true,
|
|
41
|
+
subtree: true,
|
|
42
|
+
});
|
|
43
|
+
window.setTimeout(() => {
|
|
44
|
+
this.logger.log("Enabling Submit");
|
|
45
|
+
ENGrid.enableSubmit();
|
|
46
|
+
}, 1000);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare class PostalCodeValidator {
|
|
2
|
+
private postalCodeField;
|
|
3
|
+
private _form;
|
|
4
|
+
private logger;
|
|
5
|
+
private separator;
|
|
6
|
+
private regexSeparator;
|
|
7
|
+
private supportedSeparators;
|
|
8
|
+
constructor();
|
|
9
|
+
private shouldRun;
|
|
10
|
+
private validate;
|
|
11
|
+
private isValidUSZipCode;
|
|
12
|
+
/**
|
|
13
|
+
* Formats the zip code to #####-#### as the user inputs it
|
|
14
|
+
* The separator is determined by the TidyContact option, but defaults to "-"
|
|
15
|
+
*/
|
|
16
|
+
private liveValidate;
|
|
17
|
+
private shouldValidateUSZipCode;
|
|
18
|
+
private getSeparator;
|
|
19
|
+
private getRegexSeparator;
|
|
20
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { ENGrid } from "./engrid";
|
|
2
|
+
import { EnForm } from "./events";
|
|
3
|
+
import { EngridLogger } from "./logger";
|
|
4
|
+
// Conditionally validates the postcode field for a US format zip code
|
|
5
|
+
// If US is selected as the country, a country has not been selected yet
|
|
6
|
+
// or if there is no country field
|
|
7
|
+
// Allows blank zip code if zip code is not required.
|
|
8
|
+
export class PostalCodeValidator {
|
|
9
|
+
constructor() {
|
|
10
|
+
var _a, _b;
|
|
11
|
+
this.postalCodeField = ENGrid.getField("supporter.postcode");
|
|
12
|
+
this._form = EnForm.getInstance();
|
|
13
|
+
this.logger = new EngridLogger("Postal Code Validator", "white", "red", "📬");
|
|
14
|
+
this.supportedSeparators = ["+", "-", " "];
|
|
15
|
+
this.separator = this.getSeparator();
|
|
16
|
+
this.regexSeparator = this.getRegexSeparator(this.separator);
|
|
17
|
+
if (this.shouldRun()) {
|
|
18
|
+
(_a = this.postalCodeField) === null || _a === void 0 ? void 0 : _a.addEventListener("blur", () => this.validate());
|
|
19
|
+
(_b = this.postalCodeField) === null || _b === void 0 ? void 0 : _b.addEventListener("input", () => this.liveValidate());
|
|
20
|
+
this._form.onValidate.subscribe(() => {
|
|
21
|
+
if (!this._form.validate)
|
|
22
|
+
return;
|
|
23
|
+
this.liveValidate();
|
|
24
|
+
// It seems like we need some delay or EN removes our error message.
|
|
25
|
+
setTimeout(() => {
|
|
26
|
+
this.validate();
|
|
27
|
+
}, 100);
|
|
28
|
+
// We dont need to validate the zip code, or it is valid
|
|
29
|
+
const postalCodeValid = !this.shouldValidateUSZipCode() || this.isValidUSZipCode();
|
|
30
|
+
this._form.validate = postalCodeValid;
|
|
31
|
+
if (!postalCodeValid) {
|
|
32
|
+
this.logger.log(`Invalid Zip Code ${this.postalCodeField.value}`);
|
|
33
|
+
this.postalCodeField.scrollIntoView({ behavior: "smooth" });
|
|
34
|
+
}
|
|
35
|
+
return postalCodeValid;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
shouldRun() {
|
|
40
|
+
return !!(ENGrid.getOption("PostalCodeValidator") && this.postalCodeField);
|
|
41
|
+
}
|
|
42
|
+
validate() {
|
|
43
|
+
if (this.shouldValidateUSZipCode() && !this.isValidUSZipCode()) {
|
|
44
|
+
ENGrid.setError(".en__field--postcode", `Please enter a valid ZIP Code of ##### or #####${this.separator}####`);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
ENGrid.removeError(".en__field--postcode");
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
isValidUSZipCode() {
|
|
51
|
+
var _a, _b;
|
|
52
|
+
const zipCodeRequired = !!document.querySelector(".en__field--postcode.en__mandatory");
|
|
53
|
+
// If zip code is not required in EN Form Block and the field is empty, it is valid
|
|
54
|
+
if (!zipCodeRequired && ((_a = this.postalCodeField) === null || _a === void 0 ? void 0 : _a.value) === "") {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
const postalCodeRegex = new RegExp(`^\\d{5}(${this.regexSeparator}\\d{4})?$`);
|
|
58
|
+
return !!((_b = this.postalCodeField) === null || _b === void 0 ? void 0 : _b.value.match(postalCodeRegex));
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Formats the zip code to #####-#### as the user inputs it
|
|
62
|
+
* The separator is determined by the TidyContact option, but defaults to "-"
|
|
63
|
+
*/
|
|
64
|
+
liveValidate() {
|
|
65
|
+
var _a;
|
|
66
|
+
if (!this.shouldValidateUSZipCode())
|
|
67
|
+
return;
|
|
68
|
+
let value = (_a = this.postalCodeField) === null || _a === void 0 ? void 0 : _a.value;
|
|
69
|
+
// If the value is 5 characters or less, remove all non-numeric characters
|
|
70
|
+
if (value.length <= 5) {
|
|
71
|
+
value = value.replace(/\D/g, "");
|
|
72
|
+
}
|
|
73
|
+
// If one of the supported separators is endered as the 6th character, replace it with the official separator
|
|
74
|
+
else if (value.length === 6 &&
|
|
75
|
+
this.supportedSeparators.includes(value[5])) {
|
|
76
|
+
// Removing all non-numeric characters
|
|
77
|
+
value = value.replace(/\D/g, "") + this.separator;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
// Removing all non-numeric characters
|
|
81
|
+
value = value.replace(/\D/g, "");
|
|
82
|
+
// Adding the separator after the 5th character
|
|
83
|
+
value = value.replace(/(\d{5})(\d)/, `$1${this.separator}$2`);
|
|
84
|
+
}
|
|
85
|
+
//set field value with max 10 characters
|
|
86
|
+
this.postalCodeField.value = value.slice(0, 10);
|
|
87
|
+
}
|
|
88
|
+
shouldValidateUSZipCode() {
|
|
89
|
+
// Validating US zip code only if country is US, country has not yet been selected
|
|
90
|
+
// or if there is no country field
|
|
91
|
+
const country = ENGrid.getField("supporter.country")
|
|
92
|
+
? ENGrid.getFieldValue("supporter.country")
|
|
93
|
+
: "US";
|
|
94
|
+
return ["us", "united states", "usa", ""].includes(country.toLowerCase());
|
|
95
|
+
}
|
|
96
|
+
getSeparator() {
|
|
97
|
+
const tidyContact = ENGrid.getOption("TidyContact");
|
|
98
|
+
if (tidyContact &&
|
|
99
|
+
tidyContact.us_zip_divider &&
|
|
100
|
+
this.supportedSeparators.includes(tidyContact.us_zip_divider)) {
|
|
101
|
+
return tidyContact.us_zip_divider;
|
|
102
|
+
}
|
|
103
|
+
return "-";
|
|
104
|
+
}
|
|
105
|
+
getRegexSeparator(separator) {
|
|
106
|
+
switch (separator) {
|
|
107
|
+
case "+":
|
|
108
|
+
return "\\+";
|
|
109
|
+
case "-":
|
|
110
|
+
return "-";
|
|
111
|
+
case " ":
|
|
112
|
+
return "\\s";
|
|
113
|
+
default:
|
|
114
|
+
this.logger.log(`Invalid separator "${separator}" provided to PostalCodeValidator, falling back to "-".`);
|
|
115
|
+
return "-";
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// Component to handle premium gift features
|
|
2
|
+
// 1 - Add a class to body to indicate which premium gift is selected (data-engrid-premium-gift-name="item-name-slugged")
|
|
3
|
+
// 2 - Add a class to body to indicate if the "maximize my impact" is selected (data-engrid-premium-gift-maximize="true|false")
|
|
4
|
+
// 3 - Check the premium gift when click on the title or description
|
|
5
|
+
// 4 - Create new {$PREMIUMTITLE} merge tag that's replaced with the premium gift name
|
|
6
|
+
import { ENGrid, EngridLogger } from ".";
|
|
7
|
+
export class PremiumGift {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.logger = new EngridLogger("PremiumGift", "#232323", "#f7b500", "🎁");
|
|
10
|
+
this.enElements = new Array();
|
|
11
|
+
if (!this.shoudRun())
|
|
12
|
+
return;
|
|
13
|
+
this.searchElements();
|
|
14
|
+
this.addEventListeners();
|
|
15
|
+
this.checkPremiumGift();
|
|
16
|
+
}
|
|
17
|
+
shoudRun() {
|
|
18
|
+
return ("pageJson" in window &&
|
|
19
|
+
"pageType" in window.pageJson &&
|
|
20
|
+
window.pageJson.pageType === "premiumgift");
|
|
21
|
+
}
|
|
22
|
+
addEventListeners() {
|
|
23
|
+
["click", "change"].forEach((event) => {
|
|
24
|
+
document.addEventListener(event, (e) => {
|
|
25
|
+
const element = e.target;
|
|
26
|
+
const premiumGift = element.closest(".en__pg__body");
|
|
27
|
+
if (premiumGift) {
|
|
28
|
+
const premiumGiftInput = premiumGift.querySelector('[name="en__pg"]');
|
|
29
|
+
if ("type" in element === false) {
|
|
30
|
+
const premiumGiftValue = premiumGiftInput.value;
|
|
31
|
+
window.setTimeout(() => {
|
|
32
|
+
const newPremiumGift = document.querySelector('[name="en__pg"][value="' + premiumGiftValue + '"]');
|
|
33
|
+
if (newPremiumGift) {
|
|
34
|
+
newPremiumGift.checked = true;
|
|
35
|
+
newPremiumGift.dispatchEvent(new Event("change"));
|
|
36
|
+
}
|
|
37
|
+
}, 100);
|
|
38
|
+
}
|
|
39
|
+
window.setTimeout(() => {
|
|
40
|
+
this.checkPremiumGift();
|
|
41
|
+
}, 110);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
// Check when visibility of the Premium Gift Block changes.
|
|
46
|
+
// EN will add "display: none" to this element when the supporter does not qualify for a premium
|
|
47
|
+
const premiumGiftsBlock = document.querySelector(".en__component--premiumgiftblock");
|
|
48
|
+
if (premiumGiftsBlock) {
|
|
49
|
+
const observer = new MutationObserver((mutationsList) => {
|
|
50
|
+
for (const mutation of mutationsList) {
|
|
51
|
+
if (mutation.type === "attributes" &&
|
|
52
|
+
mutation.attributeName === "style") {
|
|
53
|
+
if (premiumGiftsBlock.style.display === "none") {
|
|
54
|
+
this.logger.log("Premium Gift Section hidden - removing premium gift body data attributes and premium title.");
|
|
55
|
+
ENGrid.setBodyData("premium-gift-maximize", false);
|
|
56
|
+
ENGrid.setBodyData("premium-gift-name", false);
|
|
57
|
+
this.setPremiumTitle("");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
observer.observe(premiumGiftsBlock, { attributes: true });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
checkPremiumGift() {
|
|
66
|
+
const premiumGift = document.querySelector('[name="en__pg"]:checked');
|
|
67
|
+
if (premiumGift) {
|
|
68
|
+
const premiumGiftValue = premiumGift.value;
|
|
69
|
+
this.logger.log("Premium Gift Value: " + premiumGiftValue);
|
|
70
|
+
const premiumGiftContainer = premiumGift.closest(".en__pg");
|
|
71
|
+
if (premiumGiftValue !== "0") {
|
|
72
|
+
const premiumGiftName = premiumGiftContainer.querySelector(".en__pg__name");
|
|
73
|
+
ENGrid.setBodyData("premium-gift-maximize", "false");
|
|
74
|
+
ENGrid.setBodyData("premium-gift-name", ENGrid.slugify(premiumGiftName.innerText));
|
|
75
|
+
this.setPremiumTitle(premiumGiftName.innerText);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
ENGrid.setBodyData("premium-gift-maximize", "true");
|
|
79
|
+
ENGrid.setBodyData("premium-gift-name", false);
|
|
80
|
+
this.setPremiumTitle("");
|
|
81
|
+
}
|
|
82
|
+
if (!premiumGiftContainer.classList.contains("en__pg--selected")) {
|
|
83
|
+
const checkedPremiumGift = document.querySelector(".en__pg--selected");
|
|
84
|
+
if (checkedPremiumGift) {
|
|
85
|
+
checkedPremiumGift.classList.remove("en__pg--selected");
|
|
86
|
+
}
|
|
87
|
+
premiumGiftContainer.classList.add("en__pg--selected");
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
searchElements() {
|
|
92
|
+
const enElements = document.querySelectorAll(`
|
|
93
|
+
.en__component--copyblock,
|
|
94
|
+
.en__component--codeblock,
|
|
95
|
+
.en__field
|
|
96
|
+
`);
|
|
97
|
+
if (enElements.length > 0) {
|
|
98
|
+
enElements.forEach((item) => {
|
|
99
|
+
if (item instanceof HTMLElement &&
|
|
100
|
+
item.innerHTML.includes("{$PREMIUMTITLE}")) {
|
|
101
|
+
item.innerHTML = item.innerHTML.replace("{$PREMIUMTITLE}", `<span class="engrid_premium_title"></span>`);
|
|
102
|
+
this.enElements.push(item);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
setPremiumTitle(title) {
|
|
108
|
+
this.enElements.forEach((item) => {
|
|
109
|
+
const premiumTitle = item.querySelector(".engrid_premium_title");
|
|
110
|
+
if (premiumTitle) {
|
|
111
|
+
premiumTitle.innerHTML = title;
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ENGrid } from ".";
|
|
2
|
+
export class ProgressBar {
|
|
3
|
+
constructor() {
|
|
4
|
+
var _a, _b;
|
|
5
|
+
const progressIndicator = document.querySelector("span[data-engrid-progress-indicator]");
|
|
6
|
+
const pageCount = ENGrid.getPageCount();
|
|
7
|
+
const pageNumber = ENGrid.getPageNumber();
|
|
8
|
+
if (!progressIndicator || !pageCount || !pageNumber) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
let maxValue = (_a = progressIndicator.getAttribute("max")) !== null && _a !== void 0 ? _a : 100;
|
|
12
|
+
if (typeof maxValue === "string")
|
|
13
|
+
maxValue = parseInt(maxValue);
|
|
14
|
+
let amountValue = (_b = progressIndicator.getAttribute("amount")) !== null && _b !== void 0 ? _b : 0;
|
|
15
|
+
if (typeof amountValue === "string")
|
|
16
|
+
amountValue = parseInt(amountValue);
|
|
17
|
+
const prevPercentage = pageNumber === 1
|
|
18
|
+
? 0
|
|
19
|
+
: Math.ceil(((pageNumber - 1) / pageCount) * maxValue);
|
|
20
|
+
let percentage = pageNumber === 1 ? 0 : Math.ceil((pageNumber / pageCount) * maxValue);
|
|
21
|
+
const scalePrev = prevPercentage / 100;
|
|
22
|
+
let scale = percentage / 100;
|
|
23
|
+
if (amountValue) {
|
|
24
|
+
percentage =
|
|
25
|
+
Math.ceil(amountValue) > Math.ceil(maxValue) ? maxValue : amountValue;
|
|
26
|
+
scale = percentage / 100;
|
|
27
|
+
}
|
|
28
|
+
progressIndicator.innerHTML = `
|
|
29
|
+
<div class="indicator__wrap">
|
|
30
|
+
<span class="indicator__progress" style="transform: scaleX(${scalePrev});"></span>
|
|
31
|
+
<span class="indicator__percentage">${percentage}<span class="indicator__percentage-sign">%</span></span>
|
|
32
|
+
</div>`;
|
|
33
|
+
if (percentage !== prevPercentage) {
|
|
34
|
+
const progress = document.querySelector(".indicator__progress");
|
|
35
|
+
requestAnimationFrame(function () {
|
|
36
|
+
progress.style.transform = `scaleX(${scale})`;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { EnForm, RememberMeEvents } from "./events";
|
|
2
|
+
export declare class RememberMe {
|
|
3
|
+
_form: EnForm;
|
|
4
|
+
_events: RememberMeEvents;
|
|
5
|
+
private remoteUrl;
|
|
6
|
+
private cookieName;
|
|
7
|
+
private fieldNames;
|
|
8
|
+
private fieldData;
|
|
9
|
+
private cookieExpirationDays;
|
|
10
|
+
private iframe;
|
|
11
|
+
private rememberMeOptIn;
|
|
12
|
+
private fieldDonationAmountRadioName;
|
|
13
|
+
private fieldDonationAmountOtherName;
|
|
14
|
+
private fieldDonationRecurrPayRadioName;
|
|
15
|
+
private fieldDonationAmountOtherCheckboxID;
|
|
16
|
+
private fieldOptInSelectorTarget;
|
|
17
|
+
private fieldOptInSelectorTargetLocation;
|
|
18
|
+
private fieldClearSelectorTarget;
|
|
19
|
+
private fieldClearSelectorTargetLocation;
|
|
20
|
+
constructor(options: {
|
|
21
|
+
remoteUrl?: string;
|
|
22
|
+
cookieName?: string;
|
|
23
|
+
cookieExpirationDays?: number;
|
|
24
|
+
fieldNames?: string[];
|
|
25
|
+
fieldDonationAmountRadioName?: string;
|
|
26
|
+
fieldDonationAmountOtherName?: string;
|
|
27
|
+
fieldDonationRecurrPayRadioName?: string;
|
|
28
|
+
fieldDonationAmountOtherCheckboxID?: string;
|
|
29
|
+
fieldOptInSelectorTarget?: string;
|
|
30
|
+
fieldOptInSelectorTargetLocation?: string;
|
|
31
|
+
fieldClearSelectorTarget?: string;
|
|
32
|
+
fieldClearSelectorTargetLocation?: string;
|
|
33
|
+
checked?: boolean;
|
|
34
|
+
});
|
|
35
|
+
private updateFieldData;
|
|
36
|
+
private insertClearRememberMeLink;
|
|
37
|
+
private getElementByFirstSelector;
|
|
38
|
+
private insertRememberMeOptin;
|
|
39
|
+
private useRemote;
|
|
40
|
+
private createIframe;
|
|
41
|
+
private clearCookie;
|
|
42
|
+
private clearCookieOnRemote;
|
|
43
|
+
private saveCookieToRemote;
|
|
44
|
+
private readCookie;
|
|
45
|
+
private saveCookie;
|
|
46
|
+
private readFields;
|
|
47
|
+
private setFieldValue;
|
|
48
|
+
private clearFields;
|
|
49
|
+
/**
|
|
50
|
+
* Writes the values from the fieldData object to the corresponding HTML input fields.
|
|
51
|
+
*
|
|
52
|
+
* This function iterates over the fieldNames array and for each field name, it selects the corresponding HTML input field.
|
|
53
|
+
* If the field is found and its tag name is "INPUT", it checks if the field name matches certain conditions (like being a donation recurring payment radio button or a donation amount radio button).
|
|
54
|
+
* Depending on these conditions, it either clicks the field or sets its value using the setFieldValue function.
|
|
55
|
+
* If the field tag name is "SELECT", it sets its value using the setFieldValue function.
|
|
56
|
+
*
|
|
57
|
+
* @param overwrite - A boolean indicating whether to overwrite the existing value of the fields. Defaults to false.
|
|
58
|
+
*/
|
|
59
|
+
private writeFields;
|
|
60
|
+
private isJson;
|
|
61
|
+
}
|