Make colorpicker work with abbreviated hex values
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 16 Dec 2010 17:20:11 +0000 (10:20 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 16 Dec 2010 20:03:01 +0000 (13:03 -0700)
horde/js/colorpicker.js

index b933e0d..a393080 100644 (file)
@@ -15,8 +15,12 @@ var ColorPicker = Class.create({
 
     initialize: function(options)
     {
+        if (options.color) {
+            options.color = Color.normalizehex(options.color);
+        }
+
         this.options = Object.extend({
-            color: 'ffffff',
+            color: '#ffffff',
             update: [],
             draggable: false,
             resizable: false,
@@ -296,6 +300,21 @@ var ColorPicker = Class.create({
  */
 var Color = {
 
+    normalizehex: function(h)
+    {
+        if (h.substring(0, 1) == '#') {
+            h = h.substring(1);
+        }
+
+        if (h.length == 3) {
+            h = h.charAt(0).times(2) +
+                h.charAt(1).times(2) +
+                h.charAt(2).times(2);
+        }
+
+        return '#' + h;
+    },
+
     hsv2hex: function(h)
     {
         return Color.rgb2hex(Color.hsv2rgb(h));