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