You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by jo...@apache.org on 2009/08/18 07:14:48 UTC
svn commit: r805280 -
/incubator/shindig/trunk/features/src/main/javascript/features/dynamic-height/dynamic-height.js
Author: johnh
Date: Tue Aug 18 05:14:48 2009
New Revision: 805280
URL: http://svn.apache.org/viewvc?rev=805280&view=rev
Log:
Account for all children when deducing dynamic-height for Webkit-based browsers rather than only first order document.body children, to account for "float"-positioned elements.
Patch provided by Michael Hermanto, closing issue SHINDIG-1155.
Modified:
incubator/shindig/trunk/features/src/main/javascript/features/dynamic-height/dynamic-height.js
Modified: incubator/shindig/trunk/features/src/main/javascript/features/dynamic-height/dynamic-height.js
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/features/src/main/javascript/features/dynamic-height/dynamic-height.js?rev=805280&r1=805279&r2=805280&view=diff
==============================================================================
--- incubator/shindig/trunk/features/src/main/javascript/features/dynamic-height/dynamic-height.js (original)
+++ incubator/shindig/trunk/features/src/main/javascript/features/dynamic-height/dynamic-height.js Tue Aug 18 05:14:48 2009
@@ -39,6 +39,7 @@
/**
* Parse out the value (specified in px) for a CSS attribute of an element.
+ *
* @param {Object} elem the element with the attribute to look for.
* @param {String} attr the CSS attribute name of interest.
* @returns {int} the value of the px attr of the elem.
@@ -51,22 +52,36 @@
}
/**
- * Calculate the height of the gadget iframe by iterating through the
- * elements in the gadget body for Webkit.
+ * For Webkit-based browsers, calculate the height of the gadget iframe by
+ * iterating through all elements in the gadget, starting with the body tag.
+ * It is not sufficient to only account body children elements, because
+ * CSS style position "float" may place a child element outside of the
+ * containing parent element. Not counting "float" elements may lead to
+ * undercounting.
+ *
* @returns {int} the height of the gadget.
*/
function getHeightForWebkit() {
var result = 0;
- var children = document.body.childNodes;
- for (var i = 0; i < children.length; i++) {
- if (typeof children[i].offsetTop !== 'undefined' &&
- typeof children[i].scrollHeight !== 'undefined') {
- // scrollHeight already accounts for border-bottom and padding-bottom.
- var bottom = children[i].offsetTop + children[i].scrollHeight
- + parseIntFromElemPxAttribute(children[i], "margin-bottom");
- result = Math.max(result, bottom);
+ var queue = [ document.body ];
+
+ while (queue.length > 0) {
+ var elem = queue.shift();
+ var children = elem.childNodes;
+
+ for (var i = 0; i < children.length; i++) {
+ var child = children[i];
+ if (typeof child.offsetTop !== 'undefined' &&
+ typeof child.scrollHeight !== 'undefined') {
+ // scrollHeight already accounts for border-bottom, padding-bottom.
+ var bottom = child.offsetTop + child.scrollHeight +
+ parseIntFromElemPxAttribute(child, "margin-bottom");
+ result = Math.max(result, bottom);
+ }
+ queue.push(child);
}
- }
+ }
+
// Add border, padding and margin of the containing body.
return result
+ parseIntFromElemPxAttribute(document.body, "border-bottom")