]> git.openstreetmap.org Git - osqa.git/blob - forum/skins/default/media/iepngfix/iepngfix.htc
909f599946a91c1b202e5eff0ee2f31a2ae1c9d4
[osqa.git] / forum / skins / default / media / iepngfix / iepngfix.htc
1 <public:component>\r
2 <script type="text/javascript">\r
3 \r
4 // IE5.5+ PNG Alpha Fix v2.0 Alpha\r
5 // (c) 2004-2009 Angus Turnbull http://www.twinhelix.com\r
6 \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
9 \r
10 var IEPNGFix = window.IEPNGFix || {};\r
11 IEPNGFix.data = IEPNGFix.data || {};\r
12 \r
13 \r
14 // CONFIG: blankImg is the path to blank.gif, *relative to the HTML document*.\r
15 // Try either:\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
20 \r
21 \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
27 \r
28         var h = this.hook.enabled;\r
29         this.hook.enabled = 0;\r
30 \r
31         var f = 'DXImageTransform.Microsoft.AlphaImageLoader';\r
32                 src = (src || '').replace(/\(/g, '%28').replace(/\)/g, '%29');\r
33 \r
34         if (\r
35                 src && !(/IMG|INPUT/.test(elm.nodeName) && (t != 2)) &&\r
36                 elm.currentStyle.width == 'auto' && elm.currentStyle.height == 'auto'\r
37         ) {\r
38                 if (elm.offsetWidth) {\r
39                         elm.style.width = elm.offsetWidth + 'px';\r
40                 }\r
41                 if (elm.clientHeight) {\r
42                         elm.style.height = elm.clientHeight + 'px';\r
43                 }\r
44                 if (elm.currentStyle.display == 'inline') {\r
45                         elm.style.display = 'inline-block';\r
46                 }\r
47         }\r
48 \r
49         if (t == 1) {\r
50                 elm.style.backgroundImage = 'url("' + this.blankImg + '")';\r
51         }\r
52         if (t == 2) {\r
53                 elm.src = this.blankImg;\r
54         }\r
55 \r
56         if (elm.filters[f]) {\r
57                 elm.filters[f].enabled = src ? true : false;\r
58                 if (src) {\r
59                         elm.filters[f].src = src;\r
60                 }\r
61         } else if (src) {\r
62                 elm.style.filter = 'progid:' + f + '(src="' + src +\r
63                         '",sizingMethod="' + (t == 2 ? 'scale' : 'crop') + '")';\r
64         }\r
65 \r
66         this.hook.enabled = h;\r
67 };\r
68 \r
69 \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
73 \r
74         if (\r
75                 !/MSIE (5\.5|6)/.test(navigator.userAgent) ||\r
76                 typeof elm.filters == 'unknown'\r
77         ) {\r
78                 return;\r
79         }\r
80         if (!this.data[elm.uniqueID]) {\r
81                 this.data[elm.uniqueID] = {\r
82                         className: ''\r
83                 };\r
84         }\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
93                 return;\r
94         }\r
95         data.className = elm.className;\r
96         var blank = this.blankImg.match(/([^\/]+)$/)[1],\r
97                 eS = elm.style,\r
98                 eCS = elm.currentStyle;\r
99 \r
100         // Required for Whatever:hover - erase set BG if className changes.\r
101         if (\r
102                 isClass && (eS.backgroundImage.indexOf('url(') == -1 ||\r
103                 eS.backgroundImage.indexOf(blank) > -1)\r
104         ) {\r
105                 return setTimeout(function() {\r
106                         eS.backgroundImage = '';\r
107                 }, 0);\r
108         }\r
109 \r
110         // Foregrounds.\r
111         if (isSrc && elm.src && { IMG: 1, INPUT: 1 }[elm.nodeName]) {\r
112                 if ((/\.png/i).test(elm.src)) {\r
113                         if (!elm.oSrc) {\r
114                                 // MM rollover compat\r
115                                 elm.oSrc = elm.src;\r
116                         }\r
117                         this.fix(elm, elm.src, 2);\r
118                 } else if (elm.src.indexOf(blank) == -1) {\r
119                         this.fix(elm, '');\r
120                 }\r
121         }\r
122 \r
123         // Backgrounds.\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
127                 if (bgPNG) {\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
131                         } else {\r
132                                 if (data.tiles && data.tiles.src) {\r
133                                         this.tileBG(elm, '');\r
134                                 }\r
135                                 this.fix(elm, bgPNG[1], 1);\r
136                                 this.childFix(elm);\r
137                         }\r
138                 } else {\r
139                         if (data.tiles && data.tiles.src) {\r
140                                 this.tileBG(elm, '');\r
141                         }\r
142                         this.fix(elm, '');\r
143                 }\r
144         } else if ((isPos || isClass) && data.tiles && data.tiles.src) {\r
145                 this.tileBG(elm, data.tiles.src);\r
146         }\r
147 \r
148         if (init) {\r
149                 this.hook.enabled = 1;\r
150                 elm.attachEvent('onpropertychange', this.hook);\r
151         }\r
152 };\r
153 \r
154 \r
155 IEPNGFix.childFix = function(elm) {\r
156         // "hasLayout" fix for unclickable children inside PNG backgrounds.\r
157         var tags = [\r
158                         'a',\r
159                         'input',\r
160                         'select',\r
161                         'textarea',\r
162                         'button',\r
163                         'iframe',\r
164                         'object'\r
165                 ],\r
166                 t = tags.length,\r
167                 tFix = [];\r
168         while (t--) {\r
169                 var pFix = elm.all.tags(tags[t]),\r
170                         e = pFix.length;\r
171                 while (e--) {\r
172                         tFix.push(pFix[e]);\r
173                 }\r
174         }\r
175         t = tFix.length;\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
179         }\r
180         while (t--) {\r
181                 if (!(/relative|absolute/i).test(tFix[t].currentStyle.position)) {\r
182                         tFix[t].style.position = 'relative';\r
183                 }\r
184         }\r
185 };\r
186 \r
187 \r
188 IEPNGFix.hook = function() {\r
189         if (IEPNGFix.hook.enabled) {\r
190                 IEPNGFix.process(element, 0);\r
191         }\r
192 };\r
193 \r
194 \r
195 IEPNGFix.process(element, 1);\r
196 \r
197 </script>\r
198 </public:component>\r