4988 |
kaklik |
1 |
// correctly handle PNG transparency in Win IE 5.5 or higher. |
|
|
2 |
|
|
|
3 |
function correctPNG() |
|
|
4 |
{ |
|
|
5 |
for(var i = 0; i < document.images.length; i++) |
|
|
6 |
{ |
|
|
7 |
var img = document.images[i] |
|
|
8 |
var imgName = img.src.toUpperCase() |
|
|
9 |
if (imgName.substring(imgName.length-3, imgName.length) == "PNG") |
|
|
10 |
{ |
|
|
11 |
var imgID = (img.id) ? "id='" + img.id + "' " : "" |
|
|
12 |
var imgClass = (img.className) ? "class='" + img.className + "' " : "" |
|
|
13 |
var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' " |
|
|
14 |
var imgStyle = "display:inline-block;" + img.style.cssText |
|
|
15 |
var imgAttribs = img.attributes; |
|
|
16 |
for (var j=0; j<imgAttribs.length; j++) |
|
|
17 |
{ |
|
|
18 |
var imgAttrib = imgAttribs[j]; |
|
|
19 |
if (imgAttrib.nodeName == "align") |
|
|
20 |
{ |
|
|
21 |
if (imgAttrib.nodeValue == "left") imgStyle = "float:left;" + imgStyle |
|
|
22 |
if (imgAttrib.nodeValue == "right") imgStyle = "float:right;" + imgStyle |
|
|
23 |
break |
|
|
24 |
} |
|
|
25 |
} |
|
|
26 |
var strNewHTML = "<span " + imgID + imgClass + imgTitle |
|
|
27 |
strNewHTML += " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" |
|
|
28 |
strNewHTML += "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" |
|
|
29 |
strNewHTML += "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" |
|
|
30 |
img.outerHTML = strNewHTML |
|
|
31 |
i = i-1 |
|
|
32 |
} |
|
|
33 |
} |
|
|
34 |
} |
|
|
35 |
|
|
|
36 |
var supported = /MSIE (5\.5)|[6789]/.test(navigator.userAgent) && navigator.platform == "Win32"; |
|
|
37 |
|
|
|
38 |
if (supported) |
|
|
39 |
window.attachEvent("onload", correctPNG); |