diff options
| author | Fuwn <[email protected]> | 2024-01-04 19:43:46 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-01-04 19:43:46 -0800 |
| commit | 21ad710dd2a130d8c48bba828e237aa612590b56 (patch) | |
| tree | b47a13efdcf6c8edeb0d6ec1d093e5b03ea82c8d /src/lib/Utility/html.ts | |
| parent | feat: loading and error cards (diff) | |
| download | due.moe-21ad710dd2a130d8c48bba828e237aa612590b56.tar.xz due.moe-21ad710dd2a130d8c48bba828e237aa612590b56.zip | |
feat: site-wide limit height
Diffstat (limited to 'src/lib/Utility/html.ts')
| -rw-r--r-- | src/lib/Utility/html.ts | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/src/lib/Utility/html.ts b/src/lib/Utility/html.ts index 46c7101e..3be8e1f5 100644 --- a/src/lib/Utility/html.ts +++ b/src/lib/Utility/html.ts @@ -5,20 +5,28 @@ export const nbsp = (str: string) => str.replace(/ /g, ' '); export const limitListHeight = () => { if (get(settings).displayLimitListHeight) { + let tallestList: HTMLElement | undefined; + document.querySelectorAll('.list').forEach((list) => { - const listContainerBottom = - document.querySelector('#list-container')?.getBoundingClientRect().bottom || 0; - const headerBottom = - (document.querySelector('#header')?.getBoundingClientRect().bottom || 0) * 1.5; - const offset = 1.25 + 0.275; - const offsetInPixels = - offset * parseFloat(getComputedStyle(document.documentElement).fontSize); - - ( - list as HTMLElement - ).style.maxHeight = `calc(100vh - ${listContainerBottom}px + ${headerBottom}px - ${ - offsetInPixels * 2 - }px)`; + const element = list as HTMLElement; + + element.style.height = 'auto'; + + if (element.offsetHeight > (tallestList ? tallestList.offsetHeight : 0)) + tallestList = element; }); + + if (tallestList) + tallestList.style.maxHeight = `calc(${window.innerHeight}px - ${ + document.querySelector('#header')?.getBoundingClientRect().bottom || 0 + }px - 2rem)`; } }; + +export const createHeightObserver = () => { + const observer = new ResizeObserver(() => limitListHeight()); + + document.querySelectorAll('#list-container').forEach((element) => { + observer.observe(element); + }); +}; |