@4site/engrid-scripts 0.20.3 → 0.20.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/data-attributes.d.ts +3 -0
- package/dist/data-attributes.js +36 -1
- package/dist/interfaces/options.d.ts +5 -0
- package/dist/interfaces/options.js +1 -0
- package/dist/optin-ladder.js +55 -13
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
package/dist/data-attributes.js
CHANGED
|
@@ -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
|
}
|
|
@@ -138,6 +138,11 @@ export interface Options {
|
|
|
138
138
|
placement: "beforebegin" | "afterbegin" | "beforeend" | "afterend";
|
|
139
139
|
};
|
|
140
140
|
};
|
|
141
|
+
OptInLadder?: false | {
|
|
142
|
+
iframeUrl: string;
|
|
143
|
+
placementQuerySelector?: string | null;
|
|
144
|
+
excludePageIDs?: string[];
|
|
145
|
+
};
|
|
141
146
|
onLoad?: () => void;
|
|
142
147
|
onResize?: () => void;
|
|
143
148
|
onSubmit?: () => void;
|
package/dist/optin-ladder.js
CHANGED
|
@@ -19,20 +19,62 @@ export class OptInLadder {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
runAsParent() {
|
|
22
|
-
// Grab all the checkboxes with the name starting with "supporter.questions"
|
|
23
|
-
const checkboxes = document.querySelectorAll('input[name^="supporter.questions"]');
|
|
24
|
-
if (checkboxes.length === 0) {
|
|
25
|
-
this.logger.log("No checkboxes found");
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
this._form.onSubmit.subscribe(() => {
|
|
29
|
-
// Save the checkbox values to sessionStorage
|
|
30
|
-
this.saveOptInsToSessionStorage("parent");
|
|
31
|
-
});
|
|
32
22
|
this.logger.log("Running as Parent");
|
|
33
|
-
if (ENGrid.getPageNumber() ===
|
|
34
|
-
//
|
|
35
|
-
|
|
23
|
+
if (ENGrid.getPageNumber() === ENGrid.getPageCount()) {
|
|
24
|
+
// We are on the Thank You Page as a Parent
|
|
25
|
+
// Check autoinject iFrame
|
|
26
|
+
const optInLadderOptions = ENGrid.getOption("OptInLadder");
|
|
27
|
+
if (!optInLadderOptions || !optInLadderOptions.iframeUrl) {
|
|
28
|
+
this.logger.log("Options not found");
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
// Create an iFrame
|
|
32
|
+
const iframe = document.createElement("iframe");
|
|
33
|
+
iframe.src = optInLadderOptions.iframeUrl;
|
|
34
|
+
iframe.style.width = "100%";
|
|
35
|
+
iframe.style.height = "0";
|
|
36
|
+
iframe.scrolling = "no";
|
|
37
|
+
iframe.frameBorder = "0";
|
|
38
|
+
iframe.allowFullscreen = true;
|
|
39
|
+
iframe.allow = "payment";
|
|
40
|
+
iframe.classList.add("opt-in-ladder-iframe");
|
|
41
|
+
iframe.classList.add("engrid-iframe");
|
|
42
|
+
// If the page already has an iFrame with the same class, we don't need to add another one
|
|
43
|
+
const existingIframe = document.querySelector(".opt-in-ladder-iframe");
|
|
44
|
+
if (existingIframe) {
|
|
45
|
+
this.logger.log("iFrame already exists");
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
// Check if the current page is part of the excludePageIDs
|
|
49
|
+
if (optInLadderOptions.excludePageIDs &&
|
|
50
|
+
optInLadderOptions.excludePageIDs.includes(ENGrid.getPageID())) {
|
|
51
|
+
this.logger.log("Current page is excluded");
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
// Append the iFrame to the proper placement
|
|
55
|
+
const placementQuerySelector = optInLadderOptions.placementQuerySelector || ".body-top";
|
|
56
|
+
const placement = document.querySelector(placementQuerySelector);
|
|
57
|
+
if (!placement) {
|
|
58
|
+
this.logger.error("Placement not found");
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
placement.appendChild(iframe);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
// Grab all the checkboxes with the name starting with "supporter.questions"
|
|
65
|
+
const checkboxes = document.querySelectorAll('input[name^="supporter.questions"]');
|
|
66
|
+
if (checkboxes.length === 0) {
|
|
67
|
+
this.logger.log("No checkboxes found");
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
this._form.onSubmit.subscribe(() => {
|
|
71
|
+
// Save the checkbox values to sessionStorage
|
|
72
|
+
this.saveOptInsToSessionStorage("parent");
|
|
73
|
+
});
|
|
74
|
+
if (ENGrid.getPageNumber() === 1) {
|
|
75
|
+
// Delete items from sessionStorage
|
|
76
|
+
this.clearSessionStorage();
|
|
77
|
+
}
|
|
36
78
|
}
|
|
37
79
|
}
|
|
38
80
|
runAsChildRegular() {
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const AppVersion = "0.20.
|
|
1
|
+
export declare const AppVersion = "0.20.5";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const AppVersion = "0.20.
|
|
1
|
+
export const AppVersion = "0.20.5";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@4site/engrid-scripts",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.5",
|
|
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": "
|
|
28
|
+
"gitHead": "71f471c85a474226a7929a40b1c0374cd83ac58e",
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"nodemon": "^2.0.20"
|
|
31
31
|
}
|