@4site/engrid-scripts 0.20.8 → 0.20.10
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/embedded-ecard.d.ts +4 -0
- package/dist/embedded-ecard.js +77 -15
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
package/dist/embedded-ecard.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ export declare class EmbeddedEcard {
|
|
|
3
3
|
private readonly options;
|
|
4
4
|
private _form;
|
|
5
5
|
isSubmitting: boolean;
|
|
6
|
+
ecardFormActive: boolean;
|
|
7
|
+
iframe: HTMLIFrameElement | null;
|
|
6
8
|
constructor();
|
|
7
9
|
private onHostPage;
|
|
8
10
|
private onEmbeddedEcardPage;
|
|
@@ -10,6 +12,8 @@ export declare class EmbeddedEcard {
|
|
|
10
12
|
private embedEcard;
|
|
11
13
|
private createIframe;
|
|
12
14
|
private addEventListeners;
|
|
15
|
+
private validateRecipients;
|
|
16
|
+
private toggleEcardForm;
|
|
13
17
|
private setEmbeddedEcardSessionData;
|
|
14
18
|
private getEcardRecipients;
|
|
15
19
|
private setupEmbeddedPage;
|
package/dist/embedded-ecard.js
CHANGED
|
@@ -12,6 +12,8 @@ export class EmbeddedEcard {
|
|
|
12
12
|
this.options = EmbeddedEcardOptionsDefaults;
|
|
13
13
|
this._form = EnForm.getInstance();
|
|
14
14
|
this.isSubmitting = false;
|
|
15
|
+
this.ecardFormActive = false;
|
|
16
|
+
this.iframe = null;
|
|
15
17
|
// For the page hosting the embedded ecard
|
|
16
18
|
if (this.onHostPage()) {
|
|
17
19
|
// Clean up session variables if the page is reloaded, and it isn't a submission failure
|
|
@@ -73,7 +75,8 @@ export class EmbeddedEcard {
|
|
|
73
75
|
</div>
|
|
74
76
|
</div>`;
|
|
75
77
|
container.appendChild(checkbox);
|
|
76
|
-
|
|
78
|
+
this.iframe = this.createIframe(this.options.pageUrl);
|
|
79
|
+
container.appendChild(this.iframe);
|
|
77
80
|
(_a = document
|
|
78
81
|
.querySelector(this.options.anchor)) === null || _a === void 0 ? void 0 : _a.insertAdjacentElement(this.options.placement, container);
|
|
79
82
|
}
|
|
@@ -89,28 +92,64 @@ export class EmbeddedEcard {
|
|
|
89
92
|
return iframe;
|
|
90
93
|
}
|
|
91
94
|
addEventListeners() {
|
|
92
|
-
const iframe = document.querySelector(".engrid-iframe--embedded-ecard");
|
|
93
95
|
const sendEcardCheckbox = document.getElementById("en__field_embedded-ecard");
|
|
94
|
-
|
|
95
|
-
|
|
96
|
+
this.toggleEcardForm(sendEcardCheckbox.checked);
|
|
97
|
+
sendEcardCheckbox === null || sendEcardCheckbox === void 0 ? void 0 : sendEcardCheckbox.addEventListener("change", (e) => {
|
|
98
|
+
const checkbox = e.target;
|
|
99
|
+
this.toggleEcardForm(checkbox.checked);
|
|
100
|
+
});
|
|
101
|
+
this._form.onValidate.subscribe(this.validateRecipients.bind(this));
|
|
102
|
+
}
|
|
103
|
+
validateRecipients() {
|
|
104
|
+
var _a, _b, _c, _d;
|
|
105
|
+
if (!this.ecardFormActive || !this._form.validate)
|
|
106
|
+
return;
|
|
107
|
+
this.logger.log("Validating ecard");
|
|
108
|
+
let embeddedEcardData = JSON.parse(sessionStorage.getItem("engrid-embedded-ecard") || "{}");
|
|
109
|
+
// Testing if the ecard recipient data is set and valid
|
|
110
|
+
if (!embeddedEcardData.formData ||
|
|
111
|
+
!embeddedEcardData.formData.recipients ||
|
|
112
|
+
embeddedEcardData.formData.recipients.length == 0 ||
|
|
113
|
+
embeddedEcardData.formData.recipients.some((recipient) => {
|
|
114
|
+
const recipientName = recipient.name;
|
|
115
|
+
const recipientEmail = recipient.email;
|
|
116
|
+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
117
|
+
return (recipientName === "" ||
|
|
118
|
+
recipientEmail === "" ||
|
|
119
|
+
!emailRegex.test(recipientEmail));
|
|
120
|
+
})) {
|
|
121
|
+
this.logger.log("Ecard recipients validation failed");
|
|
122
|
+
this._form.validate = false;
|
|
123
|
+
this.sendPostMessage(this.iframe, "recipient_error");
|
|
124
|
+
const iframeDoc = ((_a = this.iframe) === null || _a === void 0 ? void 0 : _a.contentDocument) || ((_c = (_b = this.iframe) === null || _b === void 0 ? void 0 : _b.contentWindow) === null || _c === void 0 ? void 0 : _c.document);
|
|
125
|
+
if (!iframeDoc)
|
|
126
|
+
return;
|
|
127
|
+
const scrollTarget = iframeDoc.querySelector(".en__ecardrecipients");
|
|
128
|
+
if (!scrollTarget)
|
|
129
|
+
return;
|
|
130
|
+
const iframeRect = (_d = this.iframe) === null || _d === void 0 ? void 0 : _d.getBoundingClientRect();
|
|
131
|
+
if (!iframeRect)
|
|
132
|
+
return;
|
|
133
|
+
const elementRect = scrollTarget.getBoundingClientRect();
|
|
134
|
+
window.scrollTo({
|
|
135
|
+
top: iframeRect.top + elementRect.top + window.scrollY - 10,
|
|
136
|
+
behavior: "smooth",
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
toggleEcardForm(visible) {
|
|
141
|
+
const iframe = document.querySelector(".engrid-iframe--embedded-ecard");
|
|
142
|
+
this.ecardFormActive = visible;
|
|
143
|
+
if (visible) {
|
|
96
144
|
iframe === null || iframe === void 0 ? void 0 : iframe.setAttribute("style", "display: block");
|
|
97
145
|
sessionStorage.setItem("engrid-send-embedded-ecard", "true");
|
|
146
|
+
this.logger.log("Ecard form is visible");
|
|
98
147
|
}
|
|
99
148
|
else {
|
|
100
149
|
iframe === null || iframe === void 0 ? void 0 : iframe.setAttribute("style", "display: none");
|
|
101
150
|
sessionStorage.removeItem("engrid-send-embedded-ecard");
|
|
151
|
+
this.logger.log("Ecard form is hidden");
|
|
102
152
|
}
|
|
103
|
-
sendEcardCheckbox === null || sendEcardCheckbox === void 0 ? void 0 : sendEcardCheckbox.addEventListener("change", (e) => {
|
|
104
|
-
const checkbox = e.target;
|
|
105
|
-
if (checkbox === null || checkbox === void 0 ? void 0 : checkbox.checked) {
|
|
106
|
-
iframe === null || iframe === void 0 ? void 0 : iframe.setAttribute("style", "display: block");
|
|
107
|
-
sessionStorage.setItem("engrid-send-embedded-ecard", "true");
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
iframe === null || iframe === void 0 ? void 0 : iframe.setAttribute("style", "display: none");
|
|
111
|
-
sessionStorage.removeItem("engrid-send-embedded-ecard");
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
153
|
}
|
|
115
154
|
setEmbeddedEcardSessionData() {
|
|
116
155
|
let ecardVariant = document.querySelector("[name='friend.ecard']");
|
|
@@ -202,6 +241,15 @@ export class EmbeddedEcard {
|
|
|
202
241
|
ecardVariant.dispatchEvent(new Event("input"));
|
|
203
242
|
});
|
|
204
243
|
});
|
|
244
|
+
// Remove the recipient error message when the user starts typing in the recipient fields
|
|
245
|
+
[recipientName, recipientEmail].forEach((el) => {
|
|
246
|
+
el.addEventListener("input", () => {
|
|
247
|
+
const recipientDetails = document.querySelector(".en__ecardrecipients__detail");
|
|
248
|
+
const error = document.querySelector(".engrid__recipient__error");
|
|
249
|
+
recipientDetails === null || recipientDetails === void 0 ? void 0 : recipientDetails.classList.remove("validationFail");
|
|
250
|
+
error === null || error === void 0 ? void 0 : error.classList.add("hide");
|
|
251
|
+
});
|
|
252
|
+
});
|
|
205
253
|
window.addEventListener("message", (e) => {
|
|
206
254
|
if (e.origin !== location.origin || !e.data.action)
|
|
207
255
|
return;
|
|
@@ -236,6 +284,18 @@ export class EmbeddedEcard {
|
|
|
236
284
|
recipientName.dispatchEvent(new Event("input"));
|
|
237
285
|
recipientEmail.dispatchEvent(new Event("input"));
|
|
238
286
|
break;
|
|
287
|
+
case "recipient_error":
|
|
288
|
+
const recipientDetails = document.querySelector(".en__ecardrecipients__detail");
|
|
289
|
+
const error = document.querySelector(".engrid__recipient__error");
|
|
290
|
+
if (error) {
|
|
291
|
+
error.classList.remove("hide");
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
recipientDetails === null || recipientDetails === void 0 ? void 0 : recipientDetails.insertAdjacentHTML("afterend", "<div class='en__field__error engrid__recipient__error'>Please provide the details for your eCard recipient</div>");
|
|
295
|
+
}
|
|
296
|
+
recipientDetails === null || recipientDetails === void 0 ? void 0 : recipientDetails.classList.add("validationFail");
|
|
297
|
+
window.dispatchEvent(new Event("resize"));
|
|
298
|
+
break;
|
|
239
299
|
}
|
|
240
300
|
});
|
|
241
301
|
this.sendPostMessage("parent", "ecard_form_ready");
|
|
@@ -256,6 +316,8 @@ export class EmbeddedEcard {
|
|
|
256
316
|
}
|
|
257
317
|
sendPostMessage(target, action, data = {}) {
|
|
258
318
|
var _a;
|
|
319
|
+
if (!target)
|
|
320
|
+
return;
|
|
259
321
|
const message = Object.assign({ action }, data);
|
|
260
322
|
if (target === "parent") {
|
|
261
323
|
window.parent.postMessage(message, location.origin);
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const AppVersion = "0.20.
|
|
1
|
+
export declare const AppVersion = "0.20.10";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const AppVersion = "0.20.
|
|
1
|
+
export const AppVersion = "0.20.10";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@4site/engrid-scripts",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.10",
|
|
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": "ddcbbb035da4040cd61a745aefc4b4c686fe249a",
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"nodemon": "^2.0.20"
|
|
31
31
|
}
|