4
0
mirror of https://github.com/AzuraCast/AzuraCast.git synced 2024-06-15 05:36:37 +00:00

Add ResizeObserver to send updated messages to parent when main body size changes.

This commit is contained in:
Buster Neece 2023-12-21 17:00:47 -06:00
parent 47c061bad6
commit 8b15a55bad
No known key found for this signature in database

View File

@ -40,17 +40,25 @@ ready(() => {
// If in a frame, notify the parent frame of the frame dimensions.
if (window.self !== window.top) {
window.top.postMessage({
height: document.body.scrollHeight,
width: document.body.scrollWidth
}, "*");
let docHeight = 0;
let docWidth = 0;
document.addEventListener("vue-ready", () => {
window.top.postMessage({
height: document.body.scrollHeight,
width: document.body.scrollWidth
}, "*");
});
const postSizeToParent = () => {
if (document.body.scrollHeight !== docHeight || document.body.scrollWidth !== docWidth) {
docHeight = document.body.scrollHeight;
docWidth = document.body.scrollWidth;
const message = {height: docHeight, width: docWidth};
window.top.postMessage(message, "*");
}
}
postSizeToParent();
document.addEventListener("vue-ready", postSizeToParent);
const mainElem = document.querySelector('main');
const resizeObserver = new ResizeObserver(postSizeToParent);
resizeObserver.observe(mainElem);
}
});