Skip to content

Commit

Permalink
fix: address iframe resizing issue in jupyter notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
dakshpokar committed Oct 17, 2024
1 parent a437856 commit b1dd809
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions maidr/core/maidr.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,24 +193,36 @@ def generate_iframe_script(unique_id: str) -> str:
resizing_script = f"""
function resizeIframe() {{
let iframe = document.getElementById('{unique_id}');
if (iframe && iframe.contentWindow && iframe.contentWindow.document) {{
let iframeDocument = iframe.contentWindow.document;
let brailleContainer = iframeDocument.getElementById('braille-div');
let brailleContainer = iframeDocument.getElementById('braille-input');
iframe.style.height = 'auto';
let height = iframeDocument.body.scrollHeight;
if (brailleContainer && brailleContainer === iframeDocument.activeElement) {{
height *= 1.35; # Increase height by 35% if braille-container is in focus
height += 100;
}}else{{
height += 50
}}
iframe.style.height = (height + 150) + 'px';
iframe.style.height = (height) + 'px';
iframe.style.width = iframeDocument.body.scrollWidth + 'px';
}}
}}
let iframe = document.getElementById('{unique_id}');
resizeIframe();
iframe.onload = function() {{
resizeIframe();
iframe.contentWindow.addEventListener('resize', resizeIframe);
iframe.contentWindow.document.addEventListener('focusin', resizeIframe);
iframe.contentWindow.document.addEventListener('focusout', resizeIframe);
}};
iframe.contentWindow.document.addEventListener('focusin', () => {{
resizeIframe();
}});
iframe.contentWindow.document.addEventListener('focusout', () => {{
resizeIframe();
}});
"""
return resizing_script

Expand Down

0 comments on commit b1dd809

Please sign in to comment.