Created
March 15, 2010 09:32
-
-
Save joneff/332660 to your computer and use it in GitHub Desktop.
pngFix.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
// Who said browser sniffing is bad? | |
if (! /MSIE (5\.5|6\.)/.test(navigator.userAgent) ) | |
return; | |
function applyFilter(element, src) { | |
element.currentStyle.display == "block" | |
? null | |
: element.style.display = "inline-block"; | |
element.style.backgroundImage = "none"; | |
element.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\"" + src + "\", sizingMethod=\"crop\")"; | |
} | |
function doFix() { | |
var path; | |
var scripts = document.getElementsByTagName("script"); | |
for (var script in scripts) { | |
if (scripts[script].src && scripts[script].src.match(/pngFix\.js/)) { | |
path = scripts[script].src.replace(/pngFix\.js/,""); | |
} | |
} | |
for (var element in document.all) { | |
element = document.all[element]; | |
if (element.className && element.className.indexOf("fix-bg") > -1 && element.currentStyle.backgroundImage.indexOf(".png") > -1) { | |
applyFilter(element, element.currentStyle.backgroundImage.replace(/url\(\"/,"").replace(/\"\)/,"")); | |
} | |
if (element.className && element.className.indexOf("fix-src") > -1 && element.src.indexOf(".png") > -1) { | |
element.style.width = element.clientWidth + "px"; | |
element.style.height = element.clientHeight + "px"; | |
applyFilter(element, element.src); | |
element.src = path + "blank.gif"; | |
} | |
} | |
} | |
window.addEventListener = function (type, listener, useCapture) { | |
attachEvent('on' + type, function() { listener(event) }); | |
} | |
window.addEventListener("load", doFix); | |
}()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment