~ubuntu-branches/ubuntu/oneiric/emesene/oneiric-proposed

« back to all changes in this revision

Viewing changes to emesene/themes/conversations/Ravenant.AdiumMessageStyle/Contents/Resources/javascripts/reflection.js

  • Committer: Bazaar Package Importer
  • Author(s): Devid Antonio Filoni
  • Date: 2011-03-03 14:49:13 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20110303144913-0adl9cmw2s35lvzo
Tags: 2.0~git20110303-0ubuntu1
* New upstream git revision (LP: #728469).
* Remove debian/watch, debian/emesene.xpm, debian/install and
  debian/README.source files.
* Remove 21_svn2451_fix_avatar and 20_dont_build_own_libmimic patches.
* debian/control: modify python to python (>= 2.5) in Build-Depends field.
* debian/control: remove python-libmimic from Recommends field.
* debian/control: modify python-gtk2 (>= 2.10) to python-gtk2 (>= 2.12) in
  Depends field.
* debian/control: add python-appindicator and python-xmpp to Recommends
  field.
* debian/control: add python-papyon (>= 0.5.4) and python-webkit to Depends
  field.
* debian/control: update Description field.
* debian/control: add python-setuptools to Build-Depends field.
* debian/control: move python-dbus and python-notify to Depends field.
* Update debian/copyright file.
* Update debian/links file.
* debian/menu: update description field.
* Bump Standards-Version to 3.9.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * reflection.js v1.6
 
3
 *
 
4
 * Contributors: Cow http://cow.neondragon.net
 
5
 *               Gfx http://www.jroller.com/page/gfx/
 
6
 *               Sitharus http://www.sitharus.com
 
7
 *               Andreas Linde http://www.andreaslinde.de
 
8
 *               Tralala, coder @ http://www.vbulletin.org
 
9
 *
 
10
 * Freely distributable under MIT-style license.
 
11
 */
 
12
 
 
13
/* From prototype.js */
 
14
document.getElementsByClassName = function(className) {
 
15
        var children = document.getElementsByTagName('*') || document.all;
 
16
        var elements = new Array();
 
17
  
 
18
        for (var i = 0; i < children.length; i++) {
 
19
                var child = children[i];
 
20
                var classNames = child.className.split(' ');
 
21
                for (var j = 0; j < classNames.length; j++) {
 
22
                        if (classNames[j] == className) {
 
23
                                elements.push(child);
 
24
                                break;
 
25
                        }
 
26
                }
 
27
        }
 
28
        return elements;
 
29
}
 
30
 
 
31
var Reflection = {
 
32
        defaultHeight : 0.45,
 
33
        defaultOpacity: 0.4,
 
34
        
 
35
        add: function(image, options) {
 
36
                Reflection.remove(image);
 
37
                
 
38
                doptions = { "height" : Reflection.defaultHeight, "opacity" : Reflection.defaultOpacity }
 
39
                if (options) {
 
40
                        for (var i in doptions) {
 
41
                                if (!options[i]) {
 
42
                                        options[i] = doptions[i];
 
43
                                }
 
44
                        }
 
45
                } else {
 
46
                        options = doptions;
 
47
                }
 
48
        
 
49
                try {
 
50
                        var d = document.createElement('div');
 
51
                        var p = image;
 
52
                        
 
53
                        var classes = p.className.split(' ');
 
54
                        var newClasses = '';
 
55
                        for (j=0;j<classes.length;j++) {
 
56
                                if (classes[j] != "reflect") {
 
57
                                        if (newClasses) {
 
58
                                                newClasses += ' '
 
59
                                        }
 
60
                                        
 
61
                                        newClasses += classes[j];
 
62
                                }
 
63
                        }
 
64
 
 
65
                        var reflectionHeight = Math.floor(p.height*options['height']);
 
66
                        var divHeight = Math.floor(p.height*(1+options['height']));
 
67
                        
 
68
                        var reflectionWidth = p.width;
 
69
                        
 
70
                        if (document.all && !window.opera) {
 
71
                                /* Copy original image's classes & styles to div */
 
72
                                d.className = newClasses;
 
73
                                p.className = 'reflected';
 
74
                                
 
75
                                d.style.cssText = p.style.cssText;
 
76
                                p.style.cssText = 'vertical-align: bottom';
 
77
                        
 
78
                                var reflection = document.createElement('img');
 
79
                                reflection.src = p.src;
 
80
                                reflection.style.width = reflectionWidth+'px';
 
81
                                
 
82
                                reflection.style.marginBottom = "-"+(p.height-reflectionHeight)+'px';
 
83
                                reflection.style.filter = 'flipv progid:DXImageTransform.Microsoft.Alpha(opacity='+(options['opacity']*100)+', style=1, finishOpacity=0, startx=0, starty=0, finishx=0, finishy='+(options['height']*100)+')';
 
84
                                
 
85
                                d.style.width = reflectionWidth+'px';
 
86
                                d.style.height = divHeight+'px';
 
87
                                p.parentNode.replaceChild(d, p);
 
88
                                
 
89
                                d.appendChild(p);
 
90
                                d.appendChild(reflection);
 
91
                        } else {
 
92
                                var canvas = document.createElement('canvas');
 
93
                                if (canvas.getContext) {
 
94
                                        /* Copy original image's classes & styles to div */
 
95
                                        d.className = newClasses;
 
96
                                        p.className = 'reflected';
 
97
                                        
 
98
                                        d.style.cssText = p.style.cssText;
 
99
                                        p.style.cssText = 'vertical-align: bottom';
 
100
                        
 
101
                                        var context = canvas.getContext("2d");
 
102
                                
 
103
                                        canvas.style.height = reflectionHeight+'px';
 
104
                                        canvas.style.width = reflectionWidth+'px';
 
105
                                        canvas.height = reflectionHeight;
 
106
                                        canvas.width = reflectionWidth;
 
107
                                        
 
108
                                        d.style.width = reflectionWidth+'px';
 
109
                                        d.style.height = divHeight+'px';
 
110
                                        p.parentNode.replaceChild(d, p);
 
111
                                        
 
112
                                        d.appendChild(p);
 
113
                                        d.appendChild(canvas);
 
114
                                        
 
115
                                        context.save();
 
116
                                        
 
117
                                        context.translate(0,image.height-1);
 
118
                                        context.scale(1,-1);
 
119
                                        
 
120
                                        context.drawImage(image, 0, 0, reflectionWidth, image.height);
 
121
        
 
122
                                        context.restore();
 
123
                                        
 
124
                                        context.globalCompositeOperation = "destination-out";
 
125
                                        var gradient = context.createLinearGradient(0, 0, 0, reflectionHeight);
 
126
                                        
 
127
                                        gradient.addColorStop(1, "rgba(255, 255, 255, 1.0)");
 
128
                                        gradient.addColorStop(0, "rgba(255, 255, 255, "+(1-options['opacity'])+")");
 
129
                
 
130
                                        context.fillStyle = gradient;
 
131
                                        if (navigator.appVersion.indexOf('WebKit') != -1) {
 
132
                                                context.fill();
 
133
                                        } else {
 
134
                                                context.fillRect(0, 0, reflectionWidth, reflectionHeight*2);
 
135
                                        }
 
136
                                }
 
137
                        }
 
138
                } catch (e) {
 
139
            }
 
140
        },
 
141
        
 
142
        remove : function(image) {
 
143
                if (image.className == "reflected") {
 
144
                        image.className = image.parentNode.className;
 
145
                        image.parentNode.parentNode.replaceChild(image, image.parentNode);
 
146
                }
 
147
        }
 
148
}
 
149
 
 
150
function addReflections() {
 
151
        var rimages = document.getElementsByClassName('reflect');
 
152
        for (i=0;i<rimages.length;i++) {
 
153
                var rheight = null;
 
154
                var ropacity = null;
 
155
                
 
156
                var classes = rimages[i].className.split(' ');
 
157
                for (j=0;j<classes.length;j++) {
 
158
                        if (classes[j].indexOf("rheight") == 0) {
 
159
                                var rheight = classes[j].substring(7)/100;
 
160
                        } else if (classes[j].indexOf("ropacity") == 0) {
 
161
                                var ropacity = classes[j].substring(8)/100;
 
162
                        }
 
163
                }
 
164
                
 
165
                Reflection.add(rimages[i], { height: rheight, opacity : ropacity});
 
166
        }
 
167
}
 
168
 
 
169
var previousOnload = window.onload;
 
170
window.onload = function () { if(previousOnload) previousOnload(); addReflections(); }