The color watchers now work again.
authorrsesek <rsesek@ad1dcce9-c9fe-0310-b82b-83ea1733dbb0>
Sat, 11 Dec 2010 18:18:14 +0000 (18:18 +0000)
committerrsesek <rsesek@ad1dcce9-c9fe-0310-b82b-83ea1733dbb0>
Sat, 11 Dec 2010 18:18:14 +0000 (18:18 +0000)
git-svn-id: svn://depot/macosx/RGBConverter/trunk@633 ad1dcce9-c9fe-0310-b82b-83ea1733dbb0

RGB Converter.wdgt/Widget.css
RGB Converter.wdgt/Widget.html
RGB Converter.wdgt/Widget.js

index 3e978c1f970c4e6f1855089838d9a28e930ff81b..c889ba5ccecdf400d2fded1c77549edbf96b16b6 100644 (file)
 
 body
 {
-       margin: 0px;
-       font-family: "Lucida Grande";
-       font-weight: bold;
-       color: #FFFFFF;
+  margin: 0px;
+  font-family: "Lucida Grande";
+  font-weight: bold;
+  color: #FFFFFF;
 }
 
 a
 {
-       color: #FFFFFF;
-       text-decoration: underline;
+  color: #FFFFFF;
+  text-decoration: underline;
 }
 
 /* ################################################################### */
@@ -40,107 +40,61 @@ a
 
 #frontimage
 {
-       z-index: 500;
-       position: absolute;
+  z-index: 500;
+  position: absolute;
 }
 
 #redinput
 {
-       z-index: 1000;
-       font-size: 11px;
-       
-       position: absolute;
-       top: 30px;
-       left: 245px;
-       width: 70px;
+  z-index: 1000;
+  font-size: 11px;
+
+  border: 1px solid red;
+  text-align: center;
+
+  position: absolute;
+  top: 25px;
+  left: 100px;
 }
 
 #greeninput
 {
-       z-index: 1000;
-       font-size: 11px;
-       
-       position: absolute;
-       top: 30px;
-       left: 340px;
-       width: 75px;
-}
+  z-index: 1000;
+  font-size: 11px;
 
-#blueinput
-{
-       z-index: 1000;
-       font-size: 11px;
-       
-       position: absolute;
-       top: 30px;
-       left: 447px;
-       width: 70px;
+  border: 1px solid green;
+  text-align: center;
+
+  position: absolute;
+  top: 130px;
+  left: 100px;
 }
 
-#hexinput
+#blueinput
 {
-       z-index: 1000;
-       font-size: 11px;
-       font-weight: bold;
-       
-       position: absolute;
-       top: 30px;
-       left: 100px;
-       width: 200px;
-}
+  z-index: 1000;
+  font-size: 11px;
 
-/* ################################################################### */
+  border: 1px solid blue;
+  text-align: center;
 
-#swatch
-{
-       z-index: 100;
-       
-       position: absolute;
-       top: 25px;
-       left: 25px;
-       height: 35px;
-       width: 65px;
-       
-       background-color: rgb(60, 60, 60);
+  position: absolute;
+  top: 80px;
+  left: 7px;
 }
 
-#swatch-red
+#hexinput
 {
-       z-index: 100;
-       
-       position: absolute;
-       top: 25px;
-       left: 225px;
-       height: 35px;
-       width: 100px;
-       
-       background-color: rgb(60, 0, 0);
-}
+  z-index: 1000;
+  font-size: 11px;
+  font-weight: bold;
 
-#swatch-green
-{
-       z-index: 100;
-       
-       position: absolute;
-       top: 25px;
-       left: 325px;
-       height: 35px;
-       width: 100px;
-       
-       background-color: rgb(0, 60, 0);
-}
+  border: 1px solid black;
+  text-align: center;
 
-#swatch-blue
-{
-       z-index: 100;
-       
-       position: absolute;
-       top: 25px;
-       left: 425px;
-       height: 35px;
-       width: 100px;
-       
-       background-color: rgb(0, 0, 60);
+  position: absolute;
+  top: 80px;
+  left: 62px;
 }
 
 /* ################################################################### */
