iepngfix.htc 5.1 KB

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