@4site/engrid-scripts 0.28.5 → 0.28.6
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 +12 -0
- package/dist/iframe.js +37 -9
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
package/dist/iframe.d.ts
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
import { EnForm } from "./events";
|
|
2
2
|
export declare class iFrame {
|
|
3
3
|
_form: EnForm;
|
|
4
|
+
private resizeObserver;
|
|
4
5
|
private logger;
|
|
5
6
|
constructor();
|
|
6
7
|
private onLoaded;
|
|
8
|
+
/**
|
|
9
|
+
* Observes document.body for size changes (DOM mutations, font/image
|
|
10
|
+
* loads, CSS transitions) and re-sends the iframe height to the parent.
|
|
11
|
+
*
|
|
12
|
+
* Uses a leading + trailing throttle via debounceWithImmediate: the
|
|
13
|
+
* first change is sent immediately, and the settled height is always
|
|
14
|
+
* re-sent once changes stop for 120ms. Animated transitions therefore
|
|
15
|
+
* don't flood the parent page with one message per frame, but the
|
|
16
|
+
* parent always ends up matching the final resolved height.
|
|
17
|
+
*/
|
|
18
|
+
private observeHeightChanges;
|
|
7
19
|
/**
|
|
8
20
|
* Posts a `engrid-iframe-queue:thank-you` message to the parent window
|
|
9
21
|
* when the embedded EN page reaches its Thank You page (the last page
|
package/dist/iframe.js
CHANGED
|
@@ -3,6 +3,7 @@ import { EnForm } from "./events";
|
|
|
3
3
|
export class iFrame {
|
|
4
4
|
constructor() {
|
|
5
5
|
this._form = EnForm.getInstance();
|
|
6
|
+
this.resizeObserver = null;
|
|
6
7
|
this.logger = new EngridLogger("iFrame", "brown", "gray", "📡");
|
|
7
8
|
if (this.inIframe()) {
|
|
8
9
|
// Add the data-engrid-embedded attribute when inside an iFrame if it wasn't already added by a script in the Page Template
|
|
@@ -95,6 +96,7 @@ export class iFrame {
|
|
|
95
96
|
if (iframe) {
|
|
96
97
|
if (event.data.hasOwnProperty("frameHeight")) {
|
|
97
98
|
iframe.style.height = event.data.frameHeight + "px";
|
|
99
|
+
this.logger.log(`iFrame Event - Resized iframe element to ${event.data.frameHeight}px`);
|
|
98
100
|
if (event.data.frameHeight > 0) {
|
|
99
101
|
iframe.classList.add("loaded");
|
|
100
102
|
}
|
|
@@ -134,6 +136,8 @@ export class iFrame {
|
|
|
134
136
|
// Scroll to top of iFrame
|
|
135
137
|
this.logger.log("iFrame Event - window.onload");
|
|
136
138
|
this.sendIframeHeight();
|
|
139
|
+
// Continuously re-send the height whenever the body size changes
|
|
140
|
+
this.observeHeightChanges();
|
|
137
141
|
window.parent.postMessage({
|
|
138
142
|
scroll: this.shouldScroll(),
|
|
139
143
|
}, "*");
|
|
@@ -142,16 +146,40 @@ export class iFrame {
|
|
|
142
146
|
// matches it by Page ID to advance to the next queued iframe. Fires
|
|
143
147
|
// exactly once per Thank-You-page load. See iframe-queue.ts.
|
|
144
148
|
this.sendIframeQueueThankYouPing();
|
|
145
|
-
// On click fire the resize event
|
|
146
|
-
document.addEventListener("click", (e) => {
|
|
147
|
-
this.logger.log("iFrame Event - click");
|
|
148
|
-
setTimeout(() => {
|
|
149
|
-
this.sendIframeHeight();
|
|
150
|
-
}, 100);
|
|
151
|
-
});
|
|
152
149
|
// Watch for errors and send the height
|
|
153
150
|
ENGrid.watchForError(this.sendIframeHeight.bind(this));
|
|
154
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* Observes document.body for size changes (DOM mutations, font/image
|
|
154
|
+
* loads, CSS transitions) and re-sends the iframe height to the parent.
|
|
155
|
+
*
|
|
156
|
+
* Uses a leading + trailing throttle via debounceWithImmediate: the
|
|
157
|
+
* first change is sent immediately, and the settled height is always
|
|
158
|
+
* re-sent once changes stop for 120ms. Animated transitions therefore
|
|
159
|
+
* don't flood the parent page with one message per frame, but the
|
|
160
|
+
* parent always ends up matching the final resolved height.
|
|
161
|
+
*/
|
|
162
|
+
observeHeightChanges() {
|
|
163
|
+
if (typeof ResizeObserver === "undefined") {
|
|
164
|
+
this.logger.log("ResizeObserver not supported in this browser");
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
let lastSent = -1;
|
|
168
|
+
const throttledSend = this.debounceWithImmediate((_entries, _observer, immediate) => {
|
|
169
|
+
const height = document.body.offsetHeight;
|
|
170
|
+
// Skip redundant sends when the settled height is unchanged
|
|
171
|
+
if (height === lastSent) {
|
|
172
|
+
this.logger.log(`iFrame Event - ResizeObserver settled at unchanged height ${height}px, skipping send`);
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
lastSent = height;
|
|
176
|
+
this.logger.log(`iFrame Event - ResizeObserver ${immediate ? "leading" : "trailing"} resize: sending height ${height}px`);
|
|
177
|
+
this.sendIframeHeight();
|
|
178
|
+
}, 120);
|
|
179
|
+
this.resizeObserver = new ResizeObserver(throttledSend);
|
|
180
|
+
this.resizeObserver.observe(document.body);
|
|
181
|
+
this.logger.log("iFrame Event - Observing body resize");
|
|
182
|
+
}
|
|
155
183
|
/**
|
|
156
184
|
* Posts a `engrid-iframe-queue:thank-you` message to the parent window
|
|
157
185
|
* when the embedded EN page reaches its Thank You page (the last page
|
|
@@ -299,11 +327,11 @@ export class iFrame {
|
|
|
299
327
|
return (...args) => {
|
|
300
328
|
clearTimeout(timer);
|
|
301
329
|
if (firstEvent) {
|
|
302
|
-
func.apply(this, args);
|
|
330
|
+
func.apply(this, [...args, true]);
|
|
303
331
|
firstEvent = false;
|
|
304
332
|
}
|
|
305
333
|
timer = setTimeout(() => {
|
|
306
|
-
func.apply(this, args);
|
|
334
|
+
func.apply(this, [...args, false]);
|
|
307
335
|
firstEvent = true;
|
|
308
336
|
}, timeout);
|
|
309
337
|
};
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const AppVersion = "0.28.
|
|
1
|
+
export declare const AppVersion = "0.28.6";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const AppVersion = "0.28.
|
|
1
|
+
export const AppVersion = "0.28.6";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@4site/engrid-scripts",
|
|
3
|
-
"version": "0.28.
|
|
3
|
+
"version": "0.28.6",
|
|
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": "812f43226c0ecca0adb6dc6a84f4e2d760ec22fd",
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"nodemon": "^2.0.20",
|
|
31
31
|
"typescript": "^4.9.5"
|