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 // ###################################################################
20 // watches the three RGB fields to make sure they don't go over the limites
21 function rgbwatcher(colour
)
23 field
= document
.getElementById(colour
+ "inputf");
25 // sanitize the number
26 var newval
= field
.value
.replace(/[^0-9\-\.]*/g
, "");
27 newval
= Math
.floor(newval
);
29 // make sure we don't go over 255
39 // update the text field
43 fields
[colour] = newval
;
52 // ###################################################################
53 // watches the hex field for updates
56 field
= document
.getElementById("hexinputf");
59 var newval
= field
.value
.replace(/[^0-9a
-f
]*/gi
, "");
62 var length
= newval
.length
;
64 // make sure we're always 6
67 newval
= newval
.substr(0, 6);
71 for (var i
= length
; i
<= 6; i
++)
73 newval
= "" + newval
+ "0";
81 fields
['hex'] = newval
;
90 // ###################################################################
91 // update the hex value
94 var hexstr
= dec2hex(fields
['red']) + dec2hex(fields
['green']) + dec2hex(fields
['blue']);
95 fields
['hex'] = hexstr
;
96 document
.getElementById("hexinputf").value
= hexstr
;
99 // ###################################################################
100 // update the RGB values
101 function update_rgb()
103 // regex match the bits
104 var bits
= fields
['hex'].match(/(..)(..)(..)/);
106 fields
['red'] = hex2dec(bits
[1]);
107 fields
['green'] = hex2dec(bits
[2]);
108 fields
['blue'] = hex2dec(bits
[3]);
110 // construct the hex values
111 document
.getElementById("redinputf").value
= fields
['red'];
112 document
.getElementById("greeninputf").value
= fields
['green'];
113 document
.getElementById("blueinputf").value
= fields
['blue'];
116 // ###################################################################
117 // update the colour swatch
118 function update_swatch()
120 document
.getElementById("swatch").style
.backgroundColor
= "#" + fields
['hex'];
123 // ###################################################################
124 // convert a decimal to a hexidecimal
125 function dec2hex(dec
)
127 var hexstr
= "0123456789ABCDEF";
129 var high
= (dec
- low
) / 16;
130 hex
= "" + hexstr
.charAt(high
) + hexstr
.charAt(low
);
132 return hex
.toString();
135 // ###################################################################
136 // converts a hexidecimal to a decimal
137 function hex2dec(hex
)
139 return parseInt(hex
, 16);
142 // ###################################################################
143 // ###################################################################
144 // ###################################################################
150 var front
= document
.getElementById("front");
151 var back
= document
.getElementById("back");
155 widget
.prepareForTransition("ToBack");
158 front
.style
.display
= "none";
159 back
.style
.display
= "block";
163 setTimeout("widget.performTransition();", 0);
166 document
.getElementById("fliprollie").style
.display
= "none";
171 var front
= document
.getElementById("front");
172 var back
= document
.getElementById("back");
176 widget
.prepareForTransition("ToFront");
179 back
.style
.display
= "none";
180 front
.style
.display
= "block";
184 setTimeout("widget.performTransition();", 0);
188 var flipShown
= false;
200 function mousemove(event
)
204 if (animation
.timer
!= null)
206 clearInterval(animation
.timer
);
207 animation
.timer
= null;
210 var starttime
= (new Date
).getTime() - 13;
212 animation
.duration
= 500;
213 animation
.starttime
= starttime
;
214 animation
.firstElement
= document
.getElementById("flip");
215 animation
.timer
= setInterval("animate();", 13);
216 animation
.from
= animation
.now
;
223 function mouseexit(event
)
227 // fade in the flip widget
228 if (animation
.timer
!= null)
230 clearInterval (animation
.timer
);
231 animation
.timer
= null;
234 var starttime
= (new Date
).getTime() - 13;
236 animation
.duration
= 500;
237 animation
.starttime
= starttime
;
238 animation
.firstElement
= document
.getElementById("flip");
239 animation
.timer
= setInterval("animate();", 13);
240 animation
.from
= animation
.now
;
252 var time
= (new Date
).getTime();
254 T
= limit_3(time
- animation
.starttime
, 0, animation
.duration
);
256 if (T
>= animation
.duration
)
258 clearInterval(animation
.timer
);
259 animation
.timer
= null;
260 animation
.now
= animation
.to
;
264 ease
= 0.5 - (0.5 * Math
.cos(Math
.PI
* T
/ animation
.duration
));
265 animation
.now
= compute_next_float(animation
.from
, animation
.to
, ease
);
268 animation
.firstElement
.style
.opacity
= animation
.now
;
271 function limit_3 (a
, b
, c
)
273 return a
< b
? b
: (a
> c
? c
: a
);
276 function compute_next_float(from
, to
, ease
)
278 return from
+ (to
- from
) * ease
;
281 function enterflip(event
)
283 document
.getElementById("fliprollie").style
.display
= "block";
286 function exitflip(event
)
288 document
.getElementById("fliprollie").style
.display
= "none";
291 /*=====================================================================*\
292 || ###################################################################
295 || ###################################################################
296 \*=====================================================================*/