@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/vgs.js ADDED
@@ -0,0 +1,250 @@
1
+ // This component allows you to customize the VGS theme options
2
+ //
3
+ // It is used in the following way:
4
+ //
5
+ // VGS: {
6
+ // "transaction.ccnumber": {
7
+ // showCardIcon: true,
8
+ // placeholder: "•••• •••• •••• ••••",
9
+ // icons: {
10
+ // (icons can't be urls, they have to be base64 encoded images)
11
+ // cardPlaceholder: "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='24px' viewBox='0 0 24 24' width='24px' fill='%233BBF45'%3E%3Cpath d='M0 0h24v24H0z' fill='none'/%3E%3Cpath d='M21 18v1c0 1.1-.9 2-2 2H5c-1.11 0-2-.9-2-2V5c0-1.1.89-2 2-2h14c1.1 0 2 .9 2 2v1h-9c-1.11 0-2 .9-2 2v8c0 1.1.89 2 2 2h9zm-9-2h10V8H12v8zm4-2.5c-.83 0-1.5-.67-1.5-1.5s.67-1.5 1.5-1.5 1.5.67 1.5 1.5-.67 1.5-1.5 1.5z'/%3E%3C/svg%3E"
12
+ // visa: "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 384 512'%3E%3Cpath fill='%233BBF45' d='M384 32H0v448h384V32z'/%3E%3Cpath fill='white' d='M128.5 352.5l-32-192h-32l32 192zm96-192l-32 192h-32l32-192z'/%3E%3C/svg%3E",
13
+ // },
14
+ // },
15
+ // "transaction.ccvv": {
16
+ // showCardIcon: false,
17
+ // placeholder: "CVV",
18
+ // hideValue: false,
19
+ // },
20
+ // },
21
+ //
22
+ // The VGS component can also be set at the page level, if necessary
23
+ //
24
+ import { ENGrid, EnForm, EngridLogger } from ".";
25
+ export class VGS {
26
+ constructor() {
27
+ this.logger = new EngridLogger("VGS", "black", "pink", "💳");
28
+ this.vgsField = document.querySelector(".en__field--vgs");
29
+ this.options = ENGrid.getOption("VGS");
30
+ this.paymentTypeField = document.querySelector("#en__field_transaction_paymenttype");
31
+ this._form = EnForm.getInstance();
32
+ this.field_expiration_month = null;
33
+ this.field_expiration_year = null;
34
+ this.handleExpUpdate = (e) => {
35
+ if (!this.field_expiration_month || !this.field_expiration_year)
36
+ return;
37
+ const current_date = new Date();
38
+ const current_month = current_date.getMonth() + 1;
39
+ const current_year = parseInt(this.field_expiration_year[this.field_expiration_year.length - 1].value) > 2000
40
+ ? current_date.getFullYear()
41
+ : current_date.getFullYear() - 2000;
42
+ // handle if year is changed to current year (disable all months less than current month)
43
+ // handle if month is changed to less than current month (disable current year)
44
+ if (e == "month") {
45
+ let selected_month = parseInt(this.field_expiration_month.value);
46
+ let disable = selected_month < current_month;
47
+ this.logger.log(`month disable ${disable}`);
48
+ this.logger.log(`selected_month ${selected_month}`);
49
+ for (let i = 0; i < this.field_expiration_year.options.length; i++) {
50
+ // disable or enable current year
51
+ if (parseInt(this.field_expiration_year.options[i].value) <= current_year) {
52
+ if (disable) {
53
+ this.field_expiration_year.options[i].setAttribute("disabled", "disabled");
54
+ }
55
+ else {
56
+ this.field_expiration_year.options[i].disabled = false;
57
+ }
58
+ }
59
+ }
60
+ }
61
+ else if (e == "year") {
62
+ let selected_year = parseInt(this.field_expiration_year.value);
63
+ let disable = selected_year == current_year;
64
+ this.logger.log(`year disable ${disable}`);
65
+ this.logger.log(`selected_year ${selected_year}`);
66
+ for (let i = 0; i < this.field_expiration_month.options.length; i++) {
67
+ // disable or enable all months less than current month
68
+ if (parseInt(this.field_expiration_month.options[i].value) < current_month) {
69
+ if (disable) {
70
+ this.field_expiration_month.options[i].setAttribute("disabled", "disabled");
71
+ }
72
+ else {
73
+ this.field_expiration_month.options[i].disabled = false;
74
+ }
75
+ }
76
+ }
77
+ }
78
+ };
79
+ if (!this.shouldRun())
80
+ return;
81
+ this.setPaymentType();
82
+ this.setDefaults();
83
+ this.dumpGlobalVar();
84
+ const expireFiels = document.getElementsByName("transaction.ccexpire");
85
+ if (expireFiels) {
86
+ this.field_expiration_month = expireFiels[0];
87
+ this.field_expiration_year = expireFiels[1];
88
+ }
89
+ // Add event listeners to the expiration fields
90
+ if (this.field_expiration_month && this.field_expiration_year) {
91
+ ["change"].forEach((event) => {
92
+ var _a, _b;
93
+ (_a = this.field_expiration_month) === null || _a === void 0 ? void 0 : _a.addEventListener(event, () => {
94
+ this.handleExpUpdate("month");
95
+ });
96
+ (_b = this.field_expiration_year) === null || _b === void 0 ? void 0 : _b.addEventListener(event, () => {
97
+ this.handleExpUpdate("year");
98
+ });
99
+ });
100
+ }
101
+ this._form.onValidate.subscribe(() => {
102
+ if (this._form.validate) {
103
+ const isValid = this.validate();
104
+ this.logger.log(`Form Validation: ${isValid}`);
105
+ this._form.validate = isValid;
106
+ }
107
+ });
108
+ }
109
+ shouldRun() {
110
+ // Only run if the vgs field is present
111
+ if (!this.vgsField)
112
+ return false;
113
+ return true;
114
+ }
115
+ setDefaults() {
116
+ //EN attempts to define a few default styles for VGS fields based on our text field styling
117
+ //This does not always work, so we will provide our own defaults
118
+ const bodyStyles = getComputedStyle(document.body);
119
+ const styles = {
120
+ fontFamily: bodyStyles.getPropertyValue("--input_font-family") ||
121
+ "-apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji'",
122
+ fontSize: bodyStyles.getPropertyValue("--input_font-size") || "16px",
123
+ color: bodyStyles.getPropertyValue("--input_color") || "#000",
124
+ padding: bodyStyles.getPropertyValue("--input_padding") || "10px",
125
+ "&::placeholder": {
126
+ color: bodyStyles.getPropertyValue("--input_placeholder-color") || "#a9a9a9",
127
+ opacity: bodyStyles.getPropertyValue("--input_placeholder-opacity") || "1",
128
+ fontWeight: bodyStyles.getPropertyValue("--input_placeholder-font-weight") ||
129
+ "normal",
130
+ },
131
+ };
132
+ const options = this.options;
133
+ const defaultOptions = {
134
+ "transaction.ccnumber": {
135
+ showCardIcon: true,
136
+ placeholder: "•••• •••• •••• ••••",
137
+ icons: {
138
+ cardPlaceholder: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEwAAABMCAYAAADHl1ErAAAACXBIWXMAABYlAAAWJQFJUiTwAAAB8ElEQVR4nO2c4W3CMBBGz1H/NyNkAzoCo2SDrkI3YJSOABt0g9IJXBnOqUkMyifUqkrek04RlvMjT2c7sc6EGKPBfBpcaSBMBGEiCBNBmAjCRBAmgjARhIkgTARhIggTQZhK2q0Yh5l1ZrYzs0PqsrI4+LN3VTeThkvntUm6Fbuxn2E/LITQmtm7mW08Sb/MbO9tpxhjui6WEMLWzJKDdO3N7Nmf9ZjaYoyn8y8X1o6GXxLV1lJyDeE+9oWPQ/ZRG4b9WkVVpqe+8LLLo7ErM6t248qllZnWBc+uV5+zumGsQjm3f/ic9tb4JGeeXcga4U723rptilVx0avgg2Q3m/JNn+y6zeAm+GSWUi/c7L5yfB77RJhACOHs6WnuLfmGpTI3YditEEGYCMJEECaCMJHZqySvHRfIMBGEiSBMBGEiCBNBmAjCRBAmgjARhIkgTGT2t+R/59EdYXZcfwmEiSBMBGEiCBNZzCr5VzvCZJjIIMxrPKFC6abMsHbaFcZuGq8StqKwDqZkN8emKBbrvawHCtxJ7y1nVxQF34lxUXBupOy8EtWy88jBhknUDjbkPhyd+Xn2l9lHZ8rgcNZVTA5nTYRFjv/dPf7HvzuJ8C0pgjARhIkgTARhIggTQZgIwkQQJoIwEYSJIEwEYQpm9g2Ro5zhLcuLBwAAAABJRU5ErkJggg==",
139
+ },
140
+ css: styles,
141
+ // Autocomplete is not customizable
142
+ autoComplete: "cc-number",
143
+ validations: ["required", "validCardNumber"],
144
+ },
145
+ "transaction.ccvv": {
146
+ showCardIcon: false,
147
+ placeholder: "CVV",
148
+ hideValue: false,
149
+ // Autocomplete is not customizable
150
+ autoComplete: "cc-csc",
151
+ validations: ["required", "validCardSecurityCode"],
152
+ css: styles,
153
+ },
154
+ "transaction.ccexpire": {
155
+ placeholder: "MM/YY",
156
+ autoComplete: "cc-exp",
157
+ validations: ["required", "validCardExpirationDate"],
158
+ css: styles,
159
+ yearLength: 2,
160
+ },
161
+ };
162
+ // Deep merge the default options with the options set in the theme
163
+ this.options = ENGrid.deepMerge(defaultOptions, options);
164
+ this.logger.log("Options", this.options);
165
+ }
166
+ setPaymentType() {
167
+ // If there's no default payment type, set the default to card
168
+ if (ENGrid.getPaymentType() === "") {
169
+ ENGrid.setPaymentType("card");
170
+ }
171
+ }
172
+ dumpGlobalVar() {
173
+ // Dump the global variable for the VGS options
174
+ window.enVGSFields = this.options;
175
+ // EN is not reading the global variable because their JS file loads before ENgrid, so we're going to HACK TOWN
176
+ // Clean up the VGS iFrames
177
+ window.setTimeout(() => {
178
+ const vgsIElements = document.querySelectorAll(".en__field__input--vgs");
179
+ if (vgsIElements.length > 0) {
180
+ // Create a mutation observer that cleans the VGS Elements before anything is rendered
181
+ const observer = new MutationObserver((mutations) => {
182
+ mutations.forEach((mutation) => {
183
+ var _a;
184
+ if (mutation.type === "childList" &&
185
+ mutation.addedNodes.length > 0) {
186
+ mutation.addedNodes.forEach((node) => {
187
+ if (node.nodeName === "IFRAME" &&
188
+ mutation.previousSibling &&
189
+ mutation.previousSibling.nodeName === "IFRAME") {
190
+ // Delete the previous sibling
191
+ mutation.previousSibling.remove();
192
+ }
193
+ });
194
+ }
195
+ // Check if the VGS Element is valid, and remove any validation classes and errors
196
+ if (mutation.type === "attributes" &&
197
+ mutation.attributeName === "class") {
198
+ const target = mutation.target;
199
+ if (target.classList.contains("vgs-collect-container__valid")) {
200
+ const fieldWrapper = target.closest(".en__field--vgs");
201
+ fieldWrapper === null || fieldWrapper === void 0 ? void 0 : fieldWrapper.classList.remove("en__field--validationFailed");
202
+ (_a = fieldWrapper === null || fieldWrapper === void 0 ? void 0 : fieldWrapper.querySelector(".en__field__error")) === null || _a === void 0 ? void 0 : _a.remove();
203
+ }
204
+ }
205
+ });
206
+ });
207
+ // Observe the VGS Elements
208
+ vgsIElements.forEach((vgsIElement) => {
209
+ observer.observe(vgsIElement, {
210
+ childList: true,
211
+ attributeFilter: ["class"],
212
+ });
213
+ });
214
+ if (ENGrid.checkNested(window.EngagingNetworks, "require", "_defined", "enjs", "vgs")) {
215
+ window.EngagingNetworks.require._defined.enjs.vgs.init();
216
+ }
217
+ else {
218
+ this.logger.log("VGS is not defined");
219
+ }
220
+ }
221
+ }, 1000);
222
+ }
223
+ validate() {
224
+ if (this.paymentTypeField.value.toLowerCase() === "card" ||
225
+ this.paymentTypeField.value.toLowerCase() === "visa" ||
226
+ this.paymentTypeField.value.toLowerCase() === "vi") {
227
+ const cardContainer = document.querySelector(".en__field--vgs.en__field--ccnumber");
228
+ const cardEmpty = cardContainer.querySelector(".vgs-collect-container__empty");
229
+ const cvvContainer = document.querySelector(".en__field--vgs.en__field--ccvv");
230
+ const cvvEmpty = cvvContainer.querySelector(".vgs-collect-container__empty");
231
+ if (cardContainer && cardEmpty) {
232
+ window.setTimeout(() => {
233
+ ENGrid.setError(cardContainer, "Please enter a valid card number");
234
+ // Scroll to the error
235
+ cardContainer.scrollIntoView({ behavior: "smooth" });
236
+ }, 100);
237
+ return false;
238
+ }
239
+ if (cvvContainer && cvvEmpty) {
240
+ window.setTimeout(() => {
241
+ ENGrid.setError(cvvContainer, "Please enter a valid CVV");
242
+ // Scroll to the error
243
+ cvvContainer.scrollIntoView({ behavior: "smooth" });
244
+ }, 100);
245
+ return false;
246
+ }
247
+ }
248
+ return true;
249
+ }
250
+ }
@@ -0,0 +1,10 @@
1
+ export declare class WelcomeBack {
2
+ private supporterDetails;
3
+ private options;
4
+ constructor();
5
+ private shouldRun;
6
+ private addWelcomeBack;
7
+ private resetWelcomeBack;
8
+ private addPersonalDetailsSummary;
9
+ private addEventListeners;
10
+ }
@@ -0,0 +1,112 @@
1
+ /**
2
+ * This component adds a welcome back message and a personal details summary to the page.
3
+ * It depends on the "fast-personal-details" functionality from the FastFormFill component.
4
+ * The component will only run, when the "WelcomeBack" option is set,
5
+ * if the "fast-personal-details" class is present on the page and the FastFormFill conditions
6
+ * are met (all mandatory inputs in that block are filled).
7
+ *
8
+ * All the text content and positioning is configurable through the "WelcomeBack" option.
9
+ */
10
+ import { ENGrid } from ".";
11
+ import * as cookie from "./cookie";
12
+ export class WelcomeBack {
13
+ constructor() {
14
+ var _a;
15
+ this.supporterDetails = {};
16
+ this.options = (_a = ENGrid.getOption("WelcomeBack")) !== null && _a !== void 0 ? _a : false;
17
+ if (this.shouldRun()) {
18
+ this.supporterDetails = {
19
+ firstName: ENGrid.getFieldValue("supporter.firstName"),
20
+ lastName: ENGrid.getFieldValue("supporter.lastName"),
21
+ emailAddress: ENGrid.getFieldValue("supporter.emailAddress"),
22
+ address1: ENGrid.getFieldValue("supporter.address1"),
23
+ address2: ENGrid.getFieldValue("supporter.address2"),
24
+ city: ENGrid.getFieldValue("supporter.city"),
25
+ region: ENGrid.getFieldValue("supporter.region"),
26
+ postcode: ENGrid.getFieldValue("supporter.postcode"),
27
+ country: ENGrid.getFieldValue("supporter.country"),
28
+ };
29
+ this.addWelcomeBack();
30
+ this.addPersonalDetailsSummary();
31
+ this.addEventListeners();
32
+ }
33
+ }
34
+ shouldRun() {
35
+ return (!!document.querySelector(".fast-personal-details") &&
36
+ this.options !== false);
37
+ }
38
+ addWelcomeBack() {
39
+ var _a;
40
+ if (typeof this.options !== "object" ||
41
+ !this.options.welcomeBackMessage.display)
42
+ return;
43
+ const options = this.options.welcomeBackMessage;
44
+ const welcomeBack = document.createElement("div");
45
+ welcomeBack.classList.add("engrid-welcome-back", "showif-fast-personal-details");
46
+ const title = options.title.replace("{firstName}", this.supporterDetails["firstName"]);
47
+ welcomeBack.innerHTML = `<p>
48
+ ${title}
49
+ <span class="engrid-reset-welcome-back">${options.editText}</span>
50
+ </p>`;
51
+ (_a = document
52
+ .querySelector(options.anchor)) === null || _a === void 0 ? void 0 : _a.insertAdjacentElement(options.placement, welcomeBack);
53
+ }
54
+ resetWelcomeBack() {
55
+ const inputs = document.querySelectorAll(".fast-personal-details .en__field__input");
56
+ inputs.forEach((input) => {
57
+ if (input.type === "checkbox" || input.type === "radio") {
58
+ input.checked = false;
59
+ }
60
+ else {
61
+ input.value = "";
62
+ }
63
+ });
64
+ this.supporterDetails = {};
65
+ ENGrid.setBodyData("hide-fast-personal-details", false);
66
+ cookie.remove("engrid-autofill");
67
+ }
68
+ addPersonalDetailsSummary() {
69
+ var _a;
70
+ if (typeof this.options !== "object" ||
71
+ !this.options.personalDetailsSummary.display)
72
+ return;
73
+ let options = this.options.personalDetailsSummary;
74
+ const personalDetailsSummary = document.createElement("div");
75
+ personalDetailsSummary.classList.add("engrid-personal-details-summary", "showif-fast-personal-details");
76
+ personalDetailsSummary.innerHTML = `<h3>${options.title}</h3>`;
77
+ personalDetailsSummary.insertAdjacentHTML("beforeend", `
78
+ <p>
79
+ ${this.supporterDetails["firstName"]} ${this.supporterDetails["lastName"]}
80
+ <br>
81
+ ${this.supporterDetails["emailAddress"]}
82
+ </p>
83
+ `);
84
+ if (this.supporterDetails["address1"] &&
85
+ this.supporterDetails["city"] &&
86
+ this.supporterDetails["region"] &&
87
+ this.supporterDetails["postcode"]) {
88
+ personalDetailsSummary.insertAdjacentHTML("beforeend", `
89
+ <p>
90
+ ${this.supporterDetails["address1"]} ${this.supporterDetails["address2"]}
91
+ <br>
92
+ ${this.supporterDetails["city"]}, ${this.supporterDetails["region"]}
93
+ ${this.supporterDetails["postcode"]}
94
+ </p>
95
+ `);
96
+ }
97
+ personalDetailsSummary.insertAdjacentHTML("beforeend", `
98
+ <p class="engrid-welcome-back-clear setattr--data-engrid-hide-fast-personal-details--false">${options.editText}<svg viewbox="0 0 528.899 528.899" xmlns="http://www.w3.org/2000/svg"> <g> <path d="M328.883,89.125l107.59,107.589l-272.34,272.34L56.604,361.465L328.883,89.125z M518.113,63.177l-47.981-47.981 c-18.543-18.543-48.653-18.543-67.259,0l-45.961,45.961l107.59,107.59l53.611-53.611 C532.495,100.753,532.495,77.559,518.113,63.177z M0.3,512.69c-1.958,8.812,5.998,16.708,14.811,14.565l119.891-29.069 L27.473,390.597L0.3,512.69z"></path></g></svg></p>
99
+ `);
100
+ (_a = document
101
+ .querySelector(options.anchor)) === null || _a === void 0 ? void 0 : _a.insertAdjacentElement(options.placement, personalDetailsSummary);
102
+ }
103
+ addEventListeners() {
104
+ document
105
+ .querySelectorAll(".engrid-reset-welcome-back")
106
+ .forEach((element) => {
107
+ element.addEventListener("click", () => {
108
+ this.resetWelcomeBack();
109
+ });
110
+ });
111
+ }
112
+ }
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@4site/engrid-scripts",
3
+ "version": "0.19.1",
4
+ "description": "Scripts for the ENGRID Project",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "prepublishOnly": "npm run build",
10
+ "postpublish": "git push origin --tags",
11
+ "watch": "nodemon -w src -e json,ts -x npm run build"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/4site-interactive-studios/engrid.git",
16
+ "directory": "packages/scripts"
17
+ },
18
+ "author": "4Site Studios",
19
+ "license": "Unlicense",
20
+ "bugs": {
21
+ "url": "https://github.com/4site-interactive-studios/engrid/issues"
22
+ },
23
+ "dependencies": {
24
+ "shuffle-seed": "^1.1.6",
25
+ "strongly-typed-events": "^2.0.9"
26
+ },
27
+ "homepage": "https://github.com/4site-interactive-studios/engrid#readme",
28
+ "gitHead": "051783968da1bb3e8fcad6c2e5180c2247c0ffa7",
29
+ "devDependencies": {
30
+ "nodemon": "^2.0.20"
31
+ }
32
+ }