@@ -148,18 +102,18 @@ a
 
 #backtext
 {
-       position: absolute;
-       top: 29px;
-       left: 30px;
-       font-size: 10px;
+  position: absolute;
+  top: 29px;
+  left: 30px;
+  font-size: 10px;
 }
 
 #backbutton
 {
-       position: absolute;
-       top: 2px;
-       left: 440px;
-       width: 500px;
+  position: absolute;
+  top: 2px;
+  left: 440px;
+  width: 500px;
 }
 
 /* ################################################################### */
@@ -167,43 +121,43 @@ a
 
 .flip
 {
-       position: absolute;
-       top: 45px;
-       left: 510px;
-       width: 13px;
-       height: 13px;
+  position: absolute;
+  top: 45px;
+  left: 510px;
+  width: 13px;
+  height: 13px;
 }
 
 #flip
 {
-       opacity: 0;
-       background: url(file:///System/Library/WidgetResources/ibutton/white_i.png) no-repeat top left;
-       z-index: 8000;
+  opacity: 0;
+  background: url(file:///System/Library/WidgetResources/ibutton/white_i.png) no-repeat top left;
+  z-index: 8000;
 }
 
 #fliprollie
 {
-       display: none;
-       opacity: 0.25;
-       background: url(file:///System/Library/WidgetResources/ibutton/white_rollie.png) no-repeat top left;
-       z-index: 7999;
+  display: none;
+  opacity: 0.25;
+  background: url(file:///System/Library/WidgetResources/ibutton/white_rollie.png) no-repeat top left;
+  z-index: 7999;
 }
 
 #front
 {
-       display: none;
+  display: block;
 } 
 
 #back
 {
-       display: none;
+  display: none;
 } 
 
 .doneButton
 {
-       position: absolute;
-       bottom: 10px;
-       left: 10px;
+  position: absolute;
+  bottom: 10px;
+  left: 10px;
 }
 
 /*=====================================================================*\
index 9f01b36be15c7cfcf0a6f83fce70c38cf73a63a7..203c3255c07907e034c405bd22430e6739541542 100644 (file)
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 <head>
-       <title>RGB Conveter $Revision$</title>
-       <style type="text/css">
-               @import "Widget.css";
-       </style>
-       <script src="Widget.js" type="text/javascript"></script>
-       <script src="file:///System/Library/WidgetResources/button/genericButton.js" type="text/javascript"></script>
+  <title>RGB Conveter $Revision$</title>
+  <style type="text/css">
+    @import "Widget.css";
+  </style>
+  <script src="Widget.js" type="text/javascript"></script>
+  <script src="file:///System/Library/WidgetResources/button/genericButton.js" type="text/javascript"></script>
 </head>
 
 <body onload="setup()">
-    <canvas id="wheel" width="180" height="180"></canvas>
-       <!-- front -->
-    <div id="front" onmousemove="mousemove(event);" onmouseout="mouseexit(event);">
+  <!-- front -->
+    <div id="front" onmousemove="mousemove(event);" onmouseout="mouseexit(event);">    
+      <canvas id="wheel" width="180" height="180"></canvas>
+
+    <input type="text" name="hexinput" id="hexinput" size="6" onblur="hexwatcher()" value="3C3C3C" /></div>
+
+    <input type="text" name="redinput" id="redinput" size="3" onblur="rgbwatcher('red')" value="60" /></div>
+    <input type="text" name="greeninput" id="greeninput" size="3" onblur="rgbwatcher('green')" value="60" /></div>
+    <input type="text" name="blueinput" id="blueinput" size="3" onblur="rgbwatcher('blue')" value="60" /></div>
+
+    <div class="flip" id="fliprollie"></div>
+    <div class="flip" id="flip" onclick="show_back(event);" onmouseover="enterflip(event);" onmouseout="exitflip(event)";></div>
+  </div>
+  <!-- / front -->
+  
+  <!-- back -->
+  <div id="back">
+    <img src="Alternate.png" alt="" />
+    
+    <div id="backtext">
+      <div><strong style="font-size: 12px">RGB Converter</strong>, 2.2 <span id="revision">($Revision$)</span></div>
+      <div>&copy;2002-2007 <a href="javascript:widget.openURL('http://www.bluestatic.org')">Blue Static</a><div>
+    </div>
     
-               <div id="hexinput">HEX Code <input type="text" name="hexinput" id="hexinputf" size="6" onblur="hexwatcher()" value="3C3C3C" /></div>
-               
-               <div id="redinput">Red <input type="text" name="redinput" id="redinputf" size="3" onblur="rgbwatcher('red')" value="60" /></div>
-               <div id="greeninput">Green <input type="text" name="greeninput" id="greeninputf" size="3" onblur="rgbwatcher('green')" value="60" /></div>
-               <div id="blueinput">Blue <input type="text" name="blueinput" id="blueinputf" size="3" onblur="rgbwatcher('blue')" value="60" /></div>
-               
-               <div id="swatch"></div>
-               <div id="swatch-red"></div>
-               <div id="swatch-green"></div>
-               <div id="swatch-blue"></div>
-               
-               <div class="flip" id="fliprollie"></div>
-               <div class="flip" id="flip" onclick="show_back(event);" onmouseover="enterflip(event);" onmouseout="exitflip(event)";></div>
-               
-               <div id="frontimage"><img src="Default.png" alt="" style="" /></div>
-               <img src="Alternate.png" alt="" />
-       </div>
-       <!-- / front -->
-       
-       <!-- back -->
-       <div id="back">
-               <img src="Alternate.png" alt="" />
-               
-               <div id="backtext">
-                       <div><strong style="font-size: 12px">RGB Converter</strong>, 2.2 <span id="revision">($Revision$)</span></div>
-                       <div>&copy;2002-2007 <a href="javascript:widget.openURL('http://www.bluestatic.org')">Blue Static</a><div>
-               </div>
-               
-               <div id="backbutton"></div>
-       </div>
-       <!-- / back -->
+    <div id="backbutton"></div>
+  </div>
+  <!-- / back -->
 </body>
 </html>
 
index cd10c3a1dc1c0c3f2ffe8271cd1fccad4202a1eb..3697027ab46723bfdf6b104805b2097c43f3e305 100644 (file)
@@ -30,54 +30,54 @@ var colors_ = {
 function setup()
 {
   Draw();
-       createGenericButton(document.getElementById("backbutton"), "Done", hide_back, 0);
-       document.getElementById("revision").innerHTML = "(r" + document.getElementById("revision").innerHTML.replace(/[^0-9]/g, "") + ")";
+  createGenericButton(document.getElementById("backbutton"), "Done", hide_back, 0);
+  document.getElementById("revision").innerHTML = "(r" + document.getElementById("revision").innerHTML.replace(/[^0-9]/g, "") + ")";
 }
 
 // ###################################################################
 // watches the three RGB fields to make sure they don't go over the limites
-function rgbwatcher(colour)
+function rgbwatcher(color)
 {
-       field = document.getElementById(colour + "inputf");
-       
-       // handle RGB triads
-       if (triad = field.value.match(/(rgb)?\(?([0-9]{1,3}),\s?([0-9]{1,3}),\s?([0-9]{1,3})\)?/))
-       {
-               document.getElementById("redinputf").value = triad[2];
-               document.getElementById("greeninputf").value = triad[3];
-               document.getElementById("blueinputf").value = triad[4];
-               
-               rgbwatcher("red");
-               rgbwatcher("green");
-               rgbwatcher("blue");
-               return;
-       }
-       
-       // sanitize the number
-       var newval = field.value.replace(/[^0-9\-\.]*/g, "");
-       newval = Math.floor(newval);
-       
-       // make sure we don't go over 255
-       if (newval > 255)
-       {
-               newval = 255;
-       }
-       else if (newval < 0)
-       {
-               newval = 0;
-       }
-       
-       // update the text field
-       field.value = newval;
-       
-       // set fields[]
-       fields[colour] = newval;
-       
-       // set hex
-       update_hex();
-       
-       // redraw the swatch
-       update_swatch();
+  field = document.getElementById(color + "input");
+  
+  // handle RGB triads
+  if (triad = field.value.match(/(rgb)?\(?([0-9]{1,3}),\s?([0-9]{1,3}),\s?([0-9]{1,3})\)?/))
+  {
+    document.getElementById("redinput").value = triad[2];
+    document.getElementById("greeninput").value = triad[3];
+    document.getElementById("blueinput").value = triad[4];
+    
+    rgbwatcher("red");
+    rgbwatcher("green");
+    rgbwatcher("blue");
+    return;
+  }
+  
+  // sanitize the number
+  var newval = field.value.replace(/[^0-9\-\.]*/g, "");
+  newval = Math.floor(newval);
+  
+  // make sure we don't go over 255
+  if (newval > 255)
+  {
+    newval = 255;
+  }
+  else if (newval < 0)
+  {
+    newval = 0;
+  }
+  
+  // update the text field
+  field.value = newval;
+  
+  // set fields[]
+  colors_[color] = newval;
+  
+  // set hex
+  update_hex();
+  
+  // redraw the swatch
+  Draw();
 }
 
 // ###################################################################
@@ -143,7 +143,7 @@ function Draw()
 
   // Draw the inner wheel.
   context.beginPath();
-  context.arc(center[0], center[1], canvas.width / 4.5, 0, Math.PI * 2, true);
+  context.arc(center[0], center[1], canvas.width / 4.75, 0, Math.PI * 2, true);
   context.fillStyle = _GetRGBColorString();
   context.fill();
   context.strokeStyle = 'black';
@@ -178,98 +178,87 @@ function _GetComponentColorString(color)
 // watches the hex field for updates
 function hexwatcher()
 {
-       field = document.getElementById("hexinputf");
-       
-       // sanitize the hex
-       var newval = field.value.replace(/[^0-9a-f]*/gi, "");
-       
-       // get the length
-       var length = newval.length;
-       
-       // make sure we're always 6
-       if (length > 6)
-       {
-               newval = newval.substr(0, 6);
-       }
-       else if (length == 3)
-       {
-               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);
-       }
-       else if (length < 6)
-       {
-               for (var i = length; i <= 6; i++)
-               {
-                       newval = "" + newval + "0";
-               }
-       }
-       
-       // update the field
-       field.value = newval;
-       
-       // update fields[]
-       fields['hex'] = newval;
-       
-       // set RGB
-       update_rgb();
-       
-       // redraw the swatch
-       update_swatch();
+  field = document.getElementById("hexinput");
+  
+  // sanitize the hex
+  var newval = field.value.replace(/[^0-9a-f]*/gi, "");
+  
+  // get the length
+  var length = newval.length;
+  
+  // make sure we're always 6
+  if (length > 6)
+  {
+    newval = newval.substr(0, 6);
+  }
+  else if (length == 3)
+  {
+    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);
+  }
+  else if (length < 6)
+  {
+    for (var i = length; i <= 6; i++)
+    {
+      newval = "" + newval + "0";
+    }
+  }
+  
+  // update the field
+  field.value = newval;
+  
+  // update fields[]
+  colors_.hex = newval;
+  
+  // set RGB
+  update_rgb();
+  
+  // redraw the swatch
+  Draw();
 }
 
 // ###################################################################
 // update the hex value
 function update_hex()
 {
-       var hexstr = dec2hex(fields['red']) + dec2hex(fields['green']) + dec2hex(fields['blue']);
-       fields['hex'] = hexstr;
-       document.getElementById("hexinputf").value = hexstr;
+  var hexstr = dec2hex(colors_.red) + dec2hex(colors_.green) + dec2hex(colors_.blue);
+  colors_.hex = hexstr;
+  document.getElementById("hexinput").value = hexstr;
 }
 
 // ###################################################################
 // update the RGB values
 function update_rgb()
 {
-       // regex match the bits
-       var bits = fields['hex'].match(/(..)(..)(..)/);
-       
-       fields['red'] = hex2dec(bits[1]);
-       fields['green'] = hex2dec(bits[2]);
-       fields['blue'] = hex2dec(bits[3]);
-       
-       // construct the hex values
-       document.getElementById("redinputf").value = fields['red'];
-       document.getElementById("greeninputf").value = fields['green'];
-       document.getElementById("blueinputf").value = fields['blue'];
-}
-
-// ###################################################################
-// update the colour swatch
-function update_swatch()
-{
-       document.getElementById("hexinputf").value = document.getElementById("hexinputf").value.toUpperCase();
-       document.getElementById("swatch").style.backgroundColor = "rgb(" + fields['red'] + ", " + fields['green'] + ", " + fields['blue'] + ")";
-       document.getElementById("swatch-red").style.backgroundColor = "rgb(" + fields['red'] + ", 0, 0)";
-       document.getElementById("swatch-green").style.backgroundColor = "rgb(0, " + fields['green'] + ", 0)";
-       document.getElementById("swatch-blue").style.backgroundColor = "rgb(0, 0, " + fields['blue'] + ")";
+  // regex match the bits
+  var bits = colors_.hex.match(/(..)(..)(..)/);
+  
+  colors_.red = hex2dec(bits[1]);
+  colors_.green = hex2dec(bits[2]);
+  colors_.blue = hex2dec(bits[3]);
+  
+  // construct the hex values
+  document.getElementById("redinput").value = colors_.red;
+  document.getElementById("greeninput").value = colors_.green;
+  document.getElementById("blueinput").value = colors_.blue;
 }
 
 // ###################################################################
 // convert a decimal to a hexidecimal
 function dec2hex(dec)
 {
-       var hexstr = "0123456789ABCDEF";
-       var low = dec % 16;
-       var high = (dec - low) / 16;
-       hex = "" + hexstr.charAt(high) + hexstr.charAt(low);
-       
-       return hex.toString();
+  var hexstr = "0123456789ABCDEF";
+  var low = dec % 16;
+  var high = (dec - low) / 16;
+  hex = "" + hexstr.charAt(high) + hexstr.charAt(low);
+  
+  return hex.toString();
 }
 
 // ###################################################################
 // converts a hexidecimal to a decimal
 function hex2dec(hex)
 {
-       return parseInt(hex, 16);
+  return parseInt(hex, 16);
 }
 
 // ###################################################################
