Compare commits
2
Commits
1364917ada
...
38f4738eca
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
38f4738eca | ||
|
|
57bd5be4ab |
@@ -37,6 +37,19 @@ function _webform_mw_staff_key(): string {
|
||||
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().
|
||||
*
|
||||
|
||||
@@ -76,22 +76,39 @@ export function StaffReportView({
|
||||
// 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
|
||||
// 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(() => {
|
||||
if (!framed || typeof window === "undefined") 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 = () => {
|
||||
window.parent.postMessage(
|
||||
{ type: "webform-mw-height", height: document.documentElement.scrollHeight },
|
||||
"*",
|
||||
);
|
||||
const h = body.scrollHeight;
|
||||
if (h === lastHeight) return;
|
||||
lastHeight = h;
|
||||
window.parent.postMessage({ type: "webform-mw-height", height: h }, "*");
|
||||
};
|
||||
post();
|
||||
const ro = new ResizeObserver(post);
|
||||
ro.observe(document.documentElement);
|
||||
ro.observe(body);
|
||||
window.addEventListener("load", post);
|
||||
return () => {
|
||||
ro.disconnect();
|
||||
window.removeEventListener("load", post);
|
||||
html.style.height = prevHtmlHeight;
|
||||
body.style.minHeight = prevBodyMinHeight;
|
||||
};
|
||||
}, [framed, load]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user