@4site/engrid-scripts 0.19.3 → 0.19.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/iframe.d.ts +1 -1
- package/dist/iframe.js +93 -45
- 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,40 @@ 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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
this.logger.log("iFrame Event - click");
|
|
22
|
-
setTimeout(() => {
|
|
23
|
-
this.sendIframeHeight();
|
|
24
|
-
}, 100);
|
|
33
|
+
// Run onLoaded function
|
|
34
|
+
console.log("document.readyState", document.readyState);
|
|
35
|
+
// Document Load
|
|
36
|
+
if (document.readyState !== "loading") {
|
|
37
|
+
this.onLoaded();
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
document.addEventListener("DOMContentLoaded", () => {
|
|
41
|
+
this.onLoaded();
|
|
25
42
|
});
|
|
26
|
-
}
|
|
43
|
+
}
|
|
27
44
|
window.setTimeout(() => {
|
|
28
45
|
this.sendIframeHeight();
|
|
29
46
|
}, 300);
|
|
@@ -40,8 +57,7 @@ export class iFrame {
|
|
|
40
57
|
if (this.isChained() && ENGrid.getPaymentType()) {
|
|
41
58
|
this.logger.log("iFrame Event - Chained iFrame");
|
|
42
59
|
this.sendIframeFormStatus("chained");
|
|
43
|
-
this.
|
|
44
|
-
this.addChainedBanner();
|
|
60
|
+
// this.addChainedBanner();
|
|
45
61
|
}
|
|
46
62
|
// Remove the skip link markup when inside an iFrame
|
|
47
63
|
const skipLink = document.querySelector(".skip-link");
|
|
@@ -104,6 +120,23 @@ export class iFrame {
|
|
|
104
120
|
});
|
|
105
121
|
}
|
|
106
122
|
}
|
|
123
|
+
onLoaded() {
|
|
124
|
+
// Scroll to top of iFrame
|
|
125
|
+
this.logger.log("iFrame Event - window.onload");
|
|
126
|
+
this.sendIframeHeight();
|
|
127
|
+
window.parent.postMessage({
|
|
128
|
+
scroll: this.shouldScroll(),
|
|
129
|
+
}, "*");
|
|
130
|
+
// On click fire the resize event
|
|
131
|
+
document.addEventListener("click", (e) => {
|
|
132
|
+
this.logger.log("iFrame Event - click");
|
|
133
|
+
setTimeout(() => {
|
|
134
|
+
this.sendIframeHeight();
|
|
135
|
+
}, 100);
|
|
136
|
+
});
|
|
137
|
+
// Watch for errors and send the height
|
|
138
|
+
ENGrid.watchForError(this.sendIframeHeight.bind(this));
|
|
139
|
+
}
|
|
107
140
|
sendIframeHeight() {
|
|
108
141
|
let height = document.body.offsetHeight;
|
|
109
142
|
this.logger.log("iFrame Event - Sending iFrame height of: " + height + "px"); // check the message is being sent correctly
|
|
@@ -152,20 +185,31 @@ export class iFrame {
|
|
|
152
185
|
return true;
|
|
153
186
|
}
|
|
154
187
|
}
|
|
188
|
+
// This method checks if the URL has a parameter named "chain" and returns true if it exists, otherwise false.
|
|
155
189
|
isChained() {
|
|
156
190
|
return !!ENGrid.getUrlParameter("chain");
|
|
157
191
|
}
|
|
158
192
|
hideFormComponents() {
|
|
159
193
|
this.logger.log("iFrame Event - Hiding Form Components");
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
194
|
+
const excludeClasses = [
|
|
195
|
+
"giveBySelect-Card",
|
|
196
|
+
"en__field--ccnumber",
|
|
197
|
+
"give-by-select",
|
|
198
|
+
"give-by-select-header",
|
|
199
|
+
"en__submit",
|
|
200
|
+
"en__captcha",
|
|
201
|
+
"force-visibility",
|
|
202
|
+
"hide",
|
|
203
|
+
"hide-iframe",
|
|
204
|
+
"radio-to-buttons_donationAmt",
|
|
205
|
+
];
|
|
206
|
+
const excludeIds = ["en__digitalWallet"];
|
|
207
|
+
const components = Array.from(document.querySelectorAll(".body-main > div:not(:last-child)"));
|
|
208
|
+
components.forEach((component) => {
|
|
209
|
+
const shouldExclude = excludeClasses.some((cls) => component.classList.contains(cls) ||
|
|
210
|
+
component.querySelector(`:scope > .${cls}`)) || excludeIds.some((id) => component.querySelector(`#${id}`));
|
|
211
|
+
if (!shouldExclude) {
|
|
212
|
+
component.classList.add("hide-iframe", "hide-chained");
|
|
169
213
|
}
|
|
170
214
|
});
|
|
171
215
|
this.sendIframeHeight();
|
|
@@ -179,26 +223,30 @@ export class iFrame {
|
|
|
179
223
|
});
|
|
180
224
|
this.sendIframeHeight();
|
|
181
225
|
}
|
|
182
|
-
addChainedBanner() {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
226
|
+
// private addChainedBanner() {
|
|
227
|
+
// this.logger.log("iFrame Event - Adding Chained Banner");
|
|
228
|
+
// const banner = document.createElement("div");
|
|
229
|
+
// const lastComponent = document.querySelector(
|
|
230
|
+
// ".body-main > div:last-of-type"
|
|
231
|
+
// ) as HTMLDivElement;
|
|
232
|
+
// banner.classList.add("en__component");
|
|
233
|
+
// banner.classList.add("en__component--banner");
|
|
234
|
+
// banner.classList.add("en__component--banner--chained");
|
|
235
|
+
// banner.innerHTML = `<div class="en__component__content"><div class="en__component__content__inner"><div class="en__component__content__text"><p>
|
|
236
|
+
// ${ENGrid.getFieldValue("supporter.firstName") ? `Giving as <strong>${ENGrid.getFieldValue("supporter.firstName")} ${ENGrid.getFieldValue("supporter.lastName")}</strong>` : "<strong>Testing as </strong>"}
|
|
237
|
+
// with <strong>${ENGrid.getFieldValue(
|
|
238
|
+
// "transaction.paymenttype"
|
|
239
|
+
// ).toUpperCase()}</strong>
|
|
240
|
+
// (<a href="#" class="en__component__content__link">change</a>)</p></div></div></div>`;
|
|
241
|
+
// lastComponent?.parentNode?.insertBefore(banner, lastComponent);
|
|
242
|
+
// banner
|
|
243
|
+
// .querySelector(".en__component__content__link")
|
|
244
|
+
// ?.addEventListener("click", (e) => {
|
|
245
|
+
// e.preventDefault();
|
|
246
|
+
// this.showFormComponents();
|
|
247
|
+
// banner.remove();
|
|
248
|
+
// });
|
|
249
|
+
// }
|
|
202
250
|
debounceWithImmediate(func, timeout = 1000) {
|
|
203
251
|
let timer;
|
|
204
252
|
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.5";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const AppVersion = "0.19.
|
|
1
|
+
export const AppVersion = "0.19.5";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@4site/engrid-scripts",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.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": "b0e2cba40e66bb5f6fc2867c5baf344d7ce58201",
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"nodemon": "^2.0.20"
|
|
31
31
|
}
|