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");
42 // sanitize the number
43 var newval
= field
.value
.replace(/[^0-9\-\.]*/g
, "");
44 newval
= Math
.floor(newval
);
46 // make sure we don't go over 255
56 // update the text field
60 fields
[colour] = newval
;
69 // ###################################################################
70 // watches the hex field for updates
73 field
= document
.getElementById("hexinputf");
76 var newval
= field
.value
.replace(/[^0-9a
-f
]*/gi
, "");
79 var length
= newval
.length
;
81 // make sure we're always 6
84 newval
= newval
.substr(0, 6);
88 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);
92 for (var i
= length
; i
<= 6; i
++)
94 newval
= "" + newval
+ "0";
102 fields
['hex'] = newval
;
111 // ###################################################################
112 // update the hex value
113 function update_hex()
115 var hexstr
= dec2hex(fields
['red']) + dec2hex(fields
['green']) + dec2hex(fields
['blue']);
116 fields
['hex'] = hexstr
;
117 document
.getElementById("hexinputf").value
= hexstr
;
120 // ###################################################################
121 // update the RGB values
122 function update_rgb()
124 // regex match the bits
125 var bits
= fields
['hex'].match(/(..)(..)(..)/);
127 fields
['red'] = hex2dec(bits
[1]);
128 fields
['green'] = hex2dec(bits
[2]);
129 fields
['blue'] = hex2dec(bits
[3]);
131 // construct the hex values
132 document
.getElementById("redinputf").value
= fields
['red'];
133 document
.getElementById("greeninputf").value
= fields
['green'];
134 document
.getElementById("blueinputf").value
= fields
['blue'];
137 // ###################################################################
138 // update the colour swatch
139 function update_swatch()
141 document
.getElementById("swatch").style
.backgroundColor
= "rgb(" + fields
['red'] + ", " + fields
['green'] + ", " + fields
['blue'] + ")";
142 document
.getElementById("swatch-red").style
.backgroundColor
= "rgb(" + fields
['red'] + ", 0, 0)";
143 document
.getElementById("swatch-green").style
.backgroundColor
= "rgb(0, " + fields
['green'] + ", 0)";
144 document
.getElementById("swatch-blue").style
.backgroundColor
= "rgb(0, 0, " + fields
['blue'] + ")";
147 // ###################################################################
148 // convert a decimal to a hexidecimal
149 function dec2hex(dec
)
151 var hexstr
= "0123456789ABCDEF";
153 var high
= (dec
- low
) / 16;
154 hex
= "" + hexstr
.charAt(high
) + hexstr
.charAt(low
);
156 return hex
.toString();
159 // ###################################################################
160 // converts a hexidecimal to a decimal
161 function hex2dec(hex
)
163 return parseInt(hex
, 16);
166 // ###################################################################
167 // ###################################################################
168 // ###################################################################
174 var front
= document
.getElementById("front");
175 var back
= document
.getElementById("back");
179 widget
.prepareForTransition("ToBack");
182 front
.style
.display
= "none";
183 back
.style
.display
= "block";
187 setTimeout("widget.performTransition();", 0);
190 document
.getElementById("fliprollie").style
.display
= "none";
195 var front
= document
.getElementById("front");
196 var back
= document
.getElementById("back");
200 widget
.prepareForTransition("ToFront");
203 back
.style
.display
= "none";
204 front
.style
.display
= "block";
208 setTimeout("widget.performTransition();", 0);
212 var flipShown
= false;
224 function mousemove(event
)
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
;
247 function mouseexit(event
)
251 // fade in the flip widget
252 if (animation
.timer
!= null)
254 clearInterval (animation
.timer
);
255 animation
.timer
= null;
258 var starttime
= (new Date
).getTime() - 13;
260 animation
.duration
= 500;
261 animation
.starttime
= starttime
;
262 animation
.firstElement
= document
.getElementById("flip");
263 animation
.timer
= setInterval("animate();", 13);
264 animation
.from
= animation
.now
;
276 var time
= (new Date
).getTime();
278 T
= limit_3(time
- animation
.starttime
, 0, animation
.duration
);
280 if (T
>= animation
.duration
)
282 clearInterval(animation
.timer
);
283 animation
.timer
= null;
284 animation
.now
= animation
.to
;
288 ease
= 0.5 - (0.5 * Math
.cos(Math
.PI
* T
/ animation
.duration
));
289 animation
.now
= compute_next_float(animation
.from
, animation
.to
, ease
);
292 animation
.firstElement
.style
.opacity
= animation
.now
;
295 function limit_3 (a
, b
, c
)
297 return a
< b
? b
: (a
> c
? c
: a
);
300 function compute_next_float(from
, to
, ease
)
302 return from
+ (to
- from
) * ease
;
305 function enterflip(event
)
307 document
.getElementById("fliprollie").style
.display
= "block";
310 function exitflip(event
)
312 document
.getElementById("fliprollie").style
.display
= "none";
315 /*=====================================================================*\
316 || ###################################################################
319 || ###################################################################
320 \*=====================================================================*/