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);
33 document
.getElementById("revision").innerHTML
= "(r" + document
.getElementById("revision").innerHTML
.replace(/[^0-9]/g
, "") + ")";
36 // ###################################################################
37 // watches the three RGB fields to make sure they don't go over the limites
38 function rgbwatcher(colour
)
40 field
= document
.getElementById(colour
+ "inputf");
43 if (triad
= field
.value
.match(/(rgb
)?\(?([0-9]{1,3}),\s
?([0-9]{1,3}),\s
?([0-9]{1,3})\)?/))
45 document
.getElementById("redinputf").value
= triad
[2];
46 document
.getElementById("greeninputf").value
= triad
[3];
47 document
.getElementById("blueinputf").value
= triad
[4];
55 // sanitize the number
56 var newval
= field
.value
.replace(/[^0-9\-\.]*/g
, "");
57 newval
= Math
.floor(newval
);
59 // make sure we don't go over 255
69 // update the text field
73 fields
[colour] = newval
;
82 // ###################################################################
83 // watches the hex field for updates
86 field
= document
.getElementById("hexinputf");
89 var newval
= field
.value
.replace(/[^0-9a
-f
]*/gi
, "");
92 var length
= newval
.length
;
94 // make sure we're always 6
97 newval
= newval
.substr(0, 6);
101 newval
= newval
.substr(0, 1) + newval
.substr(0, 1) + newval
.substr(1, 1) + newval
.substr(1, 1) + newval
.substr(2, 1) + newval
.substr(2, 1);
105 for (var i
= length
; i
<= 6; i
++)
107 newval
= "" + newval
+ "0";
112 field
.value
= newval
;
115 fields
['hex'] = newval
;
124 // ###################################################################
125 // update the hex value
126 function update_hex()
128 var hexstr
= dec2hex(fields
['red']) + dec2hex(fields
['green']) + dec2hex(fields
['blue']);
129 fields
['hex'] = hexstr
;
130 document
.getElementById("hexinputf").value
= hexstr
;
133 // ###################################################################
134 // update the RGB values
135 function update_rgb()
137 // regex match the bits
138 var bits
= fields
['hex'].match(/(..)(..)(..)/);
140 fields
['red'] = hex2dec(bits
[1]);
141 fields
['green'] = hex2dec(bits
[2]);
142 fields
['blue'] = hex2dec(bits
[3]);
144 // construct the hex values
145 document
.getElementById("redinputf").value
= fields
['red'];
146 document
.getElementById("greeninputf").value
= fields
['green'];
147 document
.getElementById("blueinputf").value
= fields
['blue'];
150 // ###################################################################
151 // update the colour swatch
152 function update_swatch()
154 document
.getElementById("hexinputf").value
= document
.getElementById("hexinputf").value
.toUpperCase();
155 document
.getElementById("swatch").style
.backgroundColor
= "rgb(" + fields
['red'] + ", " + fields
['green'] + ", " + fields
['blue'] + ")";
156 document
.getElementById("swatch-red").style
.backgroundColor
= "rgb(" + fields
['red'] + ", 0, 0)";
157 document
.getElementById("swatch-green").style
.backgroundColor
= "rgb(0, " + fields
['green'] + ", 0)";
158 document
.getElementById("swatch-blue").style
.backgroundColor
= "rgb(0, 0, " + fields
['blue'] + ")";
161 // ###################################################################
162 // convert a decimal to a hexidecimal
163 function dec2hex(dec
)
165 var hexstr
= "0123456789ABCDEF";
167 var high
= (dec
- low
) / 16;
168 hex
= "" + hexstr
.charAt(high
) + hexstr
.charAt(low
);
170 return hex
.toString();
173 // ###################################################################
174 // converts a hexidecimal to a decimal
175 function hex2dec(hex
)
177 return parseInt(hex
, 16);
180 // ###################################################################
181 // ###################################################################
182 // ###################################################################
188 var front
= document
.getElementById("front");
189 var back
= document
.getElementById("back");
193 widget
.prepareForTransition("ToBack");
196 front
.style
.display
= "none";
197 back
.style
.display
= "block";
201 setTimeout("widget.performTransition();", 0);
204 document
.getElementById("fliprollie").style
.display
= "none";
209 var front
= document
.getElementById("front");
210 var back
= document
.getElementById("back");
214 widget
.prepareForTransition("ToFront");
217 back
.style
.display
= "none";
218 front
.style
.display
= "block";
222 setTimeout("widget.performTransition();", 0);
226 var flipShown
= false;
238 function mousemove(event
)
242 if (animation
.timer
!= null)
244 clearInterval(animation
.timer
);
245 animation
.timer
= null;
248 var starttime
= (new Date
).getTime() - 13;
250 animation
.duration
= 500;
251 animation
.starttime
= starttime
;
252 animation
.firstElement
= document
.getElementById("flip");
253 animation
.timer
= setInterval("animate();", 13);
254 animation
.from
= animation
.now
;
261 function mouseexit(event
)
265 // fade in the flip widget
266 if (animation
.timer
!= null)
268 clearInterval (animation
.timer
);
269 animation
.timer
= null;
272 var starttime
= (new Date
).getTime() - 13;
274 animation
.duration
= 500;
275 animation
.starttime
= starttime
;
276 animation
.firstElement
= document
.getElementById("flip");
277 animation
.timer
= setInterval("animate();", 13);
278 animation
.from
= animation
.now
;
290 var time
= (new Date
).getTime();
292 T
= limit_3(time
- animation
.starttime
, 0, animation
.duration
);
294 if (T
>= animation
.duration
)
296 clearInterval(animation
.timer
);
297 animation
.timer
= null;
298 animation
.now
= animation
.to
;
302 ease
= 0.5 - (0.5 * Math
.cos(Math
.PI
* T
/ animation
.duration
));
303 animation
.now
= compute_next_float(animation
.from
, animation
.to
, ease
);
306 animation
.firstElement
.style
.opacity
= animation
.now
;
309 function limit_3 (a
, b
, c
)
311 return a
< b
? b
: (a
> c
? c
: a
);
314 function compute_next_float(from
, to
, ease
)
316 return from
+ (to
- from
) * ease
;
319 function enterflip(event
)
321 document
.getElementById("fliprollie").style
.display
= "block";
324 function exitflip(event
)
326 document
.getElementById("fliprollie").style
.display
= "none";
329 /*=====================================================================*\
330 || ###################################################################
333 || ###################################################################
334 \*=====================================================================*/