Skip to content

Commit d09be31

Browse files
committed
Change iframe-resizing strategy again
Use documentElement.offsetHeight as height estimate. Also resize on every mouse or key press Issue marijnh#133
1 parent b74098e commit d09be31

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

html/js/sandbox.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,17 @@
4141
self.win = frame.contentWindow;
4242
self.setupEnv();
4343

44-
self.frame.addEventListener("load", function() {
44+
function resize() {
4545
if (self.frame.style.display != "none") self.resizeFrame();
46-
});
46+
}
47+
self.frame.addEventListener("load", resize);
48+
var resizeTimeout = null;
49+
function scheduleResize() {
50+
self.win.clearTimeout(resizeTimeout);
51+
self.win.__setTimeout(resize, 200);
52+
}
53+
self.win.addEventListener("keydown", scheduleResize);
54+
self.win.addEventListener("mousedown", scheduleResize);
4755

4856
if (options.loadFiles) {
4957
var i = 0;
@@ -179,7 +187,7 @@
179187
};
180188
},
181189
resizeFrame: function() {
182-
this.frame.style.height = Math.max(80, Math.min(this.win.document.body.scrollHeight + 20, 500)) + "px";
190+
this.frame.style.height = Math.max(80, Math.min(this.win.document.documentElement.offsetHeight + 10, 500)) + "px";
183191
var box = this.frame.getBoundingClientRect();
184192
if (box.bottom > box.top && box.top >= 0 && box.top < window.innerHeight && box.bottom > window.innerHeight)
185193
window.scrollBy(0, Math.min(box.top, box.bottom - window.innerHeight));

0 commit comments

Comments
 (0)