Index: date.inc
===================================================================
RCS file: /cvs/drupal/contributions/modules/date/Attic/date.inc,v
retrieving revision 1.27.2.32
diff -u -F^f -r1.27.2.32 date.inc
--- date.inc	19 Apr 2007 21:06:24 -0000	1.27.2.32
+++ date.inc	5 Jul 2007 19:33:50 -0000
@@ -683,7 +683,7 @@ function date_get_timezone($handling, $t
 
 
 /**
- *  Flexible Date/Time Drop-Down Selector
+ *  Flexible Date/Time Drop-Down Selector, with optional jCalendar
  *
  *  $params = an array of values, including
  *    label = the label for the date group, default is 'Date'
@@ -704,9 +704,11 @@ function date_get_timezone($handling, $t
  *    blank_default = 1 to show an empty date field with blank values, 0 to fill with current date, default is 0
  *    required = 1 if the field must contain a valid date, default is 1
  *    description = text to be used as a description for the fieldset
+ *    jcalendar = 1 use if available, 0 do not use
  */
 function date_select_input($params) {
   drupal_add_css(DATE_API_PATH .'/date.css');
+  static $jcalendar_inline_added;
 
   // set the variables
   $label         = $params['label'] ? $params['label'] : t('Date');
@@ -727,6 +729,18 @@ function date_select_input($params) {
   $select_year   = $params['select_year'];
   $years_back    = $params['years_back'];
   $years_forward = $params['years_forward'];
+  $jcalendar     = $params['jcalendar'];
+
+  // If jCalendar is enabled, also force other defaults. The normal defaults
+  // do no longer make sense.
+  if ($jcalendar) {
+    $select_year = TRUE;
+    $select_month = TRUE;
+    $select_day = TRUE;
+
+    $years_back = 5;
+    $years_forward = 5;
+  }
 
   if ($formats['input']['am_pm']) {
     $hours_format = 'g';
@@ -870,6 +884,33 @@ function date_select_input($params) {
       '#weight' => 8,
     );
   }
+  // If jCalendar will be used for input and year, month and day are the three
+  // granularity factors, set the proper classes for the three corresponding
+  // selects and encapsulate them in a div, so jCalendar can perform its magic.
+  if ($jcalendar && count($granularity) == 3 && in_array('Y', $granularity) && in_array('M', $granularity) && in_array('D', $granularity)) {
+    // Set the classes.
+    $form['year']['#attributes'] = array('class' => 'jcalendar-select-year');
+    $form['mon']['#attributes'] = array('class' => 'jcalendar-select-month');
+    $form['mday']['#attributes'] = array('class' => 'jcalendar-select-day');
+
+    // Encapsulate the selects in a div. Note that the weights of the three
+    // selects must remain unchanged by form_alter()'s. Otherwise the XHTML
+    // will invalidate and jCalendar won't work properly.
+    $form['mday']['#prefix'] = '<div class="jcalendar-wrapper"><div class="jcalendar-selects">';
+    $form['year']['#suffix'] = '</div></div>';
+
+    // Add the JavaScript, make sure the inline code is added only once.
+    drupal_add_js(DATE_API_PATH .'/jcalendar.js', 'module');
+    if (!$jcalendar_inline_added) {
+      drupal_add_js("$(document).ready(function() { $('div.jcalendar-selects').jcalendar(); });", 'inline');
+      $jcalendar_inline_added = TRUE;
+    }
+
+    $form['#theme'] = 'date_form_jcalendar';
+  }
+  else {
+    $form['#theme'] = 'date_form_text';
+  }
   $form[] = array(
     '#theme' => 'date_form_select_description',
     '#weight' => 11,
@@ -2251,6 +2292,17 @@ function theme_date_form_jscalendar($for
 }
 
 /**
+ *  jCalendar input form
+ *
+ *  $form contains a jCalendar input form.
+ *  Make any changes needed, render it, and return the result.
+ */
+function theme_date_form_jcalendar($form) {
+  drupal_add_css(DATE_API_PATH .'/jcalendar.css');
+  return drupal_render($form);
+}
+
+/**
  *  Timezone input form
  *
  *  $form contains a timzone input form.
