Index: colorpicker_cck.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/colorpicker/colorpicker_cck.info,v
retrieving revision 1.3
diff -u -r1.3 colorpicker_cck.info
--- colorpicker_cck.info	4 Nov 2007 02:31:20 -0000	1.3
+++ colorpicker_cck.info	18 Jul 2008 13:36:29 -0000
@@ -2,9 +2,4 @@
 name = Colorpicker Widget
 description = Adds a color picker widget.
 package = CCK
-required = colorpicker, cck
-; Information added by drupal.org packaging script on 2007-09-22
-version = "5.x-1.x-dev"
-project = "colorpicker"
-datestamp = "1190419295"
-
+dependencies = color colorpicker content
Index: colorpicker_cck.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/colorpicker/colorpicker_cck.module,v
retrieving revision 1.4
diff -u -r1.4 colorpicker_cck.module
--- colorpicker_cck.module	4 Nov 2007 04:29:54 -0000	1.4
+++ colorpicker_cck.module	18 Jul 2008 13:31:33 -0000
@@ -12,22 +12,19 @@
 function colorpicker_cck_help($section) {
   switch ($section) {
     case 'admin/modules#description':
-      return t('Defines a field type for colorpicking. <em>Note: Requires content.module.</em>');
+      return t('Defines a field type for colorpicking.');
   }
 }
 
-
 /**
  * Implementation of hook_field_info().
  */
 function colorpicker_cck_field_info() {
   return array(
     'colorpicker' => array('label' => 'Color picker'),
-	'colorpicker_textfield' => array('label' => 'Color textfield'),
-   );
+	);
 }
 
-
 /**
  * Implementation of hook_field_settings().
  */
@@ -35,16 +32,27 @@
   switch ($op) {
     case 'form':
       $form = array();
-	  // add settings here later
-	  // maybe this is the way to associate different textfields?
+      $form['width'] = array(
+        '#type' => 'textfield',
+        '#title' => t('Width'),
+        '#default_value' => isset($field['width']) ? $field['width'] : '75px',
+        '#description' => t('Width of color display box.'),
+      );
+      $form['height'] = array(
+        '#type' => 'textfield',
+        '#title' => t('Height'),
+        '#default_value' => isset($field['height']) ? $field['height'] : '25px',
+        '#description' => t('Height of color display box.'),
+      );
       return $form;
 
+    case 'save':
+      return array('width', 'height');
+
     case 'database columns':
-      if ($field['type'] == 'colorpicker_textfield') {
-       return array(
-         'value' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE),
-       );
-      }
+      return array(
+        'value' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE),
+      );
   }
 }
 
@@ -57,7 +65,7 @@
     case 'validate':
       if (is_array($items)) {
         foreach ($items as $delta => $item) {
-		  $error_field = $field['field_name'] .']['. $delta .'][value';
+		    $error_field = $field['field_name'] .']['. $delta .'][value';
           if ($item['value'] != '') {
             if (!preg_match('/^#(?:(?:[a-f\d]{3}){1,2})$/i', $item['value'])) {
               form_error($error_field, "'". check_plain($item['value']) ."'". t(' is not a valid hex color'));
@@ -66,11 +74,6 @@
         }
       }
 	  break;
-    case 'view':     
-      foreach ($node_field as $delta => $item) {
-        $node_field[$delta]['view'] = content_format($field, $item, 'colorpicker_cck', $node);
-      }
-      return theme('field', $node, $field, $node_field, $teaser, $page);
   }
 }
 
@@ -81,9 +84,17 @@
 function colorpicker_cck_field_formatter_info() {
   return array(
     'default' => array(
-      'label' => 'Colorpicker field',
+      'label' => t('hex value'),
       'field types' => array('colorpicker'),
-    )
+    ),
+    'colored' => array(
+      'label' => t('Colored span'),
+      'field types' => array('colorpicker'),
+    ),
+    'colored_value' => array(
+      'label' => t('Colored span with hex value'),
+      'field types' => array('colorpicker'),
+    ),
   );
 }
 
@@ -91,7 +102,14 @@
   if (empty($item['value'])) {
     return '';
   }
-  return check_plain($item['value']);
+  switch ($formatter) {
+    case 'colored':
+      return theme('colorpicker_cck_display', $field, $item['value'], FALSE);
+    case 'colored_value':
+      return theme('colorpicker_cck_display', $field, $item['value'], TRUE);
+    default:
+      return check_plain($item['value']);
+  }
 }
 
 
@@ -104,71 +122,50 @@
       'label' => t('Color picker'),
       'field types' => array('colorpicker'),
     ),
-	'colorpicker_textfield' => array(
-	  'label' => t('Color textfield'),
-      'field types' => array('colorpicker_textfield'),  
-	),
   );
 }
 
 /**
- * Implementation of hook_widget_settings
- */
-function colorpicker_widget_settings($op, $widget) {
-  switch ($op) {
-    case 'form':
-      $form = array();
-
-      return $form;
-
-    case 'validate':
-
-      break;
-
-    case 'save':
-      return;
-  }
-}
-
-
-/**
  * Implementation of hook_widget().
  */
 function colorpicker_cck_widget($op, &$node, $field, &$items) {
   switch ($op) {   
     case 'form':
       $form = array();
-	  if ($field['type'] == 'colorpicker_textfield') {
-        $form[$field['field_name']] = array('#tree' => TRUE);
-        $form[$field['field_name']][0]['value'] = array(
-          '#type' => 'colorpicker_textfield',
+      $form[$field['field_name']] = array('#tree' => TRUE);
+      $max = $field['multiple'] ? count($items) + 1 : 0;
+      $form[$field['field_name']][0]['value']['picker'] = array(
+          '#type' => 'colorpicker',
           '#title' => t($field['widget']['label']),
-          '#default_value' => isset($items[0]['value']) ? $items[0]['value'] : '#ffffff',
           '#required' => $field['required'],
           '#description' => t($field['widget']['description']),
           '#weight' => $field['widget']['weight'],
         );
-	  }
-	  else {
-        $form[$field['field_name']] = array('#tree' => TRUE);
-        $form[$field['field_name']][0]['value'] = array(
-          '#type' => 'colorpicker',
-          '#title' => t($field['widget']['label']),
+      for ($i = 0; $i <= $max; $i++) {
+        $form[$field['field_name']][$i]['value']['textfield'] = array(
+          '#type' => 'colorpicker_textfield',
+          '#default_value' => isset($items[$i]['value']) ? $items[$i]['value'] : '#ffffff',
           '#required' => $field['required'],
-          '#description' => t($field['widget']['description']),
-          '#weight' => $field['widget']['weight'],
+          '#weight' => $field['widget']['weight'] + .1,
+          '#colorpicker' => $form[$field['field_name']][0]['value']['picker'],
         );
-	  }
-	  return $form;
-    case 'process form values':
+      }
+  	  return $form;
+    
+  	case 'process form values':
       foreach ($items as $delta => $item) {
-        if ($item['value'] == '' && $delta > 0) {
+        if ($item['value']['textfield'] == '' && $delta > 0) {
           unset($items[$delta]); 
         }
+        else {
+          $items[$delta]['value'] = $item['value']['textfield'];
+        }
       }
       break;
-    default:
-      break;
   }           
 }
 
+function theme_colorpicker_cck_display($field, $hex, $include_value = TRUE) {
+  $output = '<div style="width:'. $field['width'] .';height:'. $field['height'] .';background-color:'. $hex .'">'. ($include_value ? check_plain($hex) : '&nbsp;') .'</div>';
+  return $output;
+}
\ No newline at end of file