@@ -280,125 +269,125 @@ function hex2dec(hex)
 
 function show_back()
 {
-       var front = document.getElementById("front");
-       var back = document.getElementById("back");
-       
-       if (window.widget)
-       {
-               widget.prepareForTransition("ToBack");
-       }
-       
-       front.style.display = "none";
-       back.style.display = "block";
-       
-       if (window.widget)
-       {
-               setTimeout("widget.performTransition();", 0);   
-       }
-       
-       document.getElementById("fliprollie").style.display = "none";
+  var front = document.getElementById("front");
+  var back = document.getElementById("back");
+  
+  if (window.widget)
+  {
+    widget.prepareForTransition("ToBack");
+  }
+  
+  front.style.display = "none";
+  back.style.display = "block";
+  
+  if (window.widget)
+  {
+    setTimeout("widget.performTransition();", 0);  
+  }
+  
+  document.getElementById("fliprollie").style.display = "none";
 }
 
 function hide_back()
 {
-       var front = document.getElementById("front");
-       var back = document.getElementById("back");
-       
-       if (window.widget)
-       {
-               widget.prepareForTransition("ToFront");
-       }
-       
-       back.style.display = "none";
-       front.style.display = "block";
-       
-       if (window.widget)
-       {
-               setTimeout("widget.performTransition();", 0);
-       }
+  var front = document.getElementById("front");
+  var back = document.getElementById("back");
+  
+  if (window.widget)
+  {
+    widget.prepareForTransition("ToFront");
+  }
+  
+  back.style.display = "none";
+  front.style.display = "block";
+  
+  if (window.widget)
+  {
+    setTimeout("widget.performTransition();", 0);
+  }
 }
 
 var flipShown = false;
 
 var animation = {
-       duration : 0,
-       starttime : 0,
-       to : 1.0,
-       now : 0.0,
-       from : 0.0,
-       firstElement : null,
-       timer : null
+  duration : 0,
+  starttime : 0,
+  to : 1.0,
+  now : 0.0,
+  from : 0.0,
+  firstElement : null,
+  timer : null
 };
 
 function mousemove(event)
 {
-       if (!flipShown)
-       {
-               if (animation.timer != null)
-               {
-                       clearInterval(animation.timer);
-                       animation.timer  = null;
-               }
-               
-               var starttime = (new Date).getTime() - 13;
-               
-               animation.duration = 500;
-               animation.starttime = starttime;
-               animation.firstElement = document.getElementById("flip");
-               animation.timer = setInterval("animate();", 13);
-               animation.from = animation.now;
-               animation.to = 1.0;
-               animate();
-               flipShown = true;
-       }
+  if (!flipShown)
+  {
+    if (animation.timer != null)
+    {
+      clearInterval(animation.timer);
+      animation.timer  = null;
+    }
+    
+    var starttime = (new Date).getTime() - 13;
+    
+    animation.duration = 500;
+    animation.starttime = starttime;
+    animation.firstElement = document.getElementById("flip");
+    animation.timer = setInterval("animate();", 13);
+    animation.from = animation.now;
+    animation.to = 1.0;
+    animate();
+    flipShown = true;
+  }
 }
 
 function mouseexit(event)
 {
-       if (flipShown)
-       {
-               // fade in the flip widget
-               if (animation.timer != null)
-               {
-                       clearInterval (animation.timer);
-                       animation.timer  = null;
-               }
-               
-               var starttime = (new Date).getTime() - 13;
-               
-               animation.duration = 500;
-               animation.starttime = starttime;
-               animation.firstElement = document.getElementById("flip");
-               animation.timer = setInterval("animate();", 13);
-               animation.from = animation.now;
-               animation.to = 0.0;
-               animate();
-               flipShown = false;
-       }
+  if (flipShown)
+  {
+    // fade in the flip widget
+    if (animation.timer != null)
+    {
+      clearInterval (animation.timer);
+      animation.timer  = null;
+    }
+    
+    var starttime = (new Date).getTime() - 13;
+    
+    animation.duration = 500;
+    animation.starttime = starttime;
+    animation.firstElement = document.getElementById("flip");
+    animation.timer = setInterval("animate();", 13);
+    animation.from = animation.now;
+    animation.to = 0.0;
+    animate();
+    flipShown = false;
+  }
 }
 
 
 function animate()
 {
-       var T;
-       var ease;
-       var time = (new Date).getTime();
-               
-       T = limit_3(time - animation.starttime, 0, animation.duration);
-       
-       if (T >= animation.duration)
-       {
-               clearInterval(animation.timer);
-               animation.timer = null;
-               animation.now = animation.to;
-       }
-       else
-       {
-               ease = 0.5 - (0.5 * Math.cos(Math.PI * T / animation.duration));
-               animation.now = compute_next_float(animation.from, animation.to, ease);
-       }
-       
-       animation.firstElement.style.opacity = animation.now;
+  var T;
+  var ease;
+  var time = (new Date).getTime();
+    
+  T = limit_3(time - animation.starttime, 0, animation.duration);
+  
+  if (T >= animation.duration)
+  {
+    clearInterval(animation.timer);
+    animation.timer = null;
+    animation.now = animation.to;
+  }
+  else
+  {
+    ease = 0.5 - (0.5 * Math.cos(Math.PI * T / animation.duration));
+    animation.now = compute_next_float(animation.from, animation.to, ease);
+  }
+  
+  animation.firstElement.style.opacity = animation.now;
 }
 
 function limit_3 (a, b, c)
@@ -413,12 +402,12 @@ function compute_next_float(from, to, ease)
 
 function enterflip(event)
 {
-       document.getElementById("fliprollie").style.display = "block";
+  document.getElementById("fliprollie").style.display = "block";
 }
 
 function exitflip(event)
 {
-       document.getElementById("fliprollie").style.display = "none";
+  document.getElementById("fliprollie").style.display = "none";
 }
 
 /*=====================================================================*\