iepngfix.htc 4.7 KB

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