@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
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,10 @@
1
+ export declare class PremiumGift {
2
+ private logger;
3
+ private enElements;
4
+ constructor();
5
+ shoudRun(): boolean;
6
+ addEventListeners(): void;
7
+ checkPremiumGift(): void;
8
+ searchElements(): void;
9
+ setPremiumTitle(title: string): void;
10
+ }
@@ -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,3 @@
1
+ export declare class ProgressBar {
2
+ constructor();
3
+ }
@@ -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
+ }