@4site/engrid-scripts 0.20.2 → 0.20.4

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.
@@ -1,6 +1,9 @@
1
1
  export declare class DataAttributes {
2
+ private logger;
2
3
  private _country;
4
+ private _frequency;
3
5
  constructor();
4
6
  private setDataAttributes;
5
7
  private addFrequencyDataAttribute;
8
+ private addGiftAmountDataAttribute;
6
9
  }
@@ -1,8 +1,10 @@
1
1
  // Component that adds data attributes to the Body
2
- import { ENGrid, Country } from ".";
2
+ import { ENGrid, Country, DonationFrequency, EngridLogger } from ".";
3
3
  export class DataAttributes {
4
4
  constructor() {
5
+ this.logger = new EngridLogger("Data Attribute Changed", "#FFFFFF", "#4d9068", "🛠️");
5
6
  this._country = Country.getInstance();
7
+ this._frequency = DonationFrequency.getInstance();
6
8
  this.setDataAttributes();
7
9
  }
8
10
  setDataAttributes() {
@@ -135,6 +137,7 @@ export class DataAttributes {
135
137
  }
136
138
  if (ENGrid.getPageType() === "DONATION") {
137
139
  this.addFrequencyDataAttribute();
140
+ this.addGiftAmountDataAttribute();
138
141
  }
139
142
  }
140
143
  // Add a data attribute to the body tag with how many visible frequency options there are
@@ -148,4 +151,36 @@ export class DataAttributes {
148
151
  });
149
152
  ENGrid.setBodyData("visible-frequency", visibleFrequencyOptions.toString());
150
153
  }
154
+ // Add a data attribute to the body tag with how many visible gift amount options there are
155
+ addGiftAmountDataAttribute() {
156
+ const updateGiftAmountData = () => {
157
+ const giftAmountOptions = document.querySelectorAll(".en__field--donationAmt .en__field__element .en__field__item");
158
+ let visibleGiftAmountOptions = 0;
159
+ giftAmountOptions.forEach((option) => {
160
+ if (ENGrid.isVisible(option)) {
161
+ visibleGiftAmountOptions++;
162
+ }
163
+ });
164
+ ENGrid.setBodyData("visible-gift-amount", visibleGiftAmountOptions.toString());
165
+ this.logger.log("Visible Gift Amount Changed to: " + visibleGiftAmountOptions.toString());
166
+ };
167
+ // Initial update
168
+ updateGiftAmountData();
169
+ // Observe changes in the donation amount section
170
+ const observer = new MutationObserver(updateGiftAmountData);
171
+ const targetNode = document.querySelector(".en__field--donationAmt");
172
+ if (targetNode) {
173
+ observer.observe(targetNode, {
174
+ childList: true,
175
+ subtree: true,
176
+ attributes: true,
177
+ });
178
+ }
179
+ // Run update updateGiftAmountData when frequency changes
180
+ this._frequency.onFrequencyChange.subscribe(() => {
181
+ setTimeout(() => {
182
+ updateGiftAmountData();
183
+ }, 10);
184
+ });
185
+ }
151
186
  }
@@ -11,4 +11,5 @@ export declare class OptInLadder {
11
11
  private saveOptInsToSessionStorage;
12
12
  private isEmbeddedThankYouPage;
13
13
  private hidePage;
14
+ private clearSessionStorage;
14
15
  }
@@ -27,12 +27,12 @@ export class OptInLadder {
27
27
  }
28
28
  this._form.onSubmit.subscribe(() => {
29
29
  // Save the checkbox values to sessionStorage
30
- this.saveOptInsToSessionStorage();
30
+ this.saveOptInsToSessionStorage("parent");
31
31
  });
32
32
  this.logger.log("Running as Parent");
33
33
  if (ENGrid.getPageNumber() === 1) {
34
- // Delete supporter.questions from sessionStorage
35
- sessionStorage.removeItem("engrid.supporter.questions");
34
+ // Delete items from sessionStorage
35
+ this.clearSessionStorage();
36
36
  }
37
37
  }
