@4site/engrid-scripts 0.19.3 → 0.19.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.
- package/dist/iframe.d.ts +1 -1
- package/dist/iframe.js +88 -46
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
package/dist/iframe.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export declare class iFrame {
|
|
|
3
3
|
_form: EnForm;
|
|
4
4
|
private logger;
|
|
5
5
|
constructor();
|
|
6
|
+
private onLoaded;
|
|
6
7
|
private sendIframeHeight;
|
|
7
8
|
private sendIframeFormStatus;
|
|
8
9
|
private getIFrameByEvent;
|
|
@@ -11,6 +12,5 @@ export declare class iFrame {
|
|
|
11
12
|
private isChained;
|
|
12
13
|
private hideFormComponents;
|
|
13
14
|
private showFormComponents;
|
|
14
|
-
private addChainedBanner;
|
|
15
15
|
private debounceWithImmediate;
|
|
16
16
|
}
|
package/dist/iframe.js
CHANGED
|
@@ -7,23 +7,36 @@ export class iFrame {
|
|
|
7
7
|
if (this.inIframe()) {
|
|
8
8
|
// Add the data-engrid-embedded attribute when inside an iFrame if it wasn't already added by a script in the Page Template
|
|
9
9
|
ENGrid.setBodyData("embedded", "");
|
|
10
|
+
// Check if the parent page URL matches the criteria for a thank you page donation
|
|
11
|
+
const getParentUrl = () => {
|
|
12
|
+
try {
|
|
13
|
+
return window.parent.location.href;
|
|
14
|
+
}
|
|
15
|
+
catch (e) {
|
|
16
|
+
// If we can't access parent location due to same-origin policy, fall back to referrer
|
|
17
|
+
return document.referrer;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const parentUrl = getParentUrl();
|
|
21
|
+
const thankYouPageRegex = /\/page\/\d+\/[^\/]+\/(\d+)(\?|$)/;
|
|
22
|
+
const match = parentUrl.match(thankYouPageRegex);
|
|
23
|
+
if (match) {
|
|
24
|
+
const pageNumber = parseInt(match[1], 10);
|
|
25
|
+
if (pageNumber > 1) {
|
|
26
|
+
ENGrid.setBodyData("embedded", "thank-you-page-donation");
|
|
27
|
+
this.hideFormComponents();
|
|
28
|
+
this.logger.log("iFrame Event - Set embedded attribute to thank-you-page-donation");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
10
31
|
// Fire the resize event
|
|
11
32
|
this.logger.log("iFrame Event - Begin Resizing");
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
this.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
// On click fire the resize event
|
|
20
|
-
document.addEventListener("click", (e) => {
|
|
21
|
-
this.logger.log("iFrame Event - click");
|
|
22
|
-
setTimeout(() => {
|
|
23
|
-
this.sendIframeHeight();
|
|
24
|
-
}, 100);
|
|
25
|
-
});
|
|
26
|
-
});
|
|
33
|
+
// Run onLoaded function
|
|
34
|
+
if (document.readyState === "complete") {
|
|
35
|
+
this.onLoaded();
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
window.addEventListener("load", this.onLoaded.bind(this));
|
|
39
|
+
}
|
|
27
40
|
window.setTimeout(() => {
|
|
28
41
|
this.sendIframeHeight();
|
|
29
42
|
}, 300);
|
|
@@ -40,8 +53,7 @@ export class iFrame {
|
|
|
40
53
|
if (this.isChained() && ENGrid.getPaymentType()) {
|
|
41
54
|
this.logger.log("iFrame Event - Chained iFrame");
|
|
42
55
|
this.sendIframeFormStatus("chained");
|
|
43
|
-
this.
|
|
44
|
-
this.addChainedBanner();
|
|
56
|
+
// this.addChainedBanner();
|
|
45
57
|
}
|
|
46
58
|
// Remove the skip link markup when inside an iFrame
|
|
47
59
|
const skipLink = document.querySelector(".skip-link");
|
|
@@ -104,6 +116,21 @@ export class iFrame {
|
|
|
104
116
|
});
|
|
105
117
|
}
|
|
106
118
|
}
|
|
119
|
+
onLoaded() {
|
|
120
|
+
// Scroll to top of iFrame
|
|
121
|
+
this.logger.log("iFrame Event - window.onload");
|
|
122
|
+
this.sendIframeHeight();
|
|
123
|
+
window.parent.postMessage({
|
|
124
|
+
scroll: this.shouldScroll(),
|
|
125
|
+
}, "*");
|
|
126
|
+
// On click fire the resize event
|
|
127
|
+
document.addEventListener("click", (e) => {
|
|
128
|
+
this.logger.log("iFrame Event - click");
|
|
129
|
+
setTimeout(() => {
|
|
130
|
+
this.sendIframeHeight();
|
|
131
|
+
}, 100);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
107
134
|
sendIframeHeight() {
|
|
108
135
|
let height = document.body.offsetHeight;
|
|
109
136
|
this.logger.log("iFrame Event - Sending iFrame height of: " + height + "px"); // check the message is being sent correctly
|
|
@@ -152,20 +179,31 @@ export class iFrame {
|
|
|
152
179
|
return true;
|
|
153
180
|
}
|
|
154
181
|
}
|
|
182
|
+
// This method checks if the URL has a parameter named "chain" and returns true if it exists, otherwise false.
|
|
155
183
|
isChained() {
|
|
156
184
|
return !!ENGrid.getUrlParameter("chain");
|
|
157
185
|
}
|
|
158
186
|
hideFormComponents() {
|
|
159
187
|
this.logger.log("iFrame Event - Hiding Form Components");
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
188
|
+
const excludeClasses = [
|
|
189
|
+
"giveBySelect-Card",
|
|
190
|
+
"en__field--ccnumber",
|
|
191
|
+
"give-by-select",
|
|
192
|
+
"give-by-select-header",
|
|
193
|
+
"en__submit",
|
|
194
|
+
"en__captcha",
|
|
195
|
+
"force-visibility",
|
|
196
|
+
"hide",
|
|
197
|
+
"hide-iframe",
|
|
198
|
+
"radio-to-buttons_donationAmt",
|
|
199
|
+
];
|
|
200
|
+
const excludeIds = ["en__digitalWallet"];
|
|
201
|
+
const components = Array.from(document.querySelectorAll(".body-main > div:not(:last-child)"));
|
|
202
|
+
components.forEach((component) => {
|
|
203
|
+
const shouldExclude = excludeClasses.some((cls) => component.classList.contains(cls) ||
|
|
204
|
+
component.querySelector(`:scope > .${cls}`)) || excludeIds.some((id) => component.querySelector(`#${id}`));
|
|
205
|
+
if (!shouldExclude) {
|
|
206
|
+
component.classList.add("hide-iframe", "hide-chained");
|
|
169
207
|
}
|
|
170
208
|
});
|
|
171
209
|
this.sendIframeHeight();
|
|
@@ -179,26 +217,30 @@ export class iFrame {
|
|
|
179
217
|
});
|
|
180
218
|
this.sendIframeHeight();
|
|
181
219
|
}
|
|
182
|
-
addChainedBanner() {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
220
|
+
// private addChainedBanner() {
|
|
221
|
+
// this.logger.log("iFrame Event - Adding Chained Banner");
|
|
222
|
+
// const banner = document.createElement("div");
|
|
223
|
+
// const lastComponent = document.querySelector(
|
|
224
|
+
// ".body-main > div:last-of-type"
|
|
225
|
+
// ) as HTMLDivElement;
|
|
226
|
+
// banner.classList.add("en__component");
|
|
227
|
+
// banner.classList.add("en__component--banner");
|
|
228
|
+
// banner.classList.add("en__component--banner--chained");
|
|
229
|
+
// banner.innerHTML = `<div class="en__component__content"><div class="en__component__content__inner"><div class="en__component__content__text"><p>
|
|
230
|
+
// ${ENGrid.getFieldValue("supporter.firstName") ? `Giving as <strong>${ENGrid.getFieldValue("supporter.firstName")} ${ENGrid.getFieldValue("supporter.lastName")}</strong>` : "<strong>Testing as </strong>"}
|
|
231
|
+
// with <strong>${ENGrid.getFieldValue(
|
|
232
|
+
// "transaction.paymenttype"
|
|
233
|
+
// ).toUpperCase()}</strong>
|
|
234
|
+
// (<a href="#" class="en__component__content__link">change</a>)</p></div></div></div>`;
|
|
235
|
+
// lastComponent?.parentNode?.insertBefore(banner, lastComponent);
|
|
236
|
+
// banner
|
|
237
|
+
// .querySelector(".en__component__content__link")
|
|
238
|
+
// ?.addEventListener("click", (e) => {
|
|
239
|
+
// e.preventDefault();
|
|
240
|
+
// this.showFormComponents();
|
|
241
|
+
// banner.remove();
|
|
242
|
+
// });
|
|
243
|
+
// }
|
|
202
244
|
debounceWithImmediate(func, timeout = 1000) {
|
|
203
245
|
let timer;
|
|
204
246
|
let firstEvent = true;
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const AppVersion = "0.19.
|
|
1
|
+
export declare const AppVersion = "0.19.4";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const AppVersion = "0.19.
|
|
1
|
+
export const AppVersion = "0.19.4";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@4site/engrid-scripts",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.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": "
|
|
28
|
+
"gitHead": "27f831ac7133e8d98e5373c007bea75f3fb0dbfd",
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"nodemon": "^2.0.20"
|
|
31
31
|
}
|