From 3d71b4ff4e09480978c5f9ac06f86d10f67721ca Mon Sep 17 00:00:00 2001 From: crschmidt Date: Wed, 3 Oct 2007 16:15:43 +0000 Subject: [PATCH] IE thinks that window and document.body are really the same thing -- even though one has a style property and the other doesn't. This means that when we pass in 'window' to pagePosition, it blows up, but it didin't before a recent reorganization. Here, we create a short term preventative measure to ensure that old apps don't break -- this should be fixed in 2.6. (See #1034, #1051) git-svn-id: http://svn.openlayers.org/trunk/openlayers@4783 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Util.js | 7 ++++++- tests/test_Util.html | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/OpenLayers/Util.js b/lib/OpenLayers/Util.js index ccbe7e2b54..b1b6ddc655 100644 --- a/lib/OpenLayers/Util.js +++ b/lib/OpenLayers/Util.js @@ -991,7 +991,12 @@ OpenLayers.Util.pagePosition = function(forElement) { while(element) { if(element == document.body) { - if(OpenLayers.Element.getStyle(child, 'position') == 'absolute') { + // FIXME: IE, when passed 'window' as the forElement, treats it as + // equal to document.body, but window.style fails, so getStyle + // fails, so we are paranoid and check this here. This check should + // probably move into element.getStyle in 2.6. + if(child && child.style && + OpenLayers.Element.getStyle(child, 'position') == 'absolute') { break; } } diff --git a/tests/test_Util.html b/tests/test_Util.html index 8a6481b1bf..48231379a2 100644 --- a/tests/test_Util.html +++ b/tests/test_Util.html @@ -19,6 +19,13 @@ OpenLayers.Util.removeItem(array, 3); t.eq( array.toString(), "1,2,4,5", "Util.removeItem works"); } + + function test_03_Util_pagePosition(t) { + t.plan( 1 ); + var pp = OpenLayers.Util.pagePosition(window); + t.eq( pp.toString(), "0,0", "Page position doesn't bail if passed 'window'") + + } function test_04_Util_createDiv(t) { t.plan( 24 );