Skip to content
Snippets Groups Projects
Commit f1585cd4 authored by Midhun Suresh's avatar Midhun Suresh
Browse files

Resize iframe using postmessage

parent 3353a204
No related branches found
No related tags found
No related merge requests found
...@@ -55,9 +55,8 @@ function allowsChild(parent, child) { ...@@ -55,9 +55,8 @@ function allowsChild(parent, child) {
} }
} }
function sendFrameResizeEventToParent(height?: number, width?: number) { function sendFrameResizeEventToParent(view: string) {
const message = { action: "resize-iframe", params: { height, width } }; window.parent?.postMessage(view);
window.parent?.postMessage(message);
} }
(window as any).sendFrameResizeEventToParent = sendFrameResizeEventToParent; (window as any).sendFrameResizeEventToParent = sendFrameResizeEventToParent;
......
...@@ -3,11 +3,18 @@ This script will resize the iframe based on messages ...@@ -3,11 +3,18 @@ This script will resize the iframe based on messages
*/ */
const iframeElement = document.querySelector(".chatterbox-iframe") as HTMLIFrameElement; const iframeElement = document.querySelector(".chatterbox-iframe") as HTMLIFrameElement;
window.addEventListener("message", event => { const sizeCollection = {
const { action, params } = event.data; "desktop": {
if (action === "resize-iframe") { "start": { height: "50px", width: "50px" },
const { height, width } = params; "account-setup": { height: "115px", width: "360px" },
if (height) { iframeElement.style.height = height; } "timeline": {height: "600px", width: "400px"}
if (width) { iframeElement.style.width = width; }
} }
}
window.addEventListener("message", event => {
const view = event.data;
const size = sizeCollection.desktop[view];
const { height, width } = size;
if (height) { iframeElement.style.height = height; }
if (width) { iframeElement.style.width = width; }
}); });
...@@ -12,13 +12,13 @@ export class RootView extends TemplateView<RootViewModel> { ...@@ -12,13 +12,13 @@ export class RootView extends TemplateView<RootViewModel> {
return t.mapView(vm => vm.activeSection, section => { return t.mapView(vm => vm.activeSection, section => {
switch(section) { switch(section) {
case "start": case "start":
window.sendFrameResizeEventToParent("50px", "50px"); window.sendFrameResizeEventToParent("start");
return new StartView(vm); return new StartView(vm);
case "account-setup": case "account-setup":
window.sendFrameResizeEventToParent("115px", "360px"); window.sendFrameResizeEventToParent("account-setup");
return new AccountSetupView(vm.accountSetupViewModel); return new AccountSetupView(vm.accountSetupViewModel);
case "timeline": case "timeline":
window.sendFrameResizeEventToParent("600px", "400px"); window.sendFrameResizeEventToParent("timeline");
return new ChatterboxView(vm.chatterboxViewModel); return new ChatterboxView(vm.chatterboxViewModel);
} }
return null; return null;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment