diff --git a/lib/OpenLayers/Events.js b/lib/OpenLayers/Events.js index 4a9f703038..18d1983b4f 100644 --- a/lib/OpenLayers/Events.js +++ b/lib/OpenLayers/Events.js @@ -860,10 +860,9 @@ OpenLayers.Events = OpenLayers.Class({ // returns incorrect offsets. So our best bet is to not invalidate the // offsets once we have them, and hope that the page was not scrolled // when we did the initial calculation. - if (!((document.body.scrollTop != 0 || - document.body.scrollLeft != 0) && - navigator.userAgent.match(/iPhone/i))) { - OpenLayers.Console.log("clear"); + var body = document.body; + if (body && !((body.scrollTop != 0 || body.scrollLeft != 0) && + navigator.userAgent.match(/iPhone/i))) { this.element.offsets = null; } }, diff --git a/tests/Map.html b/tests/Map.html index d4a8d12b6d..5f89d1a2d9 100644 --- a/tests/Map.html +++ b/tests/Map.html @@ -1593,8 +1593,20 @@ } + // test if we can call updateSize before document.body is ready. updateOk + // is tested in the test_updateSize function below + var earlyMap = new OpenLayers.Map(); + var updateOk; + try { + earlyMap.updateSize(); + updateOk = true; + } catch(e) {} + earlyMap.destroy(); function test_updateSize(t) { - t.plan(2); + t.plan(3); + + // checking updateSize from outside this test function (see above) + t.ok(updateOk, "updateSize works before document.body is ready"); var map, moveToCnt, size; @@ -1625,7 +1637,7 @@ map.updateSize(); t.eq(moveToCnt, 1, "updateSize move the map if it has a center"); - map.destroy(); + map.destroy(); } function test_invisible_map(t) {