-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Settings panel overflows screen on certain sizes #90
- Loading branch information
SethBurkart123
authored and
SethBurkart123
committed
Feb 12, 2024
1 parent
5cf84bf
commit bd63261
Showing
4 changed files
with
56 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { debounce } from "../utils/debounce"; | ||
|
||
/** | ||
* Automatically resizes the popup to fit the screen, checks on resize but is debounced to prevent intense utilisation. | ||
*/ | ||
export class SettingsResizer { | ||
constructor() { | ||
this.adjustPopupHeight(); | ||
window.addEventListener('resize', debounce(this.adjustPopupHeight, 250) as EventListener); | ||
document.addEventListener('DOMContentLoaded', this.adjustPopupHeight); | ||
} | ||
|
||
private adjustPopupHeight() { | ||
const iframePopup = document.getElementById('ExtensionPopup'); | ||
if (!iframePopup) return; | ||
|
||
const viewportHeight = window.innerHeight; | ||
const idealHeight = viewportHeight - 80 - 15; // -80px for the top of the popup | ||
|
||
if (idealHeight > 600) { | ||
iframePopup.style.height = '600px'; | ||
} else { | ||
iframePopup.style.height = `${idealHeight}px`; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Creates a debounced function that delays invoking the provided function until after `wait` milliseconds have elapsed | ||
* since the last time it was invoked. The debounced function will only be invoked once during the `wait` period. | ||
* | ||
* @param func - The function to debounce. | ||
* @param wait - The number of milliseconds to delay. | ||
* @param immediate - If `true`, the function will be invoked immediately on the leading edge instead of the trailing edge. | ||
* If not provided, it is disabled by default. | ||
* @returns A debounced function. | ||
*/ | ||
export function debounce(func: Function, wait: number, immediate?: boolean): Function { | ||
let timeout: number | undefined; | ||
return function(this: any) { | ||
const context = this; | ||
const args = arguments; | ||
const later = function() { | ||
timeout = undefined; | ||
if (!immediate) func.apply(context, args); | ||
}; | ||
const callNow = immediate && !timeout; | ||
clearTimeout(timeout); | ||
timeout = setTimeout(later, wait); | ||
if (callNow) func.apply(context, args); | ||
}; | ||
} |