diff --git a/lib/OpenLayers/Popup.js b/lib/OpenLayers/Popup.js index a315adfbe1..0c5cccbaa8 100644 --- a/lib/OpenLayers/Popup.js +++ b/lib/OpenLayers/Popup.js @@ -484,8 +484,14 @@ OpenLayers.Popup = OpenLayers.Class({ var preparedHTML = "
" + this.contentDiv.innerHTML + "
"; + + var containerElement = (this.map) ? this.map.layerContainerDiv + : document.body; var realSize = OpenLayers.Util.getRenderedDimensions( - preparedHTML, null, { displayClass: this.displayClass } + preparedHTML, null, { + displayClass: this.displayClass, + containerElement: containerElement + } ); // is the "real" size of the div is safe to display in our map? @@ -514,8 +520,10 @@ OpenLayers.Popup = OpenLayers.Class({ //content is clipped in only one direction, so we need to // run getRenderedDimensions() again with a fixed dimension var clippedSize = OpenLayers.Util.getRenderedDimensions( - preparedHTML, fixedSize, - { displayClass: this.contentDisplayClass } + preparedHTML, fixedSize, { + displayClass: this.contentDisplayClass, + containerElement: containerElement + } ); //if the clipped size is still the same as the safeSize, diff --git a/lib/OpenLayers/Util.js b/lib/OpenLayers/Util.js index 18916c370e..996b357f13 100644 --- a/lib/OpenLayers/Util.js +++ b/lib/OpenLayers/Util.js @@ -1478,6 +1478,8 @@ OpenLayers.Util.getBrowserName = function() { * options - {Object} * displayClass - {String} Optional parameter. A CSS class name(s) string * to provide the CSS context of the rendered content. + * containerElement - {DOMElement} Optional parameter. Insert the HTML to + * this node instead of the body root when calculating dimensions. * * Returns: * {OpenLayers.Size} @@ -1492,6 +1494,9 @@ OpenLayers.Util.getRenderedDimensions = function(contentHTML, size, options) { container.style.position = "absolute"; container.style.left = "-9999px"; + var containerElement = (options && options.containerElement) + ? options.containerElement : document.body; + //fix a dimension, if specified. if (size) { if (size.w) { @@ -1516,7 +1521,7 @@ OpenLayers.Util.getRenderedDimensions = function(contentHTML, size, options) { container.appendChild(content); // append container to body for rendering - document.body.appendChild(container); + containerElement.appendChild(container); // calculate scroll width of content and add corners and shadow width if (!w) { @@ -1532,7 +1537,7 @@ OpenLayers.Util.getRenderedDimensions = function(contentHTML, size, options) { // remove elements container.removeChild(content); - document.body.removeChild(container); + containerElement.removeChild(container); return new OpenLayers.Size(w, h); }; diff --git a/tests/manual/renderedDimensions.html b/tests/manual/renderedDimensions.html new file mode 100644 index 0000000000..b01624b40b --- /dev/null +++ b/tests/manual/renderedDimensions.html @@ -0,0 +1,113 @@ + + + OpenLayers: Popup Mayhem + + + + + + + +

Popup Matrix

+ +
+
+
+
+
+ Click on popup, should be able to read a full sentence, not just two lines. +
+ +