Some interesting keycode stuff, but we're not going to use it anymore
[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 var fields = {
13 red : '',
14 green : '',
15 blue : '',
16 hex : ''
17 };
18
19 // ###################################################################
20 // watches the three RGB fields to make sure they don't go over the limites
21 function rgbwatcher(colour)
22 {
23 keycode = event.keyCode;
24 field = document.getElementById(colour + "inputf");
25
26 if ((keycode >= 48 && keycode <= 57) || (keycode >= 96 && keycode <= 105))
27 {
28 fields[colour] = intval(fields[colour].toString() + intval(fetch_keycode_val(keycode)));
29 }
30 // backspace
31 else if (keycode == 8)
32 {
33 fields[colour] = fields[colour].toString().substr(0, fields[colour].toString().length - 1);
34 field.value = fields[colour];
35 }
36 else
37 {
38 //alert("bad key: " + keycode);
39 field.value = fields[colour];
40 }
41
42 //alert(window.event.keycode);
43
44
45 //alert(field.value);
46 }
47
48 // ###################################################################
49 // fetches the integer value
50 function intval(aval)
51 {
52 return aval - 0;
53 }
54
55 // ###################################################################
56 // lookup keycode
57 function fetch_keycode_val(keycode)
58 {
59 switch (keycode)
60 {
61 case 48:
62 case 96:
63 val = 0;
64 break;
65 case 49:
66 case 97:
67 val = 1;
68 break;
69 case 50:
70 case 98:
71 val = 2;
72 break;
73 case 51:
74 case 99:
75 val = 3;
76 break;
77 case 52:
78 case 100:
79 val = 4;
80 break;
81 case 53:
82 case 101:
83 val = 5;
84 break;
85 case 54:
86 case 102:
87 val = 6;
88 break;
89 case 55:
90 case 103:
91 val = 7;
92 break;
93 case 56:
94 case 104:
95 val = 8;
96 break;
97 case 57:
98 case 105:
99 val = 9;
100 break;
101 }
102
103 return val;
104 }
105
106 // ###################################################################
107 // ###################################################################
108 // ###################################################################
109
110 // flip data
111
112 function show_back()
113 {
114 var front = document.getElementById("front");
115 var back = document.getElementById("back");
116
117 if (window.widget)
118 {
119 widget.prepareForTransition("ToBack");
120 }
121
122 front.style.display = "none";
123 back.style.display = "block";
124
125 if (window.widget)
126 {
127 setTimeout("widget.performTransition();", 0);
128 }
129
130 document.getElementById("fliprollie").style.display = "none";
131 }
132
133 function hide_back()
134 {
135 var front = document.getElementById("front");
136 var back = document.getElementById("back");
137
138 if (window.widget)
139 {
140 widget.prepareForTransition("ToFront");
141 }
142
143 back.style.display = "none";
144 front.style.display = "block";
145
146 if (window.widget)
147 {
148 setTimeout("widget.performTransition();", 0);
149 }
150 }
151
152 var flipShown = false;
153
154 var animation = {
155 duration : 0,
156 starttime : 0,
157 to : 1.0,
158 now : 0.0,
159 from : 0.0,
160 firstElement : null,
161 timer : null
162 };
163
164 function mousemove(event)
165 {
166 if (!flipShown)
167 {
168 if (animation.timer != null)
169 {
170 clearInterval(animation.timer);
171 animation.timer = null;
172 }
173
174 var starttime = (new Date).getTime() - 13;
175
176 animation.duration = 500;
177 animation.starttime = starttime;
178 animation.firstElement = document.getElementById("flip");
179 animation.timer = setInterval("animate();", 13);
180 animation.from = animation.now;
181 animation.to = 1.0;
182 animate();
183 flipShown = true;
184 }
185 }
186
187 function mouseexit(event)
188 {
189 if (flipShown)
190 {
191 // fade in the flip widget
192 if (animation.timer != null)
193 {
194 clearInterval (animation.timer);
195 animation.timer = null;
196 }
197
198 var starttime = (new Date).getTime() - 13;
199
200 animation.duration = 500;
201 animation.starttime = starttime;
202 animation.firstElement = document.getElementById("flip");
203 animation.timer = setInterval("animate();", 13);
204 animation.from = animation.now;
205 animation.to = 0.0;
206 animate();
207 flipShown = false;
208 }
209 }
210
211
212 function animate()
213 {
214 var T;
215 var ease;
216 var time = (new Date).getTime();
217
218 T = limit_3(time - animation.starttime, 0, animation.duration);
219
220 if (T >= animation.duration)
221 {
222 clearInterval(animation.timer);
223 animation.timer = null;
224 animation.now = animation.to;
225 }
226 else
227 {
228 ease = 0.5 - (0.5 * Math.cos(Math.PI * T / animation.duration));
229 animation.now = compute_next_float(animation.from, animation.to, ease);
230 }
231
232 animation.firstElement.style.opacity = animation.now;
233 }
234
235 function limit_3 (a, b, c)
236 {
237 return a < b ? b : (a > c ? c : a);
238 }
239
240 function compute_next_float(from, to, ease)
241 {
242 return from + (to - from) * ease;
243 }
244
245 function enterflip(event)
246 {
247 document.getElementById("fliprollie").style.display = "block";
248 }
249
250 function exitflip(event)
251 {
252 document.getElementById("fliprollie").style.display = "none";
253 }
254
255 /*=====================================================================*\
256 || ###################################################################
257 || # $HeadURL$
258 || # $Id$
259 || ###################################################################
260 \*=====================================================================*/