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'] + ")";
128 document
.getElementById("swatch-red").style
.backgroundColor
= "rgb(" + fields
['red'] + ", 0, 0)";
129 document
.getElementById("swatch-green").style
.backgroundColor
= "rgb(0, " + fields
['green'] + ", 0)";
130 document
.getElementById("swatch-blue").style
.backgroundColor
= "rgb(0, 0, " + fields
['blue'] + ")";
133 // ###################################################################
134 // convert a decimal to a hexidecimal
135 function dec2hex(dec
)
137 var hexstr
= "0123456789ABCDEF";
139 var high
= (dec
- low
) / 16;
140 hex
= "" + hexstr
.charAt(high
) + hexstr
.charAt(low
);
142 return hex
.toString();
145 // ###################################################################
146 // converts a hexidecimal to a decimal
147 function hex2dec(hex
)
149 return parseInt(hex
, 16);
152 // ###################################################################
153 // ###################################################################
154 // ###################################################################
160 var front
= document
.getElementById("front");
161 var back
= document
.getElementById("back");
165 widget
.prepareForTransition("ToBack");
168 front
.style
.display
= "none";
169 back
.style
.display
= "block";
173 setTimeout("widget.performTransition();", 0);
176 document
.getElementById("fliprollie").style
.display
= "none";
181 var front
= document
.getElementById("front");
182 var back
= document
.getElementById("back");
186 widget
.prepareForTransition("ToFront");
189 back
.style
.display
= "none";
190 front
.style
.display
= "block";
194 setTimeout("widget.performTransition();", 0);
198 var flipShown
= false;
210 function mousemove(event
)
214 if (animation
.timer
!= null)
216 clearInterval(animation
.timer
);
217 animation
.timer
= null;
220 var starttime
= (new Date
).getTime() - 13;
222 animation
.duration
= 500;
223 animation
.starttime
= starttime
;
224 animation
.firstElement
= document
.getElementById("flip");
225 animation
.timer
= setInterval("animate();", 13);
226 animation
.from
= animation
.now
;
233 function mouseexit(event
)
237 // fade in the flip widget
238 if (animation
.timer
!= null)
240 clearInterval (animation
.timer
);
241 animation
.timer
= null;
244 var starttime
= (new Date
).getTime() - 13;
246 animation
.duration
= 500;
247 animation
.starttime
= starttime
;
248 animation
.firstElement
= document
.getElementById("flip");
249 animation
.timer
= setInterval("animate();", 13);
250 animation
.from
= animation
.now
;
262 var time
= (new Date
).getTime();
264 T
= limit_3(time
- animation
.starttime
, 0, animation
.duration
);
266 if (T
>= animation
.duration
)
268 clearInterval(animation
.timer
);
269 animation
.timer
= null;
270 animation
.now
= animation
.to
;
274 ease
= 0.5 - (0.5 * Math
.cos(Math
.PI
* T
/ animation
.duration
));
275 animation
.now
= compute_next_float(animation
.from
, animation
.to
, ease
);
278 animation
.firstElement
.style
.opacity
= animation
.now
;
281 function limit_3 (a
, b
, c
)
283 return a
< b
? b
: (a
> c
? c
: a
);
286 function compute_next_float(from
, to
, ease
)
288 return from
+ (to
- from
) * ease
;
291 function enterflip(event
)
293 document
.getElementById("fliprollie").style
.display
= "block";
296 function exitflip(event
)
298 document
.getElementById("fliprollie").style
.display
= "none";
301 /*=====================================================================*\
302 || ###################################################################
305 || ###################################################################
306 \*=====================================================================*/