You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.1 KiB
48 lines
1.1 KiB
'use strict';
|
|
|
|
window.initBlock = initBlock;
|
|
|
|
// Blocks Initialization.
|
|
function initBlock(blockName = '', selector = '', cb) {
|
|
document.querySelectorAll(selector).forEach((el) => cb(el));
|
|
}
|
|
|
|
// Scrollbars / Frame resizes notifications.
|
|
(function () {
|
|
let height;
|
|
const debug = false;
|
|
|
|
handleHeightChange(); // Initial frame's height setup.
|
|
setupResizeListener(); // Listen to frame's height changes.
|
|
|
|
///
|
|
|
|
function setupResizeListener() {
|
|
const resizeObserver = new ResizeObserver(handleHeightChange);
|
|
resizeObserver.observe(document.body);
|
|
}
|
|
|
|
function handleHeightChange(entries) {
|
|
const updatedHeight = getCurrentHeight();
|
|
|
|
if (debug) {
|
|
console.log('Height Updates', 'Old vs New: ' + height, updatedHeight);
|
|
}
|
|
|
|
if (height === updatedHeight) {
|
|
return;
|
|
}
|
|
|
|
const RESIZE_CODE = 'resize:';
|
|
height = updatedHeight;
|
|
window.parent.postMessage(RESIZE_CODE + JSON.stringify({height}), '*');
|
|
|
|
if (debug) {
|
|
console.log('Resize message sent: ', height)
|
|
}
|
|
}
|
|
|
|
function getCurrentHeight() {
|
|
return document.querySelector('body > main').scrollHeight;
|
|
}
|
|
})();
|
|
|