Skip to content

Instantly share code, notes, and snippets.

@gumayunov
Created June 4, 2009 06:50
Show Gist options
  • Save gumayunov/123476 to your computer and use it in GitHub Desktop.
Save gumayunov/123476 to your computer and use it in GitHub Desktop.
Element.addMethods({
png_fix: function(el) {
var el = $(el);
var pos = navigator.userAgent.indexOf("MSIE ");
if (!(Prototype.Browser.IE && el.match('img') && el.src.include('png')) || pos == -1 )
return el;
var version = navigator.userAgent.substring(pos + 5);
if (! (((version.indexOf("5.5") == 0) || (version.indexOf("6") == 0)) && (navigator.platform == ("Win32"))) )
return el;
var src = el.src;
// if image is not visible, we should try to read demensions from attributes
var height = el.getHeight() || Element.readAttribute(el, 'height');
var width = el.getWidth() || Element.readAttribute(el, 'width');
var filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+src+'",sizingMethod="scale")';
el.setStyle({height: height, width: width});
// transparent pixel gif
el.src = '/img/pixel.gif';
// should not override all existing filters
el.style.filter += filter;
return el;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment