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 \*=====================================================================*/
19 // ###################################################################
23 createGenericButton(document
.getElementById("backbutton"), "Done", hide_back
, 0);
26 // ###################################################################
27 // watches the three RGB fields to make sure they don't go over the limites
28 function rgbwatcher(colour
)
30 field
= document
.getElementById(colour
+ "inputf");
32 // sanitize the number
33 var newval
= field
.value
.replace(/[^0-9\-\.]*/g
, "");
34 newval
= Math
.floor(newval
);
36 // make sure we don't go over 255
46 // update the text field
50 fields
[colour] = newval
;
59 // ###################################################################
60 // watches the hex field for updates
63 field
= document
.getElementById("hexinputf");
66 var newval
= field
.value
.replace(/[^0-9a
-f
]*/gi
, "");
69 var length
= newval
.length
;
71 // make sure we're always 6
74 newval
= newval
.substr(0, 6);
78 for (var i
= length
; i
<= 6; i
++)
80 newval
= "" + newval
+ "0";
88 fields
['hex'] = newval
;
97 // ###################################################################
98 // update the hex value
101 var hexstr
= dec2hex(fields
['red']) + dec2hex(fields
['green']) + dec2hex(fields
['blue']);
102 fields
['hex'] = hexstr
;
103 document
.getElementById("hexinputf").value
= hexstr
;
106 // ###################################################################
107 // update the RGB values
108 function update_rgb()
110 // regex match the bits
111 var bits
= fields
['hex'].match(/(..)(..)(..)/);
113 fields
['red'] = hex2dec(bits
[1]);
114 fields
['green'] = hex2dec(bits
[2]);
115 fields
['blue'] = hex2dec(bits
[3]);
117 // construct the hex values
118 document
.getElementById("redinputf").value
= fields
['red'];
119 document
.getElementById("greeninputf").value
= fields
['green'];
120 document
.getElementById("blueinputf").value
= fields
['blue'];
123 // ###################################################################
124 // update the colour swatch
125 function update_swatch()
127 document
.getElementById("swatch").style
.backgroundColor
= "rgb(" + fields
['red'] + ", " + fields
['green'] + ", " + fields
['blue'] + ")";
130 // ###################################################################
131 // convert a decimal to a hexidecimal
132 function dec2hex(dec
)
134 var hexstr
= "0123456789ABCDEF";
136 var high
= (dec
- low
) / 16;
137 hex
= "" + hexstr
.charAt(high
) + hexstr
.charAt(low
);
139 return hex
.toString();
142 // ###################################################################
143 // converts a hexidecimal to a decimal
144 function hex2dec(hex
)
146 return parseInt(hex
, 16);
149 // ###################################################################
150 // ###################################################################
151 // ###################################################################
157 var front
= document
.getElementById("front");
158 var back
= document
.getElementById("back");
162 widget
.prepareForTransition("ToBack");
165 front
.style
.display
= "none";
166 back
.style
.display
= "block";
170 setTimeout("widget.performTransition();", 0);
173 document
.getElementById("fliprollie").style
.display
= "none";
178 var front
= document
.getElementById("front");
179 var back
= document
.getElementById("back");
183 widget
.prepareForTransition("ToFront");
186 back
.style
.display
= "none";
187 front
.style
.display
= "block";
191 setTimeout("widget.performTransition();", 0);
195 var flipShown
= false;
207 function mousemove(event
)
211 if (animation
.timer
!= null)
213 clearInterval(animation
.timer
);
214 animation
.timer
= null;
217 var starttime
= (new Date
).getTime() - 13;
219 animation
.duration
= 500;
220 animation
.starttime
= starttime
;
221 animation
.firstElement
= document
.getElementById("flip");
222 animation
.timer
= setInterval("animate();", 13);
223 animation
.from
= animation
.now
;
230 function mouseexit(event
)
234 // fade in the flip widget
235 if (animation
.timer
!= null)
237 clearInterval (animation
.timer
);
238 animation
.timer
= null;
241 var starttime
= (new Date
).getTime() - 13;
243 animation
.duration
= 500;
244 animation
.starttime
= starttime
;
245 animation
.firstElement
= document
.getElementById("flip");
246 animation
.timer
= setInterval("animate();", 13);
247 animation
.from
= animation
.now
;
259 var time
= (new Date
).getTime();
261 T
= limit_3(time
- animation
.starttime
, 0, animation
.duration
);
263 if (T
>= animation
.duration
)
265 clearInterval(animation
.timer
);
266 animation
.timer
= null;
267 animation
.now
= animation
.to
;
271 ease
= 0.5 - (0.5 * Math
.cos(Math
.PI
* T
/ animation
.duration
));
272 animation
.now
= compute_next_float(animation
.from
, animation
.to
, ease
);
275 animation
.firstElement
.style
.opacity
= animation
.now
;
278 function limit_3 (a
, b
, c
)
280 return a
< b
? b
: (a
> c
? c
: a
);
283 function compute_next_float(from
, to
, ease
)
285 return from
+ (to
- from
) * ease
;
288 function enterflip(event
)
290 document
.getElementById("fliprollie").style
.display
= "block";
293 function exitflip(event
)
295 document
.getElementById("fliprollie").style
.display
= "none";
298 /*=====================================================================*\
299 || ###################################################################
302 || ###################################################################
303 \*=====================================================================*/