pngbehavior.htc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <public:component>
  2. <public:attach event="onpropertychange" onevent="propertyChanged()" />
  3. <public:attach event="onbeforeprint" for="window" onevent="beforePrint()" />
  4. <public:attach event="onafterprint" for="window" onevent="afterPrint()" />
  5. <script>
  6. /*
  7. * PNG Behavior
  8. *
  9. * This script was created by Erik Arvidsson (erik(at)eae.net)
  10. * for WebFX (http://webfx.eae.net)
  11. * Copyright 2002
  12. *
  13. * For usage see license at http://webfx.eae.net/license.html
  14. *
  15. * Version: 1.01a
  16. * Created: 2001-??-?? First working version
  17. * Updated: 2002-03-28 Fixed issue when starting with a non png image and
  18. * switching between non png images
  19. * 2003-01-06 Fixed RegExp to correctly work with IE 5.0x
  20. * 2004-04-25 Fixed PNG image printing, eliminated need for external
  21. * GIF file, fixed intermittent uninitialised variable
  22. * error [by AG, <http://www.scss.com.au/family/andrew/> ]
  23. * 2004-09-30 Reverted inline javascript image to transparent GIF. The
  24. * new XP SP2 'security' measures prevented the JS image
  25. * from working. [by AG]
  26. * 2004-10-22 Rewrote fixImage() to try and work around some reported
  27. * problems with PNGs vanishing! [by AG]
  28. * 2004-12-12 Fixed problem with PNGs not being restored after
  29. * printing. I have no idea how I missed this one! [by AG]
  30. * 2005-03-26 Fixed supported RE mis-identifying IE 5.0/Win98 as
  31. * 'supported'.
  32. *
  33. */
  34. var IS_PNG = /\.png$/i;
  35. var supported = /MSIE (5\.[5-9]|[6]\.[0-9]*)/.test(navigator.userAgent) && navigator.platform == 'Win32';
  36. var realSrc;
  37. var blankSrc = '/images/blank.png';
  38. if (supported) fixImage();
  39. function propertyChanged() {
  40. if (supported && event.propertyName == 'src') {
  41. var i = element.src.lastIndexOf(blankSrc);
  42. if (i == -1 || i != element.src.length - blankSrc.length) {
  43. fixImage();
  44. }
  45. }
  46. }
  47. function fixImage() {
  48. if (realSrc && element.src == realSrc) {
  49. // this is an attempt to set the image to itself!
  50. // pointless - leave the filter as-is, restore the blank image
  51. element.src = blankSrc;
  52. } else {
  53. // set the image to something different
  54. if (IS_PNG.test(element.src)) {
  55. // fixable PNG
  56. realSrc = element.src;
  57. element.src = blankSrc;
  58. element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + realSrc + "',sizingMethod='scale')";
  59. } else {
  60. // ordinary image - make sure the fix is removed
  61. if (realSrc) {
  62. realSrc = null;
  63. element.runtimeStyle.filter = '';
  64. }
  65. }
  66. }
  67. }
  68. function beforePrint() {
  69. if (realSrc) {
  70. supported = false;
  71. element.src = realSrc;
  72. element.runtimeStyle.filter = '';
  73. supported = true;
  74. }
  75. }
  76. function afterPrint() {
  77. if (realSrc) {
  78. var rs = realSrc;
  79. realSrc = null;
  80. element.src = rs;
  81. }
  82. }
  83. </script>
  84. </public:component>