~vanvugt/ubuntu/oneiric/mediatomb/fix-770964-784431

« back to all changes in this revision

Viewing changes to webnew/js/pngbehavior.htc

  • Committer: Bazaar Package Importer
  • Author(s): Andres Mejia
  • Date: 2009-04-22 21:39:19 UTC
  • mto: (4.2.1 sid)
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: james.westby@ubuntu.com-20090422213919-52m015y6gcpv1m1g
Tags: upstream-0.12.0~svn2018
ImportĀ upstreamĀ versionĀ 0.12.0~svn2018

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<public:component lightWeight="true">
 
2
<public:attach event="onpropertychange" onevent="propertyChanged()" />
 
3
<public:attach event="onbeforeprint" onevent="beforePrint()" for="window"/>
 
4
<public:attach event="onafterprint" onevent="afterPrint()" for="window"/>
 
5
<script>
 
6
 
 
7
/*
 
8
 * PNG Behavior
 
9
 *
 
10
 * This script was created by Erik Arvidsson (http://webfx.eae.net/contact.html#erik)
 
11
 * for WebFX (http://webfx.eae.net)
 
12
 * Copyright 2002-2004
 
13
 *
 
14
 * For usage see license at http://webfx.eae.net/license.html
 
15
 *
 
16
 * Notice that the PNG Behavior does not require any license. You may use it 
 
17
 * in any way you see fit as long as credit is given where credit is due. 
 
18
 * In other words, don't claim you create it and don't try to make money 
 
19
 * directly from it.
 
20
 *
 
21
 * Version: 1.02
 
22
 * Created: 2001-??-??  First working version
 
23
 * Updated: 2002-03-28  Fixed issue when starting with a non png image and
 
24
 *                      switching between non png images
 
25
 *          2003-01-06  Fixed RegExp to correctly work with IE 5.0x
 
26
 *          2004-05-09  When printing revert to original
 
27
 *
 
28
 */
 
29
 
 
30
var supported = /MSIE ((5\.5)|[6789])/.test(navigator.userAgent) &&
 
31
                                navigator.platform == "Win32";
 
32
 
 
33
var realSrc;
 
34
var blankSrc = "icons/blank.gif";
 
35
var isPrinting = false;
 
36
 
 
37
if (supported) fixImage();
 
38
 
 
39
function propertyChanged() {
 
40
        if (!supported || isPrinting) return;
 
41
 
 
42
        var pName = event.propertyName;
 
43
        if (pName != "src") return;
 
44
        // if not set to blank
 
45
        if (!new RegExp(blankSrc).test(src))
 
46
                fixImage();
 
47
};
 
48
 
 
49
function fixImage() {
 
50
        // get src
 
51
        var src = element.src;
 
52
 
 
53
        // check for real change
 
54
        if (src == realSrc && /\.png$/i.test(src)) {
 
55
                element.src = blankSrc;
 
56
                return;
 
57
        }
 
58
 
 
59
        if ( ! new RegExp(blankSrc).test(src)) {
 
60
                // backup old src
 
61
                realSrc = src;
 
62
        }
 
63
 
 
64
        // test for png
 
65
        if (/\.png$/i.test(realSrc)) {
 
66
                // set blank image
 
67
                element.src = blankSrc;
 
68
                // set filter
 
69
                element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft." +
 
70
                                        "AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
 
71
        }
 
72
        else {
 
73
                // remove filter
 
74
                element.runtimeStyle.filter = "";
 
75
        }
 
76
}
 
77
 
 
78
function beforePrint() {
 
79
        isPrinting = true;
 
80
        element.src = realSrc;
 
81
        element.runtimeStyle.filter = "";
 
82
        realSrc = null;
 
83
}
 
84
 
 
85
function afterPrint() {
 
86
        isPrinting = false;
 
87
        fixImage();
 
88
}
 
89
 
 
90
</script>
 
91
</public:component>