@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,89 @@
1
+ // This component uses EN's Custom Validators on the client side to validate form fields.
2
+ // It's currently behind a feature flag, so it's not enabled by default.
3
+ // To enable it, add the following to your options:
4
+ // ENValidators: true
5
+ import { EnForm, ENGrid, EngridLogger } from ".";
6
+ export class ENValidators {
7
+ constructor() {
8
+ this._form = EnForm.getInstance();
9
+ this._enElements = null;
10
+ this.logger = new EngridLogger("ENValidators", "white", "darkolivegreen", "🧐");
11
+ if (!this.loadValidators()) {
12
+ // This is an error to flag a racing condition. If the script is loaded before the validators are loaded, it will not work.
13
+ this.logger.error("Not Loaded");
14
+ return;
15
+ }
16
+ if (!this.shouldRun()) {
17
+ // If there's no custom validators, get out
18
+ this.logger.log("Not Needed");
19
+ return;
20
+ }
21
+ this._form.onValidate.subscribe(this.enOnValidate.bind(this));
22
+ }
23
+ loadValidators() {
24
+ if (!ENGrid.checkNested(window.EngagingNetworks, "require", "_defined", "enValidation", "validation", "validators")) {
25
+ return false;
26
+ }
27
+ // Loop through the array validators and add them to this._enElements
28
+ const validators = window.EngagingNetworks.require._defined.enValidation.validation
29
+ .validators;
30
+ this._enElements = validators.reduce((acc, validator) => {
31
+ if ("type" in validator && validator.type === "CUST") {
32
+ const container = document.querySelector(".en__field--" + validator.field);
33
+ const field = container
34
+ ? container.querySelector("input, select, textarea")
35
+ : null;
36
+ if (field) {
37
+ field.addEventListener("input", this.liveValidate.bind(this, container, field, validator.regex, validator.message));
38
+ acc.push({
39
+ container: container,
40
+ field: field,
41
+ regex: validator.regex,
42
+ message: validator.message,
43
+ });
44
+ }
45
+ }
46
+ return acc;
47
+ }, []);
48
+ return true;
49
+ }
50
+ // Should we run the script?
51
+ shouldRun() {
52
+ return (ENGrid.getOption("ENValidators") &&
53
+ this._enElements &&
54
+ this._enElements.length > 0);
55
+ }
56
+ // Don't submit the form if any of the fields are invalid
57
+ enOnValidate() {
58
+ if (!this._enElements || this._form.validate === false) {
59
+ return;
60
+ }
61
+ this._enElements.forEach((element) => {
62
+ const fieldValidation = this.liveValidate(element.container, element.field, element.regex, element.message);
63
+ if (!fieldValidation) {
64
+ this._form.validate = false;
65
+ element.field.focus();
66
+ return;
67
+ }
68
+ });
69
+ this._form.validate = true;
70
+ }
71
+ // Validate the field on the fly
72
+ liveValidate(container, field, regex, message) {
73
+ const value = ENGrid.getFieldValue(field.getAttribute("name") || "");
74
+ // Do not validate empty fields, that's the job of the required validator
75
+ if (value === "") {
76
+ return true;
77
+ }
78
+ this.logger.log(`Live Validate ${field.getAttribute("name")} with ${regex}`);
79
+ // compare the value of the field with the regex
80
+ if (!value.match(regex)) {
81
+ // If the value is not valid, add the error message
82
+ ENGrid.setError(container, message);
83
+ return false;
84
+ }
85
+ // If the value is valid, remove the error message
86
+ ENGrid.removeError(container);
87
+ return true;
88
+ }
89
+ }
@@ -0,0 +1,49 @@
1
+ import { Options } from ".";
2
+ export declare abstract class ENGrid {
3
+ constructor();
4
+ static get enForm(): HTMLFormElement;
5
+ static get debug(): boolean;
6
+ static get demo(): boolean;
7
+ static getUrlParameter(name: string): string | true | Object[] | null;
8
+ static getField(name: string): Element | null;
9
+ static getFieldValue(name: string): string;
10
+ static setFieldValue(name: string, value: unknown, parseENDependencies?: boolean, dispatchEvents?: boolean): void;
11
+ static createHiddenInput(name: string, value?: string): HTMLInputElement;
12
+ static enParseDependencies(): void;
13
+ static getGiftProcess(): any;
14
+ static getPageCount(): any;
15
+ static getPageNumber(): any;
16
+ static getPageID(): any;
17
+ static getClientID(): any;
18
+ static getDataCenter(): "us" | "ca";
19
+ static getPageType(): "DONATION" | "ECARD" | "SURVEY" | "EMAILTOTARGET" | "ADVOCACY" | "SUBSCRIBEFORM" | "SUPPORTERHUB" | "UNSUBSCRIBE" | "TWEETPAGE" | "UNKNOWN";
20
+ static setBodyData(dataName: string, value: string | boolean): void;
21
+ static getBodyData(dataName: string): string | null;
22
+ static hasBodyData(dataName: string): boolean;
23
+ static getOption<K extends keyof Options>(key: K): Options[K] | null;
24
+ static loadJS(url: string, onload?: (() => void) | null, head?: boolean): void;
25
+ static formatNumber(number: string | number, decimals?: number, dec_point?: string, thousands_sep?: string): string;
26
+ static cleanAmount(amount: string): number;
27
+ static disableSubmit(label?: string): boolean;
28
+ static enableSubmit(): boolean;
29
+ static formatDate(date: Date, format?: string): string;
30
+ /**
31
+ * Check if the provided object has ALL the provided properties
32
+ * Example: checkNested(EngagingNetworks, 'require', '_defined', 'enjs', 'checkSubmissionFailed')
33
+ * will return true if EngagingNetworks.require._defined.enjs.checkSubmissionFailed is defined
34
+ */
35
+ static checkNested(obj: any, ...args: string[]): boolean;
36
+ static deepMerge(target: any, source: any): any;
37
+ static setError(element: string | HTMLElement, errorMessage: string): void;
38
+ static removeError(element: string | HTMLElement): void;
39
+ static isVisible(element: HTMLElement): boolean;
40
+ static getCurrencySymbol(): string;
41
+ static getCurrencyCode(): string;
42
+ static addHtml(html: string | HTMLElement, target?: string, position?: string): void;
43
+ static removeHtml(target: string): void;
44
+ static slugify(text: string): string;
45
+ static watchForError(callback: Function): void;
46
+ static getPaymentType(): string;
47
+ static setPaymentType(paymentType: string): void;
48
+ static isInViewport(element: HTMLElement): boolean;
49
+ }
package/dist/engrid.js ADDED
@@ -0,0 +1,547 @@
1
+ export class ENGrid {
2
+ constructor() {
3
+ if (!ENGrid.enForm) {
4
+ throw new Error("Engaging Networks Form Not Found!");
5
+ }
6
+ }
7
+ static get enForm() {
8
+ return document.querySelector("form.en__component");
9
+ }
10
+ static get debug() {
11
+ return !!this.getOption("Debug");
12
+ }
13
+ static get demo() {
14
+ return this.getUrlParameter("mode") === "DEMO";
15
+ }
16
+ // Return any parameter from the URL
17
+ static getUrlParameter(name) {
18
+ const searchParams = new URLSearchParams(window.location.search);
19
+ // Add support for array on the name ending with []
20
+ if (name.endsWith("[]")) {
21
+ let values = [];
22
+ searchParams.forEach((value, key) => {
23
+ if (key.startsWith(name.replace("[]", ""))) {
24
+ values.push(new Object({ [key]: value }));
25
+ }
26
+ });
27
+ return values.length > 0 ? values : null;
28
+ }
29
+ if (searchParams.has(name)) {
30
+ return searchParams.get(name) || true;
31
+ }
32
+ return null;
33
+ }
34
+ static getField(name) {
35
+ // Get the field by name
36
+ return document.querySelector(`[name="${name}"]`);
37
+ }
38
+ // Return the field value from its name. It works on any field type.
39
+ // Multiple values (from checkboxes or multi-select) are returned as single string
40
+ // Separated by ,
41
+ static getFieldValue(name) {
42
+ return new FormData(this.enForm).getAll(name).join(",");
43
+ }
44
+ // Set a value to any field. If it's a dropdown, radio or checkbox, it selects the proper option matching the value
45
+ static setFieldValue(name, value, parseENDependencies = true, dispatchEvents = false) {
46
+ if (value === ENGrid.getFieldValue(name))
47
+ return;
48
+ document.getElementsByName(name).forEach((field) => {
49
+ if ("type" in field) {
50
+ switch (field.type) {
51
+ case "select-one":
52
+ case "select-multiple":
53
+ for (const option of field.options) {
54
+ if (option.value == value) {
55
+ option.selected = true;
56
+ if (dispatchEvents) {
57
+ field.dispatchEvent(new Event("change", { bubbles: true }));
58
+ }
59
+ }
60
+ }
61
+ break;
62
+ case "checkbox":
63
+ case "radio":
64
+ if (field.value == value) {
65
+ field.checked = true;
66
+ if (dispatchEvents) {
67
+ field.dispatchEvent(new Event("change", { bubbles: true }));
68
+ }
69
+ }
70
+ break;
71
+ case "textarea":
72
+ case "text":
73
+ default:
74
+ field.value = value;
75
+ if (dispatchEvents) {
76
+ field.dispatchEvent(new Event("change", { bubbles: true }));
77
+ field.dispatchEvent(new Event("blur", { bubbles: true }));
78
+ }
79
+ }
80
+ field.setAttribute("engrid-value-changed", "");
81
+ }
82
+ });
83
+ if (parseENDependencies)
84
+ this.enParseDependencies();
85
+ return;
86
+ }
87
+ // Create a hidden input field
88
+ static createHiddenInput(name, value = "") {
89
+ var _a;
90
+ const formBlock = document.createElement("div");
91
+ formBlock.classList.add("en__component", "en__component--formblock", "hide");
92
+ const textField = document.createElement("div");
93
+ textField.classList.add("en__field", "en__field--text");
94
+ const textElement = document.createElement("div");
95
+ textElement.classList.add("en__field__element", "en__field__element--text");
96
+ const inputField = document.createElement("input");
97
+ inputField.classList.add("en__field__input", "en__field__input--text", "engrid-added-input");
98
+ inputField.setAttribute("name", name);
99
+ inputField.setAttribute("type", "hidden");
100
+ inputField.setAttribute("value", value);
101
+ textElement.appendChild(inputField);
102
+ textField.appendChild(textElement);
103
+ formBlock.appendChild(textField);
104
+ const submitElement = document.querySelector(".en__submit");
105
+ if (submitElement) {
106
+ const lastFormComponent = submitElement.closest(".en__component");
107
+ if (lastFormComponent) {
108
+ // Insert the new field after the submit button
109
+ (_a = lastFormComponent.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(formBlock, lastFormComponent.nextSibling);
110
+ }
111
+ }
112
+ else {
113
+ ENGrid.enForm.appendChild(formBlock);
114
+ }
115
+ return inputField;
116
+ }
117
+ // Trigger EN Dependencies
118
+ static enParseDependencies() {
119
+ var _a, _b, _c, _d, _e, _f;
120
+ if (window.EngagingNetworks &&
121
+ typeof ((_e = (_d = (_c = (_b = (_a = window.EngagingNetworks) === null || _a === void 0 ? void 0 : _a.require) === null || _b === void 0 ? void 0 : _b._defined) === null || _c === void 0 ? void 0 : _c.enDependencies) === null || _d === void 0 ? void 0 : _d.dependencies) === null || _e === void 0 ? void 0 : _e.parseDependencies) === "function") {
122
+ const customDependencies = [];
123
+ if ("dependencies" in window.EngagingNetworks) {
124
+ const amountContainer = document.querySelector(".en__field--donationAmt");
125
+ if (amountContainer) {
126
+ let amountID = ((_f = [...amountContainer.classList.values()]
127
+ .filter((v) => v.startsWith("en__field--") && Number(v.substring(11)) > 0)
128
+ .toString()
129
+ .match(/\d/g)) === null || _f === void 0 ? void 0 : _f.join("")) || "";
130
+ if (amountID) {
131
+ window.EngagingNetworks.dependencies.forEach((dependency) => {
132
+ if ("actions" in dependency && dependency.actions.length > 0) {
133
+ let amountIdFound = false;
134
+ dependency.actions.forEach((action) => {
135
+ if ("target" in action && action.target == amountID) {
136
+ amountIdFound = true;
137
+ }
138
+ });
139
+ if (!amountIdFound) {
140
+ customDependencies.push(dependency);
141
+ }
142
+ }
143
+ });
144
+ if (customDependencies.length > 0) {
145
+ window.EngagingNetworks.require._defined.enDependencies.dependencies.parseDependencies(customDependencies);
146
+ if (ENGrid.getOption("Debug"))
147
+ console.log("EN Dependencies Triggered", customDependencies);
148
+ }
149
+ }
150
+ }
151
+ }
152
+ }
153
+ }
154
+ // Return the status of the gift process (true if a donation has been made, otherwise false)
155
+ static getGiftProcess() {
156
+ if ("pageJson" in window)
157
+ return window.pageJson.giftProcess;
158
+ return null;
159
+ }
160
+ // Return the page count
161
+ static getPageCount() {
162
+ if ("pageJson" in window)
163
+ return window.pageJson.pageCount;
164
+ return null;
165
+ }
166
+ // Return the current page number
167
+ static getPageNumber() {
168
+ if ("pageJson" in window)
169
+ return window.pageJson.pageNumber;
170
+ return null;
171
+ }
172
+ // Return the current page ID
173
+ static getPageID() {
174
+ if ("pageJson" in window)
175
+ return window.pageJson.campaignPageId;
176
+ return 0;
177
+ }
178
+ // Return the client ID
179
+ static getClientID() {
180
+ if ("pageJson" in window)
181
+ return window.pageJson.clientId;
182
+ return 0;
183
+ }
184
+ //returns 'us or 'ca' based on the client ID
185
+ static getDataCenter() {
186
+ return ENGrid.getClientID() >= 10000 ? "us" : "ca";
187
+ }
188
+ // Return the current page type
189
+ static getPageType() {
190
+ if ("pageJson" in window && "pageType" in window.pageJson) {
191
+ switch (window.pageJson.pageType) {
192
+ case "donation":
193
+ case "premiumgift":
194
+ return "DONATION";
195
+ break;
196
+ case "e-card":
197
+ return "ECARD";
198
+ break;
199
+ case "otherdatacapture":
200
+ case "survey":
201
+ return "SURVEY";
202
+ break;
203
+ case "emailtotarget":
204
+ return "EMAILTOTARGET";
205
+ break;
206
+ case "advocacypetition":
207
+ return "ADVOCACY";
208
+ break;
209
+ case "emailsubscribeform":
210
+ return "SUBSCRIBEFORM";
211
+ break;
212
+ case "supporterhub":
213
+ return "SUPPORTERHUB";
214
+ break;
215
+ case "unsubscribe":
216
+ return "UNSUBSCRIBE";
217
+ break;
218
+ case "tweetpage":
219
+ return "TWEETPAGE";
220
+ break;
221
+ default:
222
+ return "UNKNOWN";
223
+ }
224
+ }
225
+ else {
226
+ return "UNKNOWN";
227
+ }
228
+ }
229
+ // Set body engrid data attributes
230
+ static setBodyData(dataName, value) {
231
+ const body = document.querySelector("body");
232
+ // If value is boolean
233
+ if (typeof value === "boolean" && value === false) {
234
+ body.removeAttribute(`data-engrid-${dataName}`);
235
+ return;
236
+ }
237
+ body.setAttribute(`data-engrid-${dataName}`, value.toString());
238
+ }
239
+ // Get body engrid data attributes
240
+ static getBodyData(dataName) {
241
+ const body = document.querySelector("body");
242
+ return body.getAttribute(`data-engrid-${dataName}`);
243
+ }
244
+ // Check if body has engrid data attributes
245
+ static hasBodyData(dataName) {
246
+ const body = document.querySelector("body");
247
+ return body.hasAttribute(`data-engrid-${dataName}`);
248
+ }
249
+ // Return the option value
250
+ static getOption(key) {
251
+ return window.EngridOptions[key] || null;
252
+ }
253
+ // Load an external script
254
+ static loadJS(url, onload = null, head = true) {
255
+ const scriptTag = document.createElement("script");
256
+ scriptTag.src = url;
257
+ scriptTag.onload = onload;
258
+ if (head) {
259
+ document.head.appendChild(scriptTag);
260
+ return;
261
+ }
262
+ document.body.appendChild(scriptTag);
263
+ return;
264
+ }
265
+ // Format a number
266
+ static formatNumber(number, decimals = 2, dec_point = ".", thousands_sep = ",") {
267
+ // Strip all characters but numerical ones.
268
+ number = (number + "").replace(/[^0-9+\-Ee.]/g, "");
269
+ const n = !isFinite(+number) ? 0 : +number;
270
+ const prec = !isFinite(+decimals) ? 0 : Math.abs(decimals);
271
+ const sep = typeof thousands_sep === "undefined" ? "," : thousands_sep;
272
+ const dec = typeof dec_point === "undefined" ? "." : dec_point;
273
+ let s = [];
274
+ const toFixedFix = function (n, prec) {
275
+ const k = Math.pow(10, prec);
276
+ return "" + Math.round(n * k) / k;
277
+ };
278
+ // Fix for IE parseFloat(0.55).toFixed(0) = 0;
279
+ s = (prec ? toFixedFix(n, prec) : "" + Math.round(n)).split(".");
280
+ if (s[0].length > 3) {
281
+ s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
282
+ }
283
+ if ((s[1] || "").length < prec) {
284
+ s[1] = s[1] || "";
285
+ s[1] += new Array(prec - s[1].length + 1).join("0");
286
+ }
287
+ return s.join(dec);
288
+ }
289
+ // Clean an Amount
290
+ static cleanAmount(amount) {
291
+ // Split the number
292
+ const valueArray = amount.replace(/[^0-9,\.]/g, "").split(/[,.]+/);
293
+ const delimArray = amount.replace(/[^.,]/g, "").split("");
294
+ // Handle values with no decimal places and non-numeric values
295
+ if (valueArray.length === 1) {
296
+ return parseInt(valueArray[0]) || 0;
297
+ }
298
+ // Ignore invalid numbers
299
+ if (valueArray
300
+ .map((x, index) => {
301
+ return index > 0 && index + 1 !== valueArray.length && x.length !== 3
302
+ ? true
303
+ : false;
304
+ })
305
+ .includes(true)) {
306
+ return 0;
307
+ }
308
+ // Multiple commas is a bad thing? So edgy.
309
+ if (delimArray.length > 1 && !delimArray.includes(".")) {
310
+ return 0;
311
+ }
312
+ // Handle invalid decimal and comma formatting
313
+ if ([...new Set(delimArray.slice(0, -1))].length > 1) {
314
+ return 0;
315
+ }
316
+ // If there are cents
317
+ if (valueArray[valueArray.length - 1].length <= 2) {
318
+ const cents = valueArray.pop() || "00";
319
+ return parseInt(cents) > 0
320
+ ? parseFloat(Number(parseInt(valueArray.join("")) + "." + cents).toFixed(2))
321
+ : parseInt(valueArray.join(""));
322
+ }
323
+ return parseInt(valueArray.join(""));
324
+ }
325
+ static disableSubmit(label = "") {
326
+ const submit = document.querySelector(".en__submit button");
327
+ if (!submit)
328
+ return false;
329
+ submit.dataset.originalText = submit.innerHTML;
330
+ let submitButtonProcessingHTML = "<span class='loader-wrapper'><span class='loader loader-quart'></span><span class='submit-button-text-wrapper'>" +
331
+ label +
332
+ "</span></span>";
333
+ submit.disabled = true;
334
+ submit.innerHTML = submitButtonProcessingHTML;
335
+ return true;
336
+ }
337
+ static enableSubmit() {
338
+ const submit = document.querySelector(".en__submit button");
339
+ if (!submit)
340
+ return false;
341
+ if (submit.dataset.originalText) {
342
+ submit.disabled = false;
343
+ submit.innerHTML = submit.dataset.originalText;
344
+ delete submit.dataset.originalText;
345
+ return true;
346
+ }
347
+ return false;
348
+ }
349
+ static formatDate(date, format = "MM/DD/YYYY") {
350
+ const dateAray = date
351
+ .toLocaleDateString("en-US", {
352
+ year: "numeric",
353
+ month: "2-digit",
354
+ day: "2-digit",
355
+ })
356
+ .split("/");
357
+ const dateString = format
358
+ .replace(/YYYY/g, dateAray[2])
359
+ .replace(/MM/g, dateAray[0])
360
+ .replace(/DD/g, dateAray[1])
361
+ .replace(/YY/g, dateAray[2].substr(2, 2));
362
+ return dateString;
363
+ }
364
+ /**
365
+ * Check if the provided object has ALL the provided properties
366
+ * Example: checkNested(EngagingNetworks, 'require', '_defined', 'enjs', 'checkSubmissionFailed')
367
+ * will return true if EngagingNetworks.require._defined.enjs.checkSubmissionFailed is defined
368
+ */
369
+ static checkNested(obj, ...args) {
370
+ for (let i = 0; i < args.length; i++) {
371
+ if (!obj || !obj.hasOwnProperty(args[i])) {
372
+ return false;
373
+ }
374
+ obj = obj[args[i]];
375
+ }
376
+ return true;
377
+ }
378
+ // Deep merge two objects
379
+ static deepMerge(target, source) {
380
+ for (const key in source) {
381
+ if (source[key] instanceof Object)
382
+ Object.assign(source[key], ENGrid.deepMerge(target[key], source[key]));
383
+ }
384
+ Object.assign(target || {}, source);
385
+ return target;
386
+ }
387
+ static setError(element, errorMessage) {
388
+ const errorElement = typeof element === "string" ? document.querySelector(element) : element;
389
+ if (errorElement) {
390
+ errorElement.classList.add("en__field--validationFailed");
391
+ let errorMessageElement = errorElement.querySelector(".en__field__error");
392
+ if (!errorMessageElement) {
393
+ errorMessageElement = document.createElement("div");
394
+ errorMessageElement.classList.add("en__field__error");
395
+ errorMessageElement.innerHTML = errorMessage;
396
+ errorElement.insertBefore(errorMessageElement, errorElement.firstChild);
397
+ }
398
+ else {
399
+ errorMessageElement.innerHTML = errorMessage;
400
+ }
401
+ }
402
+ }
403
+ static removeError(element) {
404
+ const errorElement = typeof element === "string" ? document.querySelector(element) : element;
405
+ if (errorElement) {
406
+ errorElement.classList.remove("en__field--validationFailed");
407
+ const errorMessageElement = errorElement.querySelector(".en__field__error");
408
+ if (errorMessageElement) {
409
+ errorElement.removeChild(errorMessageElement);
410
+ }
411
+ }
412
+ }
413
+ static isVisible(element) {
414
+ if (!element) {
415
+ return false;
416
+ }
417
+ return !!(element.offsetWidth ||
418
+ element.offsetHeight ||
419
+ element.getClientRects().length);
420
+ }
421
+ static getCurrencySymbol() {
422
+ const currencyField = ENGrid.getField("transaction.paycurrency");
423
+ if (currencyField) {
424
+ // Check if the selected currency field option have a data-currency-symbol attribute
425
+ const selectedOption = currencyField.tagName === "SELECT"
426
+ ? currencyField.options[currencyField.selectedIndex]
427
+ : currencyField;
428
+ if (selectedOption.dataset.currencySymbol) {
429
+ return selectedOption.dataset.currencySymbol;
430
+ }
431
+ const currencyArray = {
432
+ USD: "$",
433
+ EUR: "€",
434
+ GBP: "£",
435
+ AUD: "$",
436
+ CAD: "$",
437
+ JPY: "¥",
438
+ };
439
+ return currencyArray[currencyField.value] || "$";
440
+ }
441
+ return ENGrid.getOption("CurrencySymbol") || "$";
442
+ }
443
+ static getCurrencyCode() {
444
+ const currencyField = ENGrid.getField("transaction.paycurrency");
445
+ if (currencyField) {
446
+ return currencyField.value || "USD";
447
+ }
448
+ return ENGrid.getOption("CurrencyCode") || "USD";
449
+ }
450
+ static addHtml(html, target = "body", position = "before") {
451
+ var _a, _b;
452
+ const targetElement = document.querySelector(target);
453
+ if (typeof html === "object") {
454
+ html = html.outerHTML;
455
+ }
456
+ if (targetElement) {
457
+ const htmlElement = document.createRange().createContextualFragment(html);
458
+ if (position === "before") {
459
+ (_a = targetElement.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(htmlElement, targetElement);
460
+ }
461
+ else {
462
+ (_b = targetElement.parentNode) === null || _b === void 0 ? void 0 : _b.insertBefore(htmlElement, targetElement.nextSibling);
463
+ }
464
+ }
465
+ }
466
+ static removeHtml(target) {
467
+ const targetElement = document.querySelector(target);
468
+ if (targetElement) {
469
+ targetElement.remove();
470
+ }
471
+ }
472
+ static slugify(text) {
473
+ return text
474
+ .toString()
475
+ .toLowerCase()
476
+ .replace(/\s+/g, "-") // Replace spaces with -
477
+ .replace(/[^\w\-]+/g, "") // Remove all non-word chars
478
+ .replace(/\-\-+/g, "-") // Replace multiple - with single -
479
+ .replace(/^-+/, "") // Trim - from start of text
480
+ .replace(/-+$/, ""); // Trim - from end of text
481
+ }
482
+ // This function is used to run a callback function when an error is displayed on the page
483
+ static watchForError(callback) {
484
+ const errorElement = document.querySelector(".en__errorList");
485
+ const capitalize = (word) => word.charAt(0).toUpperCase() + word.slice(1);
486
+ // Avoid duplicate callbacks
487
+ let callbackType = callback.toString();
488
+ if (callbackType.indexOf("function") === 0) {
489
+ callbackType = callbackType.replace("function ", "");
490
+ }
491
+ if (callbackType.indexOf("(") > 0) {
492
+ callbackType = callbackType.substring(0, callbackType.indexOf("("));
493
+ }
494
+ // Remove invalid characters
495
+ callbackType = callbackType.replace(/[^a-zA-Z0-9]/g, "");
496
+ // Limit to 20 characters and add prefix
497
+ callbackType = callbackType.substring(0, 20);
498
+ callbackType = "engrid" + capitalize(callbackType);
499
+ if (errorElement && !errorElement.dataset[callbackType]) {
500
+ errorElement.dataset[callbackType] = "true";
501
+ const observer = new MutationObserver(function (mutations) {
502
+ mutations.forEach(function (mutation) {
503
+ if (mutation.type === "childList" && mutation.addedNodes.length > 0) {
504
+ callback();
505
+ }
506
+ });
507
+ });
508
+ observer.observe(errorElement, { childList: true });
509
+ }
510
+ }
511
+ // Get the Payment Type
512
+ static getPaymentType() {
513
+ return ENGrid.getFieldValue("transaction.paymenttype");
514
+ }
515
+ // Set the Payment Type
516
+ static setPaymentType(paymentType) {
517
+ const enFieldPaymentType = ENGrid.getField("transaction.paymenttype");
518
+ if (enFieldPaymentType) {
519
+ const paymentTypeOption = Array.from(enFieldPaymentType.options).find((option) => paymentType.toLowerCase() === "card"
520
+ ? ["card", "visa", "vi"].includes(option.value.toLowerCase())
521
+ : paymentType.toLowerCase() === option.value.toLowerCase());
522
+ if (paymentTypeOption) {
523
+ paymentTypeOption.selected = true;
524
+ enFieldPaymentType.value = paymentTypeOption.value;
525
+ }
526
+ else {
527
+ enFieldPaymentType.value = paymentType;
528
+ }
529
+ const event = new Event("change", {
530
+ bubbles: true,
531
+ cancelable: true,
532
+ });
533
+ enFieldPaymentType.dispatchEvent(event);
534
+ }
535
+ }
536
+ static isInViewport(element) {
537
+ const rect = element.getBoundingClientRect();
538
+ return (rect.top >= 0 &&
539
+ rect.left >= 0 &&
540
+ rect.bottom <=
541
+ (window.innerHeight ||
542
+ document.documentElement.clientHeight) /* or $(window).height() */ &&
543
+ rect.right <=
544
+ (window.innerWidth ||
545
+ document.documentElement.clientWidth) /* or $(window).width() */);
546
+ }
547
+ }
@@ -0,0 +1,3 @@
1
+ export declare class EventTickets {
2
+ constructor();
3
+ }