38
38
  runAsChildRegular() {
@@ -123,7 +123,7 @@ export class OptInLadder {
123
123
  this.saveStepToSessionStorage(currentStep, totalSteps);
124
124
  // On form submit, save the checkbox values to sessionStorage
125
125
  this._form.onSubmit.subscribe(() => {
126
- this.saveOptInsToSessionStorage();
126
+ this.saveOptInsToSessionStorage("child");
127
127
  // Save the current step to sessionStorage
128
128
  currentStep++;
129
129
  this.saveStepToSessionStorage(currentStep, totalSteps);
@@ -134,19 +134,25 @@ export class OptInLadder {
134
134
  this.logger.log("Not Embedded on a Thank You Page");
135
135
  return;
136
136
  }
137
+ const hasOptInLadderStop = sessionStorage.getItem("engrid.optin-ladder-stop");
138
+ if (hasOptInLadderStop) {
139
+ this.logger.log("OptInLadder has been stopped");
140
+ return;
141
+ }
137
142
  const sessionStorageOptInLadder = JSON.parse(sessionStorage.getItem("engrid.optin-ladder") || "{}");
138
143
  const currentStep = sessionStorageOptInLadder.step || 0;
139
144
  const totalSteps = sessionStorageOptInLadder.totalSteps || 0;
140
- if (currentStep < totalSteps) {
141
- this.logger.log(`Current step ${currentStep} is less than total steps ${totalSteps}`);
145
+ if (currentStep <= totalSteps) {
146
+ this.logger.log(`Current step ${currentStep} is less or equal to total steps ${totalSteps}`);
147
+ this.hidePage();
142
148
  // Redirect to the first page
143
149
  window.location.href = this.getFirstPageUrl();
144
150
  return;
145
151
  }
146
152
  else {
147
- this.logger.log(`Current step ${currentStep} is equal to total steps ${totalSteps}`);
153
+ this.logger.log(`Current step ${currentStep} is greater than total steps ${totalSteps}`);
148
154
  // Remove the session storage
149
- sessionStorage.removeItem("engrid.optin-ladder");
155
+ this.clearSessionStorage();
150
156
  }
151
157
  }
152
158
  inIframe() {
@@ -169,7 +175,7 @@ export class OptInLadder {
169
175
  path.push("1");
170
176
  return url.origin + path.join("/") + "?chain";
171
177
  }
172
- saveOptInsToSessionStorage() {
178
+ saveOptInsToSessionStorage(type = "parent") {
173
179
  // Grab all the checkboxes with the name starting with "supporter.questions"
174
180
  const checkboxes = document.querySelectorAll('input[name^="supporter.questions"]');
175
181
  if (checkboxes.length === 0) {
@@ -177,15 +183,23 @@ export class OptInLadder {
177
183
  return;
178
184
  }
179
185
  const sessionStorageCheckboxValues = JSON.parse(sessionStorage.getItem("engrid.supporter.questions") || "{}");
186
+ let hasDeny = false;
180
187
  // Loop through all the checkboxes and store the value in sessionStorage
181
188
  checkboxes.forEach((checkbox) => {
182
189
  if (checkbox.checked) {
183
190
  const index = checkbox.name.split(".")[2];
184
191
  sessionStorageCheckboxValues[index] = "Y";
185
192
  }
193
+ else {
194
+ hasDeny = true;
195
+ }
186
196
  });
187
197
  sessionStorage.setItem("engrid.supporter.questions", JSON.stringify(sessionStorageCheckboxValues));
188
198
  this.logger.log(`Saved checkbox values to sessionStorage: ${JSON.stringify(sessionStorageCheckboxValues)}`);
199
+ if (type === "child" && hasDeny) {
200
+ // Add a deny value to the sessionStorage to stop the ladder
201
+ sessionStorage.setItem("engrid.optin-ladder-stop", "Y");
202
+ }
189
203
  }
190
204
  isEmbeddedThankYouPage() {
191
205
  return ENGrid.getBodyData("embedded") === "thank-you-page-donation";
@@ -196,4 +210,9 @@ export class OptInLadder {
196
210
  engridPage.classList.add("hide");
197
211
  }
198
212
  }
213
+ clearSessionStorage() {
214
+ sessionStorage.removeItem("engrid.supporter.questions");
215
+ sessionStorage.removeItem("engrid.optin-ladder");
216
+ sessionStorage.removeItem("engrid.optin-ladder-stop");
217
+ }
199
218
  }
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const AppVersion = "0.20.2";
1
+ export declare const AppVersion = "0.20.4";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const AppVersion = "0.20.2";
1
+ export const AppVersion = "0.20.4";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@4site/engrid-scripts",
3
- "version": "0.20.2",
3
+ "version": "0.20.4",
4
4
  "description": "Scripts for the ENGRID Project",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -25,7 +25,7 @@
25
25
  "strongly-typed-events": "^2.0.9"
26
26
  },
27
27
  "homepage": "https://github.com/4site-interactive-studios/engrid#readme",
28
- "gitHead": "adb404739290088346c897570c1a587d4fe30f99",
28
+ "gitHead": "11e6a1d7af282dc9f3601368f16ac82616aa5e3c",
29
29
  "devDependencies": {
30
30
  "nodemon": "^2.0.20"
31
31
  }