mirror of
https://github.com/go-gitea/gitea.git
synced 2024-12-20 08:53:47 +08:00
Backport #32599 by william-allspice
This commit is contained in:
parent
27489f2e0b
commit
4b73e92264
|
@ -57,16 +57,12 @@ export async function renderMermaid() {
|
||||||
mermaidBlock.append(btn);
|
mermaidBlock.append(btn);
|
||||||
|
|
||||||
const updateIframeHeight = () => {
|
const updateIframeHeight = () => {
|
||||||
iframe.style.height = `${iframe.contentWindow.document.body.clientHeight}px`;
|
const body = iframe.contentWindow?.document?.body;
|
||||||
|
if (body) {
|
||||||
|
iframe.style.height = `${body.clientHeight}px`;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// update height when element's visibility state changes, for example when the diagram is inside
|
|
||||||
// a <details> + <summary> block and the <details> block becomes visible upon user interaction, it
|
|
||||||
// would initially set a incorrect height and the correct height is set during this callback.
|
|
||||||
(new IntersectionObserver(() => {
|
|
||||||
updateIframeHeight();
|
|
||||||
}, {root: document.documentElement})).observe(iframe);
|
|
||||||
|
|
||||||
iframe.addEventListener('load', () => {
|
iframe.addEventListener('load', () => {
|
||||||
pre.replaceWith(mermaidBlock);
|
pre.replaceWith(mermaidBlock);
|
||||||
mermaidBlock.classList.remove('tw-hidden');
|
mermaidBlock.classList.remove('tw-hidden');
|
||||||
|
@ -75,6 +71,13 @@ export async function renderMermaid() {
|
||||||
mermaidBlock.classList.remove('is-loading');
|
mermaidBlock.classList.remove('is-loading');
|
||||||
iframe.classList.remove('tw-invisible');
|
iframe.classList.remove('tw-invisible');
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|
||||||
|
// update height when element's visibility state changes, for example when the diagram is inside
|
||||||
|
// a <details> + <summary> block and the <details> block becomes visible upon user interaction, it
|
||||||
|
// would initially set a incorrect height and the correct height is set during this callback.
|
||||||
|
(new IntersectionObserver(() => {
|
||||||
|
updateIframeHeight();
|
||||||
|
}, {root: document.documentElement})).observe(iframe);
|
||||||
});
|
});
|
||||||
|
|
||||||
document.body.append(mermaidBlock);
|
document.body.append(mermaidBlock);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user