Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
38f4738eca | ||
|
|
57bd5be4ab |
@@ -37,6 +37,19 @@ function _webform_mw_staff_key(): string {
|
|||||||
return is_string($env) ? $env : '';
|
return is_string($env) ? $env : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements hook_civicrm_config().
|
||||||
|
*
|
||||||
|
* Registers this extension's `templates/` directory with Smarty so the
|
||||||
|
* Engagement Report tab page can locate `CRM/WebformMw/Page/Tab.tpl`.
|
||||||
|
* Without this hook the page callback runs but Smarty has no idea where
|
||||||
|
* the template lives.
|
||||||
|
*/
|
||||||
|
function webform_mw_civicrm_config(&$config) {
|
||||||
|
$template = CRM_Core_Smarty::singleton();
|
||||||
|
$template->prependTemplateDir(__DIR__ . '/templates');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements hook_civicrm_xmlMenu().
|
* Implements hook_civicrm_xmlMenu().
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -76,22 +76,39 @@ export function StaffReportView({
|
|||||||
// When embedded, post our content height to the parent so the Civi tab's
|
// When embedded, post our content height to the parent so the Civi tab's
|
||||||
// iframe can resize to fit (no nested scrollbars). The receiving script
|
// iframe can resize to fit (no nested scrollbars). The receiving script
|
||||||
// lives in the WebForm-mw Civi extension's tab template.
|
// lives in the WebForm-mw Civi extension's tab template.
|
||||||
|
//
|
||||||
|
// The root layout sets `html.h-full` and `body.min-h-full`, which tie
|
||||||
|
// document height to the iframe's viewport height. Combined with the
|
||||||
|
// parent setting `iframe.height = postedHeight + 24` on every message,
|
||||||
|
// that creates an unbounded feedback loop (viewport grows -> measured
|
||||||
|
// height grows -> parent grows the iframe -> repeat). Inside the iframe
|
||||||
|
// we decouple html/body from the viewport, measure `body.scrollHeight`
|
||||||
|
// (the actual content), observe the body, and skip duplicate posts.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!framed || typeof window === "undefined") return;
|
if (!framed || typeof window === "undefined") return;
|
||||||
if (window.parent === window) return;
|
if (window.parent === window) return;
|
||||||
|
const html = document.documentElement;
|
||||||
|
const body = document.body;
|
||||||
|
const prevHtmlHeight = html.style.height;
|
||||||
|
const prevBodyMinHeight = body.style.minHeight;
|
||||||
|
html.style.height = "auto";
|
||||||
|
body.style.minHeight = "0";
|
||||||
|
let lastHeight = -1;
|
||||||
const post = () => {
|
const post = () => {
|
||||||
window.parent.postMessage(
|
const h = body.scrollHeight;
|
||||||
{ type: "webform-mw-height", height: document.documentElement.scrollHeight },
|
if (h === lastHeight) return;
|
||||||
"*",
|
lastHeight = h;
|
||||||
);
|
window.parent.postMessage({ type: "webform-mw-height", height: h }, "*");
|
||||||
};
|
};
|
||||||
post();
|
post();
|
||||||
const ro = new ResizeObserver(post);
|
const ro = new ResizeObserver(post);
|
||||||
ro.observe(document.documentElement);
|
ro.observe(body);
|
||||||
window.addEventListener("load", post);
|
window.addEventListener("load", post);
|
||||||
return () => {
|
return () => {
|
||||||
ro.disconnect();
|
ro.disconnect();
|
||||||
window.removeEventListener("load", post);
|
window.removeEventListener("load", post);
|
||||||
|
html.style.height = prevHtmlHeight;
|
||||||
|
body.style.minHeight = prevBodyMinHeight;
|
||||||
};
|
};
|
||||||
}, [framed, load]);
|
}, [framed, load]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user