Widget now works in basic form
[rgbconverter.git] / RGB_Converter / RGB_Converter.wdgt / Widget.js
1 /*=====================================================================*\
2 || ################################################################### ||
3 || # RGB Converter Widget [#]version[#]
4 || # --------------------------------------------------------------- # ||
5 || # Copyright ©2002-[#]year[#] by Iris Studios, Inc. All Rights Reserved. # ||
6 || # This file may not be reproduced in any way without permission. # ||
7 || # --------------------------------------------------------------- # ||
8 || # User License Agreement at http://www.iris-studios.com/license/ # ||
9 || ################################################################### ||
10 \*=====================================================================*/
11
12 // ###################################################################
13 // flip data
14
15 function show_back()
16 {
17 var front = document.getElementById("front");
18 var back = document.getElementById("back");
19
20 if (window.widget)
21 {
22 widget.prepareForTransition("ToBack");
23 }
24
25 front.style.display = "none";
26 back.style.display = "block";
27
28 if (window.widget)
29 {
30 setTimeout("widget.performTransition();", 0);
31 }
32
33 document.getElementById("fliprollie").style.display = "none";
34 }
35
36
37 function hide_back()
38 {
39 var front = document.getElementById("front");
40 var back = document.getElementById("back");
41
42 if (window.widget)
43 {
44 widget.prepareForTransition("ToFront");
45 }
46
47 back.style.display = "none";
48 front.style.display = "block";
49
50 if (window.widget)
51 {
52 setTimeout("widget.performTransition();", 0);
53 }
54 }
55
56 var flipShown = false;
57
58 var animation = {
59 duration : 0,
60 starttime : 0,
61 to : 1.0,
62 now : 0.0,
63 from : 0.0,
64 firstElement : null,
65 timer : null
66 };
67
68 function mousemove(event)
69 {
70 if (!flipShown)
71 {
72 if (animation.timer != null)
73 {
74 clearInterval(animation.timer);
75 animation.timer = null;
76 }
77
78 var starttime = (new Date).getTime() - 13;
79
80 animation.duration = 500;
81 animation.starttime = starttime;
82 animation.firstElement = document.getElementById("flip");
83 animation.timer = setInterval("animate();", 13);
84 animation.from = animation.now;
85 animation.to = 1.0;
86 animate();
87 flipShown = true;
88 }
89 }
90
91 function mouseexit(event)
92 {
93 if (flipShown)
94 {
95 // fade in the flip widget
96 if (animation.timer != null)
97 {
98 clearInterval (animation.timer);
99 animation.timer = null;
100 }
101
102 var starttime = (new Date).getTime() - 13;
103
104 animation.duration = 500;
105 animation.starttime = starttime;
106 animation.firstElement = document.getElementById("flip");
107 animation.timer = setInterval("animate();", 13);
108 animation.from = animation.now;
109 animation.to = 0.0;
110 animate();
111 flipShown = false;
112 }
113 }
114
115
116 function animate()
117 {
118 var T;
119 var ease;
120 var time = (new Date).getTime();
121
122 T = limit_3(time - animation.starttime, 0, animation.duration);
123
124 if (T >= animation.duration)
125 {
126 clearInterval (animation.timer);
127 animation.timer = null;
128 animation.now = animation.to;
129 }
130 else
131 {
132 ease = 0.5 - (0.5 * Math.cos(Math.PI * T / animation.duration));
133 animation.now = compute_next_float(animation.from, animation.to, ease);
134 }
135
136 animation.firstElement.style.opacity = animation.now;
137 }
138
139
140 function limit_3 (a, b, c)
141 {
142 return a < b ? b : (a > c ? c : a);
143 }
144
145 function compute_next_float(from, to, ease)
146 {
147 return from + (to - from) * ease;
148 }
149
150 function enterflip(event)
151 {
152 document.getElementById("fliprollie").style.display = "block";
153 }
154
155 function exitflip(event)
156 {
157 document.getElementById("fliprollie").style.display = "none";
158 }
159
160 /*=====================================================================*\
161 || ###################################################################
162 || # $HeadURL$
163 || # $Id$
164 || ###################################################################
165 \*=====================================================================*/