2 <script type="text/javascript">
4 // IE5.5+ PNG Alpha Fix v2.0 Alpha
5 // (c) 2004-2009 Angus Turnbull http://www.twinhelix.com
7 // This is licensed under the GNU LGPL, version 2.1 or later.
8 // For details, see: http://creativecommons.org/licenses/LGPL/2.1/
10 var IEPNGFix = window.IEPNGFix || {};
11 IEPNGFix.data = IEPNGFix.data || {};
14 // CONFIG: blankImg is the path to blank.gif, *relative to the HTML document*.
16 // * An absolute path like: '/images/blank.gif'
17 // * A path relative to this HTC file like: thisFolder + 'blank.gif'
18 var thisFolder = document.URL.replace(/(\\|\/)[^\\\/]*$/, '/');
19 //IEPNGFix.blankImg = thisFolder + 'blank.gif';
20 IEPNGFix.blankImg = '/css/blank.gif';
23 IEPNGFix.fix = function(elm, src, t) {
24 // Applies an image 'src' to an element 'elm' using the DirectX filter.
25 // If 'src' is null, filter is disabled.
26 // Disables the 'hook' to prevent infinite recursion on setting BG/src.
27 // 't' = type, where background tile = 0, background = 1, IMG SRC = 2.
29 var h = this.hook.enabled;
30 this.hook.enabled = 0;
32 var f = 'DXImageTransform.Microsoft.AlphaImageLoader';
33 src = (src || '').replace(/\(/g, '%28').replace(/\)/g, '%29');
36 src && !(/IMG|INPUT/.test(elm.nodeName) && (t != 2)) &&
37 elm.currentStyle.width == 'auto' && elm.currentStyle.height == 'auto'
39 if (elm.offsetWidth) {
40 elm.style.width = elm.offsetWidth + 'px';
42 if (elm.clientHeight) {
43 elm.style.height = elm.clientHeight + 'px';
45 if (elm.currentStyle.display == 'inline') {
46 elm.style.display = 'inline-block';
51 elm.style.backgroundImage = 'url("' + this.blankImg + '")';
54 elm.src = this.blankImg;
58 elm.filters[f].enabled = src ? true : false;
60 elm.filters[f].src = src;
63 elm.style.filter = 'progid:' + f + '(src="' + src +
64 '",sizingMethod="' + (t == 2 ? 'scale' : 'crop') + '")';
67 this.hook.enabled = h;
71 IEPNGFix.process = function(elm, init) {
72 // Checks the onpropertychange event (on first 'init' run, a fake event)
73 // and calls the filter-applying-functions.
76 !/MSIE (5\.5|6)/.test(navigator.userAgent) ||
77 typeof elm.filters == 'unknown'
81 if (!this.data[elm.uniqueID]) {
82 this.data[elm.uniqueID] = {
86 var data = this.data[elm.uniqueID],
87 evt = init ? { propertyName: 'src,backgroundImage' } : event,
88 isSrc = /src/.test(evt.propertyName),
89 isBg = /backgroundImage/.test(evt.propertyName),
90 isPos = /width|height|background(Pos|Rep)/.test(evt.propertyName),
91 isClass = !init && ((elm.className != data.className) &&
92 (elm.className || data.className));
93 if (!(isSrc || isBg || isPos || isClass)) {
96 data.className = elm.className;
97 var blank = this.blankImg.match(/([^\/]+)$/)[1],
99 eCS = elm.currentStyle;
101 // Required for Whatever:hover - erase set BG if className changes.
103 isClass && (eS.backgroundImage.indexOf('url(') == -1 ||
104 eS.backgroundImage.indexOf(blank) > -1)
106 return setTimeout(function() {
107 eS.backgroundImage = '';
112 if (isSrc && elm.src && { IMG: 1, INPUT: 1 }[elm.nodeName]) {
113 if ((/\.png/i).test(elm.src)) {
115 // MM rollover compat
118 this.fix(elm, elm.src, 2);
119 } else if (elm.src.indexOf(blank) == -1) {
125 var bgSrc = eCS.backgroundImage || eS.backgroundImage;
126 if ((bgSrc + elm.src).indexOf(blank) == -1) {
127 var bgPNG = bgSrc.match(/url[("']+(.*\.png[^\)"']*)[\)"']/i);
129 if (this.tileBG && !{ IMG: 1, INPUT: 1 }[elm.nodeName]) {
130 this.tileBG(elm, bgPNG[1]);
131 this.fix(elm, '', 1);
133 if (data.tiles && data.tiles.src) {
134 this.tileBG(elm, '');
136 this.fix(elm, bgPNG[1], 1);
140 if (data.tiles && data.tiles.src) {
141 this.tileBG(elm, '');
145 } else if ((isPos || isClass) && data.tiles && data.tiles.src) {
146 this.tileBG(elm, data.tiles.src);
150 this.hook.enabled = 1;
151 elm.attachEvent('onpropertychange', this.hook);
156 IEPNGFix.childFix = function(elm) {
157 // "hasLayout" fix for unclickable children inside PNG backgrounds.
170 var pFix = elm.all.tags(tags[t]),
177 if (t && (/relative|absolute/i).test(elm.currentStyle.position)) {
178 alert('IEPNGFix: Unclickable children of element:' +
179 '\n\n<' + elm.nodeName + (elm.id && ' id=' + elm.id) + '>');
182 if (!(/relative|absolute/i).test(tFix[t].currentStyle.position)) {
183 tFix[t].style.position = 'relative';
189 IEPNGFix.hook = function() {
190 if (IEPNGFix.hook.enabled) {
191 IEPNGFix.process(element, 0);
196 IEPNGFix.process(element, 1);