1 /*=====================================================================*\
2 || ###################################################################
3 || # RGB Converter [#]version[#]
4 || # Copyright ©2002-[#]year[#] Blue Static
6 || # This program is free software; you can redistribute it and/or modify
7 || # it under the terms of the GNU General Public License as published by
8 || # the Free Software Foundation; version [#]gpl[#] of the License.
10 || # This program is distributed in the hope that it will be useful, but
11 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 || # You should have received a copy of the GNU General Public License along
16 || # with this program; if not, write to the Free Software Foundation, Inc.,
17 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
18 || ###################################################################
19 \*=====================================================================*/
28 // ###################################################################
32 createGenericButton(document
.getElementById("backbutton"), "Done", hide_back
, 0);
35 // ###################################################################
36 // watches the three RGB fields to make sure they don't go over the limites
37 function rgbwatcher(colour
)
39 field
= document
.getElementById(colour
+ "inputf");
41 // sanitize the number
42 var newval
= field
.value
.replace(/[^0-9\-\.]*/g
, "");
43 newval
= Math
.floor(newval
);
45 // make sure we don't go over 255
55 // update the text field
59 fields
[colour] = newval
;
68 // ###################################################################
69 // watches the hex field for updates
72 field
= document
.getElementById("hexinputf");
75 var newval
= field
.value
.replace(/[^0-9a
-f
]*/gi
, "");
78 var length
= newval
.length
;
80 // make sure we're always 6
83 newval
= newval
.substr(0, 6);
87 for (var i
= length
; i
<= 6; i
++)
89 newval
= "" + newval
+ "0";
97 fields
['hex'] = newval
;
106 // ###################################################################
107 // update the hex value
108 function update_hex()
110 var hexstr
= dec2hex(fields
['red']) + dec2hex(fields
['green']) + dec2hex(fields
['blue']);
111 fields
['hex'] = hexstr
;
112 document
.getElementById("hexinputf").value
= hexstr
;
115 // ###################################################################
116 // update the RGB values
117 function update_rgb()
119 // regex match the bits
120 var bits
= fields
['hex'].match(/(..)(..)(..)/);
122 fields
['red'] = hex2dec(bits
[1]);
123 fields
['green'] = hex2dec(bits
[2]);
124 fields
['blue'] = hex2dec(bits
[3]);
126 // construct the hex values
127 document
.getElementById("redinputf").value
= fields
['red'];
128 document
.getElementById("greeninputf").value
= fields
['green'];
129 document
.getElementById("blueinputf").value
= fields
['blue'];
132 // ###################################################################
133 // update the colour swatch
134 function update_swatch()
136 document
.getElementById("swatch").style
.backgroundColor
= "rgb(" + fields
['red'] + ", " + fields
['green'] + ", " + fields
['blue'] + ")";
137 document
.getElementById("swatch-red").style
.backgroundColor
= "rgb(" + fields
['red'] + ", 0, 0)";
138 document
.getElementById("swatch-green").style
.backgroundColor
= "rgb(0, " + fields
['green'] + ", 0)";
139 document
.getElementById("swatch-blue").style
.backgroundColor
= "rgb(0, 0, " + fields
['blue'] + ")";
142 // ###################################################################
143 // convert a decimal to a hexidecimal
144 function dec2hex(dec
)
146 var hexstr
= "0123456789ABCDEF";
148 var high
= (dec
- low
) / 16;
149 hex
= "" + hexstr
.charAt(high
) + hexstr
.charAt(low
);
151 return hex
.toString();
154 // ###################################################################
155 // converts a hexidecimal to a decimal
156 function hex2dec(hex
)
158 return parseInt(hex
, 16);
161 // ###################################################################
162 // ###################################################################
163 // ###################################################################
169 var front
= document
.getElementById("front");
170 var back
= document
.getElementById("back");
174 widget
.prepareForTransition("ToBack");
177 front
.style
.display
= "none";
178 back
.style
.display
= "block";
182 setTimeout("widget.performTransition();", 0);
185 document
.getElementById("fliprollie").style
.display
= "none";
190 var front
= document
.getElementById("front");
191 var back
= document
.getElementById("back");
195 widget
.prepareForTransition("ToFront");
198 back
.style
.display
= "none";
199 front
.style
.display
= "block";
203 setTimeout("widget.performTransition();", 0);
207 var flipShown
= false;
219 function mousemove(event
)
223 if (animation
.timer
!= null)
225 clearInterval(animation
.timer
);
226 animation
.timer
= null;
229 var starttime
= (new Date
).getTime() - 13;
231 animation
.duration
= 500;
232 animation
.starttime
= starttime
;
233 animation
.firstElement
= document
.getElementById("flip");
234 animation
.timer
= setInterval("animate();", 13);
235 animation
.from
= animation
.now
;
242 function mouseexit(event
)
246 // fade in the flip widget
247 if (animation
.timer
!= null)
249 clearInterval (animation
.timer
);
250 animation
.timer
= null;
253 var starttime
= (new Date
).getTime() - 13;
255 animation
.duration
= 500;
256 animation
.starttime
= starttime
;
257 animation
.firstElement
= document
.getElementById("flip");
258 animation
.timer
= setInterval("animate();", 13);
259 animation
.from
= animation
.now
;
271 var time
= (new Date
).getTime();
273 T
= limit_3(time
- animation
.starttime
, 0, animation
.duration
);
275 if (T
>= animation
.duration
)
277 clearInterval(animation
.timer
);
278 animation
.timer
= null;
279 animation
.now
= animation
.to
;
283 ease
= 0.5 - (0.5 * Math
.cos(Math
.PI
* T
/ animation
.duration
));
284 animation
.now
= compute_next_float(animation
.from
, animation
.to
, ease
);
287 animation
.firstElement
.style
.opacity
= animation
.now
;
290 function limit_3 (a
, b
, c
)
292 return a
< b
? b
: (a
> c
? c
: a
);
295 function compute_next_float(from
, to
, ease
)
297 return from
+ (to
- from
) * ease
;
300 function enterflip(event
)
302 document
.getElementById("fliprollie").style
.display
= "block";
305 function exitflip(event
)
307 document
.getElementById("fliprollie").style
.display
= "none";
310 /*=====================================================================*\
311 || ###################################################################
314 || ###################################################################
315 \*=====================================================================*/