iepngfix.htc 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <public:component>
  2. <script type="text/javascript">
  3. // IE5.5+ PNG Alpha Fix v2.0 Alpha
  4. // (c) 2004-2009 Angus Turnbull http://www.twinhelix.com
  5. // This is licensed under the GNU LGPL, version 2.1 or later.
  6. // For details, see: http://creativecommons.org/licenses/LGPL/2.1/
  7. var IEPNGFix = window.IEPNGFix || {};
  8. IEPNGFix.data = IEPNGFix.data || {};
  9. // CONFIG: blankImg is the path to blank.gif, *relative to the HTML document*.
  10. // Try either:
  11. // * An absolute path like: '/images/blank.gif'
  12. // * A path relative to this HTC file like: thisFolder + 'blank.gif'
  13. var thisFolder = document.URL.replace(/(\\|\/)[^\\\/]*$/, '/');
  14. //IEPNGFix.blankImg = thisFolder + 'blank.gif';
  15. IEPNGFix.blankImg = '/css/blank.gif';
  16. IEPNGFix.fix = function(elm, src, t) {
  17. // Applies an image 'src' to an element 'elm' using the DirectX filter.
  18. // If 'src' is null, filter is disabled.
  19. // Disables the 'hook' to prevent infinite recursion on setting BG/src.
  20. // 't' = type, where background tile = 0, background = 1, IMG SRC = 2.
  21. var h = this.hook.enabled;
  22. this.hook.enabled = 0;
  23. var f = 'DXImageTransform.Microsoft.AlphaImageLoader';
  24. src = (src || '').replace(/\(/g, '%28').replace(/\)/g, '%29');
  25. if (
  26. src && !(/IMG|INPUT/.test(elm.nodeName) && (t != 2)) &&
  27. elm.currentStyle.width == 'auto' && elm.currentStyle.height == 'auto'
  28. ) {
  29. if (elm.offsetWidth) {
  30. elm.style.width = elm.offsetWidth + 'px';
  31. }
  32. if (elm.clientHeight) {
  33. elm.style.height = elm.clientHeight + 'px';
  34. }
  35. if (elm.currentStyle.display == 'inline') {
  36. elm.style.display = 'inline-block';
  37. }
  38. }
  39. if (t == 1) {
  40. elm.style.backgroundImage = 'url("' + this.blankImg + '")';
  41. }
  42. if (t == 2) {
  43. elm.src = this.blankImg;
  44. }
  45. if (elm.filters[f]) {
  46. elm.filters[f].enabled = src ? true : false;
  47. if (src) {
  48. elm.filters[f].src = src;
  49. }
  50. } else if (src) {
  51. elm.style.filter = 'progid:' + f + '(src="' + src +
  52. '",sizingMethod="' + (t == 2 ? 'scale' : 'crop') + '")';
  53. }
  54. this.hook.enabled = h;
  55. };
  56. IEPNGFix.process = function(elm, init) {
  57. // Checks the onpropertychange event (on first 'init' run, a fake event)
  58. // and calls the filter-applying-functions.
  59. if (
  60. !/MSIE (5\.5|6)/.test(navigator.userAgent) ||
  61. typeof elm.filters == 'unknown'
  62. ) {
  63. return;
  64. }
  65. if (!this.data[elm.uniqueID]) {
  66. this.data[elm.uniqueID] = {
  67. className: ''
  68. };
  69. }
  70. var data = this.data[elm.uniqueID],
  71. evt = init ? { propertyName: 'src,backgroundImage' } : event,
  72. isSrc = /src/.test(evt.propertyName),
  73. isBg = /backgroundImage/.test(evt.propertyName),
  74. isPos = /width|height|background(Pos|Rep)/.test(evt.propertyName),
  75. isClass = !init && ((elm.className != data.className) &&
  76. (elm.className || data.className));
  77. if (!(isSrc || isBg || isPos || isClass)) {
  78. return;
  79. }
  80. data.className = elm.className;
  81. var blank = this.blankImg.match(/([^\/]+)$/)[1],
  82. eS = elm.style,
  83. eCS = elm.currentStyle;
  84. // Required for Whatever:hover - erase set BG if className changes.
  85. if (
  86. isClass && (eS.backgroundImage.indexOf('url(') == -1 ||
  87. eS.backgroundImage.indexOf(blank) > -1)
  88. ) {
  89. return setTimeout(function() {
  90. eS.backgroundImage = '';
  91. }, 0);
  92. }
  93. // Foregrounds.
  94. if (isSrc && elm.src && { IMG: 1, INPUT: 1 }[elm.nodeName]) {
  95. if ((/\.png/i).test(elm.src)) {
  96. if (!elm.oSrc) {
  97. // MM rollover compat
  98. elm.oSrc = elm.src;
  99. }
  100. this.fix(elm, elm.src, 2);
  101. } else if (elm.src.indexOf(blank) == -1) {
  102. this.fix(elm, '');
  103. }
  104. }
  105. // Backgrounds.
  106. var bgSrc = eCS.backgroundImage || eS.backgroundImage;
  107. if ((bgSrc + elm.src).indexOf(blank) == -1) {
  108. var bgPNG = bgSrc.match(/url[("']+(.*\.png[^\)"']*)[\)"']/i);
  109. if (bgPNG) {
  110. if (this.tileBG && !{ IMG: 1, INPUT: 1 }[elm.nodeName]) {
  111. this.tileBG(elm, bgPNG[1]);
  112. this.fix(elm, '', 1);
  113. } else {
  114. if (data.tiles && data.tiles.src) {
  115. this.tileBG(elm, '');
  116. }
  117. this.fix(elm, bgPNG[1], 1);
  118. this.childFix(elm);
  119. }
  120. } else {
  121. if (data.tiles && data.tiles.src) {
  122. this.tileBG(elm, '');
  123. }
  124. this.fix(elm, '');
  125. }
  126. } else if ((isPos || isClass) && data.tiles && data.tiles.src) {
  127. this.tileBG(elm, data.tiles.src);
  128. }
  129. if (init) {
  130. this.hook.enabled = 1;
  131. elm.attachEvent('onpropertychange', this.hook);
  132. }
  133. };
  134. IEPNGFix.childFix = function(elm) {
  135. // "hasLayout" fix for unclickable children inside PNG backgrounds.
  136. var tags = [
  137. 'a',
  138. 'input',
  139. 'select',
  140. 'textarea',
  141. 'button',
  142. 'iframe',
  143. 'object'
  144. ],
  145. t = tags.length,
  146. tFix = [];
  147. while (t--) {
  148. var pFix = elm.all.tags(tags[t]),
  149. e = pFix.length;
  150. while (e--) {
  151. tFix.push(pFix[e]);
  152. }
  153. }
  154. t = tFix.length;
  155. if (t && (/relative|absolute/i).test(elm.currentStyle.position)) {
  156. alert('IEPNGFix: Unclickable children of element:' +
  157. '\n\n<' + elm.nodeName + (elm.id && ' id=' + elm.id) + '>');
  158. }
  159. while (t--) {
  160. if (!(/relative|absolute/i).test(tFix[t].currentStyle.position)) {
  161. tFix[t].style.position = 'relative';
  162. }
  163. }
  164. };
  165. IEPNGFix.hook = function() {
  166. if (IEPNGFix.hook.enabled) {
  167. IEPNGFix.process(element, 0);
  168. }
  169. };
  170. IEPNGFix.process(element, 1);
  171. </script>
  172. </public:component>