From bed7f208abb74d7a93389682b261aaee9e5e941d Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sat, 7 Jun 2008 15:17:10 +0000 Subject: [PATCH] Fixing Util.getRenderedDimensions so it assigns units to positional values. Thanks Wally for the report. r=euzuro (closes #1570) git-svn-id: http://svn.openlayers.org/trunk/openlayers@7329 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Util.js | 8 +++++--- tests/Util.html | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/OpenLayers/Util.js b/lib/OpenLayers/Util.js index e70254357b..39983802f9 100644 --- a/lib/OpenLayers/Util.js +++ b/lib/OpenLayers/Util.js @@ -1365,7 +1365,7 @@ OpenLayers.Util.getBrowserName = function() { */ OpenLayers.Util.getRenderedDimensions = function(contentHTML, size) { - var w = h = null; + var w, h; // create temp container div with restricted size var container = document.createElement("div"); @@ -1376,9 +1376,11 @@ OpenLayers.Util.getRenderedDimensions = function(contentHTML, size) { //fix a dimension, if specified. if (size) { if (size.w) { - w = container.style.width = size.w; + w = size.w; + container.style.width = w + "px"; } else if (size.h) { - h = container.style.height = size.h; + h = size.h + container.style.height = h + "px"; } } diff --git a/tests/Util.html b/tests/Util.html index 1f943369e4..aefd31089a 100644 --- a/tests/Util.html +++ b/tests/Util.html @@ -782,6 +782,20 @@ t.ok(ret == g_TestVal3, "try returns first sucessfully executed function's return"); } + + function test_getRenderedDimensions(t) { + t.plan(2); + var content = (new Array(100)).join("foo "); + + // test with fixed width + var fw = OpenLayers.Util.getRenderedDimensions(content, {w: 20}); + t.eq(fw.w, 20, "got the fixed width"); + + // test with fixed height + var fh = OpenLayers.Util.getRenderedDimensions(content, {h: 15}); + t.eq(fh.h, 15, "got the fixed height"); + + }