Use a resize observer to center the popup after an image is loaded when polyfilled

This commit is contained in:
QuantumEntangledAndy 2024-10-10 10:41:40 +07:00
parent 6cca977d07
commit b05d5e12fe
No known key found for this signature in database
GPG Key ID: 3EB4B66F30C609B6

View File

@ -182,6 +182,14 @@ export class Popup {
if (!this.dlg.showModal) {
this.dlg.classList.add('poly_dialog');
dialogPolyfill.registerDialog(this.dlg);
// Force a vertical reposition after the content
// (like crop image) has been set
const resizeObserver = new ResizeObserver((entries) => {
for (const entry of entries) {
dialogPolyfill.reposition(entry.target);
}
});
resizeObserver.observe(this.dlg);
}
this.body = this.dlg.querySelector('.popup-body');
this.content = this.dlg.querySelector('.popup-content');