Bug #9297: Better algorithm to fix HTML IFRAME heights
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 22 Oct 2010 21:18:14 +0000 (15:18 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 26 Oct 2010 23:27:28 +0000 (17:27 -0600)
imp/js/imp.js

index d6eb6d8..5559d50 100644 (file)
@@ -90,25 +90,19 @@ document.observe('dom:loaded', function() {
 
     IMP.iframeResize = function(id)
     {
-        var val,
-            i = 0;
+        var lc, val;
 
         if (id = $(id)) {
-            val = Math.max(id.contentWindow.document.body.scrollHeight, id.contentWindow.document.lastChild.scrollHeight);
+            lc = id.contentWindow.document.lastChild;
+            val = Math.max(id.contentWindow.document.body.scrollHeight, lc.scrollHeight);
             id.setStyle({ height: val + 'px' });
 
             // For whatever reason, browsers will report different heights
-            // after the initial height setting. Try expanding IFRAME up to
-            // 5 times in 20px increments.  If still scrolling, give up to
-            // prevent infinite loops (and giant IFRAMES).
-            do {
-                if (id.contentWindow.document.body.scrollHeight == id.contentWindow.document.lastChild.scrollHeight) {
-                    break;
-                }
-
-                val += 20;
-                id.setStyle({ height: val + 'px' });
-            } while (++i <= 5);
+            // after the initial height setting.
+            // Try expanding IFRAME if we detect a scroll.
+            if (lc.clientHeight != lc.scrollHeight) {
+                id.setStyle({ height: (val + 25) + 'px' });
+            }
          }
     };