From 274afe0a5fa79ebe034ee412c44d20ccc9341bfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Junod?= Date: Thu, 27 Nov 2008 14:23:11 +0000 Subject: [PATCH] Keep the Util.alphaHack function result in a cache. r=pgiraud (closes #1825) git-svn-id: http://svn.openlayers.org/trunk/openlayers@8419 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Util.js | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/lib/OpenLayers/Util.js b/lib/OpenLayers/Util.js index db12e792a2..611ea839a8 100644 --- a/lib/OpenLayers/Util.js +++ b/lib/OpenLayers/Util.js @@ -390,6 +390,12 @@ OpenLayers.Util.onImageLoadError = function() { this.style.display = ""; }; +/** + * Property: alphaHackNeeded + * {Boolean} true if the png alpha hack is necessary and possible, false otherwise. + */ +OpenLayers.Util.alphaHackNeeded = null; + /** * Function: alphaHack * Checks whether it's necessary (and possible) to use the png alpha @@ -397,25 +403,27 @@ OpenLayers.Util.onImageLoadError = function() { * Explorer. * * Returns: - * {Boolean} true if alpha has is necessary and possible, false otherwise. + * {Boolean} true if the png alpha hack is necessary and possible, false otherwise. */ OpenLayers.Util.alphaHack = function() { - var arVersion = navigator.appVersion.split("MSIE"); - var version = parseFloat(arVersion[1]); - var filter = false; + if (OpenLayers.Util.alphaHackNeeded == null) { + var arVersion = navigator.appVersion.split("MSIE"); + var version = parseFloat(arVersion[1]); + var filter = false; - // IEs4Lin dies when trying to access document.body.filters, because - // the property is there, but requires a DLL that can't be provided. This - // means that we need to wrap this in a try/catch so that this can - // continue. + // IEs4Lin dies when trying to access document.body.filters, because + // the property is there, but requires a DLL that can't be provided. This + // means that we need to wrap this in a try/catch so that this can + // continue. - try { - filter = !!(document.body.filters); - } catch (e) { - } + try { + filter = !!(document.body.filters); + } catch (e) {} - return ( filter && - (version >= 5.5) && (version < 7) ); + OpenLayers.Util.alphaHackNeeded = (filter && + (version >= 5.5) && (version < 7)); + } + return OpenLayers.Util.alphaHackNeeded; }; /**