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