2 <script type="text/javascript">
\r
4 // IE5.5+ PNG Alpha Fix v2.0 Alpha
\r
5 // (c) 2004-2009 Angus Turnbull http://www.twinhelix.com
\r
7 // This is licensed under the GNU LGPL, version 2.1 or later.
\r
8 // For details, see: http://creativecommons.org/licenses/LGPL/2.1/
\r
10 var IEPNGFix = window.IEPNGFix || {};
\r
11 IEPNGFix.data = IEPNGFix.data || {};
\r
14 // CONFIG: blankImg is the path to blank.gif, *relative to the HTML document*.
\r
16 // * An absolute path like: '/images/blank.gif'
\r
17 // * A path relative to this HTC file like: thisFolder + 'blank.gif'
\r
18 var thisFolder = document.URL.replace(/(\\|\/)[^\\\/]*$/, '/');
\r
19 IEPNGFix.blankImg = thisFolder + 'blank.gif';
\r
22 IEPNGFix.fix = function(elm, src, t) {
\r
23 // Applies an image 'src' to an element 'elm' using the DirectX filter.
\r
24 // If 'src' is null, filter is disabled.
\r
25 // Disables the 'hook' to prevent infinite recursion on setting BG/src.
\r
26 // 't' = type, where background tile = 0, background = 1, IMG SRC = 2.
\r
28 var h = this.hook.enabled;
\r
29 this.hook.enabled = 0;
\r
31 var f = 'DXImageTransform.Microsoft.AlphaImageLoader';
\r
32 src = (src || '').replace(/\(/g, '%28').replace(/\)/g, '%29');
\r
35 src && !(/IMG|INPUT/.test(elm.nodeName) && (t != 2)) &&
\r
36 elm.currentStyle.width == 'auto' && elm.currentStyle.height == 'auto'
\r
38 if (elm.offsetWidth) {
\r
39 elm.style.width = elm.offsetWidth + 'px';
\r
41 if (elm.clientHeight) {
\r
42 elm.style.height = elm.clientHeight + 'px';
\r
44 if (elm.currentStyle.display == 'inline') {
\r
45 elm.style.display = 'inline-block';
\r
50 elm.style.backgroundImage = 'url("' + this.blankImg + '")';
\r
53 elm.src = this.blankImg;
\r
56 if (elm.filters[f]) {
\r
57 elm.filters[f].enabled = src ? true : false;
\r
59 elm.filters[f].src = src;
\r
62 elm.style.filter = 'progid:' + f + '(src="' + src +
\r
63 '",sizingMethod="' + (t == 2 ? 'scale' : 'crop') + '")';
\r
66 this.hook.enabled = h;
\r
70 IEPNGFix.process = function(elm, init) {
\r
71 // Checks the onpropertychange event (on first 'init' run, a fake event)
\r
72 // and calls the filter-applying-functions.
\r
75 !/MSIE (5\.5|6)/.test(navigator.userAgent) ||
\r
76 typeof elm.filters == 'unknown'
\r
80 if (!this.data[elm.uniqueID]) {
\r
81 this.data[elm.uniqueID] = {
\r
85 var data = this.data[elm.uniqueID],
\r
86 evt = init ? { propertyName: 'src,backgroundImage' } : event,
\r
87 isSrc = /src/.test(evt.propertyName),
\r
88 isBg = /backgroundImage/.test(evt.propertyName),
\r
89 isPos = /width|height|background(Pos|Rep)/.test(evt.propertyName),
\r
90 isClass = !init && ((elm.className != data.className) &&
\r
91 (elm.className || data.className));
\r
92 if (!(isSrc || isBg || isPos || isClass)) {
\r
95 data.className = elm.className;
\r
96 var blank = this.blankImg.match(/([^\/]+)$/)[1],
\r
98 eCS = elm.currentStyle;
\r
100 // Required for Whatever:hover - erase set BG if className changes.
\r
102 isClass && (eS.backgroundImage.indexOf('url(') == -1 ||
\r
103 eS.backgroundImage.indexOf(blank) > -1)
\r
105 return setTimeout(function() {
\r
106 eS.backgroundImage = '';
\r
111 if (isSrc && elm.src && { IMG: 1, INPUT: 1 }[elm.nodeName]) {
\r
112 if ((/\.png/i).test(elm.src)) {
\r
114 // MM rollover compat
\r
115 elm.oSrc = elm.src;
\r
117 this.fix(elm, elm.src, 2);
\r
118 } else if (elm.src.indexOf(blank) == -1) {
\r
124 var bgSrc = eCS.backgroundImage || eS.backgroundImage;
\r
125 if ((bgSrc + elm.src).indexOf(blank) == -1) {
\r
126 var bgPNG = bgSrc.match(/url[("']+(.*\.png[^\)"']*)[\)"']/i);
\r
128 if (this.tileBG && !{ IMG: 1, INPUT: 1 }[elm.nodeName]) {
\r
129 this.tileBG(elm, bgPNG[1]);
\r
130 this.fix(elm, '', 1);
\r
132 if (data.tiles && data.tiles.src) {
\r
133 this.tileBG(elm, '');
\r
135 this.fix(elm, bgPNG[1], 1);
\r
136 this.childFix(elm);
\r
139 if (data.tiles && data.tiles.src) {
\r
140 this.tileBG(elm, '');
\r
144 } else if ((isPos || isClass) && data.tiles && data.tiles.src) {
\r
145 this.tileBG(elm, data.tiles.src);
\r
149 this.hook.enabled = 1;
\r
150 elm.attachEvent('onpropertychange', this.hook);
\r
155 IEPNGFix.childFix = function(elm) {
\r
156 // "hasLayout" fix for unclickable children inside PNG backgrounds.
\r
169 var pFix = elm.all.tags(tags[t]),
\r
172 tFix.push(pFix[e]);
\r
176 if (t && (/relative|absolute/i).test(elm.currentStyle.position)) {
\r
177 alert('IEPNGFix: Unclickable children of element:' +
\r
178 '\n\n<' + elm.nodeName + (elm.id && ' id=' + elm.id) + '>');
\r
181 if (!(/relative|absolute/i).test(tFix[t].currentStyle.position)) {
\r
182 tFix[t].style.position = 'relative';
\r
188 IEPNGFix.hook = function() {
\r
189 if (IEPNGFix.hook.enabled) {
\r
190 IEPNGFix.process(element, 0);
\r
195 IEPNGFix.process(element, 1);
\r
198 </public:component>
\r