From f302f70299088d1af87edc98594d82062572b71a Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Wed, 8 Dec 2021 20:03:51 -0300 Subject: [PATCH] IE6 CSS: Try to perform PNG fix before the page is fully loaded --- assets/js/style-reduced.js | 40 ++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/assets/js/style-reduced.js b/assets/js/style-reduced.js index 4d992d9..63b9680 100644 --- a/assets/js/style-reduced.js +++ b/assets/js/style-reduced.js @@ -23,21 +23,27 @@ document.createElement('hero'); document.createElement('main'); document.createElement('footer'); -window.onload = function() { - /* Make the logo transparent on IE6. Doing this on more - images interferes with the auto-sizing CSS expression. */ - if (document.all && /MSIE (5\.5|6)/.test(navigator.userAgent)) { - for (var i = 0; i < Math.min(2, document.images.length); i++) { - var img = document.images[i]; - img.style.paddingRight = 0; /* padding counts as space for AlphaImageLoader so swap it for margin */ - var oldsrc = img.src; - var oldw = img.clientWidth; - var oldh = img.clientHeight; - img.src = '/assets/images/blank.gif'; - img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + oldsrc + "', sizingMethod='scale')"; - img.style.width = oldw + 'px'; - img.style.height = oldh + 'px'; - img.style.marginRight = '20pt'; - } +/* Make the logo transparent on IE6. Doing this on more + images interferes with the auto-sizing CSS expression. */ +function fixPngs() { + /* Check if the icon and logo are loaded, and try + again after a while if they're not present yet. */ + if (!document.images || (document.images.length < 2)) + setTimeout(fixPngs, 500); + + /* Fix icon and logo. */ + for (var i = 0; i < Math.min(2, document.images.length); i++) { + var img = document.images[i]; + img.style.paddingRight = 0; /* padding counts as space for AlphaImageLoader so swap it for margin */ + var oldsrc = img.src; + var oldw = img.clientWidth; + var oldh = img.clientHeight; + img.src = '/assets/images/blank.gif'; + img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + oldsrc + "', sizingMethod='scale')"; + img.style.width = oldw + 'px'; + img.style.height = oldh + 'px'; + img.style.marginRight = '20pt'; } -}; +} +if (document.all && /MSIE (5\.5|6)/.test(navigator.userAgent)) + fixPngs();