Skip to content

Commit 2931a8e

Browse files
committed
Ensure that a knowl dialog is at least 600 pixels tall if its content is.
Also, just append the knowl dialog to the document body. There is know reason to look for an ancestral div for this.
1 parent f11bb7d commit 2931a8e

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

htdocs/js/Knowls/knowl.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@
2525
knowl.knowlModal.setAttribute('aria-hidden', 'true');
2626

2727
const knowlDialog = document.createElement('div');
28-
knowlDialog.classList.add('modal-dialog', 'modal-dialog-centered', 'modal-dialog-scrollable');
28+
knowlDialog.classList.add(
29+
'knowl-dialog',
30+
'modal-dialog',
31+
'modal-dialog-centered',
32+
'modal-dialog-scrollable'
33+
);
34+
knowlDialog.dataset.iframeHeight = '1';
2935
knowl.knowlModal.append(knowlDialog);
3036

3137
const knowlContent = document.createElement('div');
@@ -60,11 +66,17 @@
6066
knowlContent.append(knowlFooter);
6167
}
6268

63-
// Insert the knowl modal into the end of the closest div ancestor.
64-
// If no such element is found, there is not much else that can be done, so just bail.
65-
const insertElt = knowl.closest('div');
66-
if (insertElt) insertElt.append(knowl.knowlModal);
67-
else return;
69+
knowl.knowlModal.addEventListener('shown.bs.modal', () => {
70+
const heightAdjust = Math.min(
71+
600,
72+
knowlBody.scrollHeight +
73+
knowlHeader.offsetHeight +
74+
(knowlContent.querySelector('.modal-footer')?.offsetHeight || 0)
75+
);
76+
if (knowlDialog.offsetHeight < heightAdjust) knowlDialog.style.height = `${heightAdjust}px`;
77+
});
78+
79+
document.body.append(knowl.knowlModal);
6880

6981
knowl.dataset.bsTarget = `#${knowl.knowlModal.id}`;
7082

0 commit comments

Comments
 (0)