Index: jscalendar.module =================================================================== RCS file: /cvs/drupal/contributions/modules/jstools/jscalendar/jscalendar.module,v retrieving revision 1.10 diff -u -r1.10 jscalendar.module --- jscalendar.module 6 Oct 2006 04:25:38 -0000 1.10 +++ jscalendar.module 17 Oct 2006 16:32:14 -0000 @@ -1,5 +1,5 @@ 'admin/settings/jscalendar', + 'title' => t('jscalendar'), + 'callback' => 'drupal_get_form', + 'callback arguments' => array('jscalendar_admin_settings'), + 'access' => user_access('access administration pages'), + ); } + return $items; } /** @@ -36,13 +43,14 @@ foreach (element_children($form) as $key) { if (isset($form[$key]) && isset($form[$key]['#attributes']) && isset($form[$key]['#attributes']['class']) && !(strpos($form[$key]['#attributes']['class'], 'jscalendar') === FALSE)) { jscalendar_load(); - $settings = array('ifFormat', 'showsTime', 'timeFormat'); + $settings = array('timestamp', 'ifFormat', 'showsTime', 'timeFormat'); foreach ($settings as $setting) { - if (isset($form[$key]['#jscalendar_' . $setting])) { - $form[$key.'_jscalendar']['#tree'] = TRUE; + if (isset($form[$key]['#jscalendar_' . $setting])) { + $form[$key.'_jscalendar']['#tree'] = true; $form[$key.'_jscalendar'][$setting] = array( '#type' => 'hidden', - '#value' => $form[$key]['#jscalendar_' . $setting] + '#value' => $form[$key]['#jscalendar_' . $setting], + '#disabled' => ($setting != 'timestamp'), // disable values not necessary in form submit ); unset($form[$key]['#jscalendar_' . $setting]); } @@ -54,9 +62,9 @@ } /** - * Implementation of hook_settings(). + * Implementation of hook_admin_settings(). */ -function jscalendar_settings() { +function jscalendar_admin_settings() { $form['jscalendar_css'] = array( '#type' => 'select', '#title' => t('JSCalendar style'), @@ -64,7 +72,7 @@ '#default_value' => variable_get('jscalendar_css', NULL), '#options' => jscalendar_available_styles(), ); - return $form; + return system_settings_form($form); } /** @@ -124,7 +132,8 @@ drupal_add_js($path . '/lib/calendar-setup_stripped.js'); drupal_add_js($path . '/lib/lang/calendar-' . $lib_locale . '.js'); drupal_add_js($path . '/jscalendar.js'); - drupal_set_html_head(theme_stylesheet_import(base_path() . $path .'/jscalendar.css')); - drupal_set_html_head(theme_stylesheet_import(base_path() . variable_get('jscalendar_css', $path .'/lib/skins/aqua/theme.css'))); + drupal_add_css($path .'/jscalendar.css'); + drupal_add_css(variable_get('jscalendar_css', $path .'/lib/skins/aqua/theme.css')); + $loaded = TRUE; } \ No newline at end of file Index: jscalendar.js =================================================================== RCS file: /cvs/drupal/contributions/modules/jstools/jscalendar/jscalendar.js,v retrieving revision 1.7 diff -u -r1.7 jscalendar.js --- jscalendar.js 17 Sep 2006 17:32:02 -0000 1.7 +++ jscalendar.js 17 Oct 2006 16:32:32 -0000 @@ -1,33 +1,52 @@ -// $Id: jscalendar.js,v 1.7 2006/09/17 17:32:02 nedjo Exp $ +// $Id: jscalendar.js,v 1.6 2006/05/23 21:05:34 nedjo Exp $ -if (isJsEnabled()) { - addLoadEvent(function() { - // Select all input elements - inputs = document.getElementsByTagName('input'); - for (var i = 0; input = inputs[i]; ++i) { - if (input && (input.getAttribute('type') == 'text') && hasClass(input, 'jscalendar')) { - var form = input.form; +/** + * Attaches the jscalendar behaviour to all required fields + */ +Drupal.jscalendarAutoAttach = function () { + // Select all input elements + $('input.jscalendar').each(function () { + if (this && (this.getAttribute('type') == 'text')) { + var form = this.form; + var id = this.getAttribute('id'); var button = document.createElement('button'); button.appendChild(document.createTextNode(' ... ')); - button.setAttribute('id', input.getAttribute('id') + '-button'); - addClass(button, 'jscalendar-icon'); - input.parentNode.insertBefore(button, input.nextSibling); - addClass(input.parentNode, 'jscalendar'); - var settings = []; - settings['ifFormat'] = $(input.id+'_jscalendar-ifFormat') ? $(input.id+'_jscalendar-ifFormat').value : '%Y-%m-%d %H:%M:%S'; + button.setAttribute('id', id + '-button'); + $(button).addClass('jscalendar-icon'); + $(this.parentNode)[0].insertBefore(button, this.nextSibling); + + var obj = $(this.parentNode)[0]; + $(obj).addClass('jscalendar'); + //$(this.parentNode)[0].addClass('jscalendar'); + + var settings = []; + settings['ifFormat'] = this.form.elements[id + '_jscalendar-ifFormat'] ? this.form.elements[id + '_jscalendar-ifFormat'].value : '%Y-%m-%d %H:%M:%S'; // We use eval() because the result is a boolean while our input is a string. - settings['showsTime'] = $(input.id+'_jscalendar-showsTime') ? eval($(input.id+'_jscalendar-showsTime').value) : true; - settings['timeFormat'] = $(input.id+'_jscalendar-timeFormat') ? $(input.id+'_jscalendar-timeFormat').value : '12'; - Calendar.setup( + settings['showsTime'] = this.form.elements[id + '_jscalendar-showsTime'] ? eval(this.form.elements[id + '_jscalendar-showsTime'].value) : true; + settings['timeFormat'] = this.form.elements[id + '_jscalendar-timeFormat]'] ? this.form.elements[id + '_jscalendar-timeFormat]'].value : '12'; + + Calendar.setup( { - inputField : input.id, + inputField : this.id, ifFormat : settings['ifFormat'], - button : input.getAttribute('id') + '-button', + button : id + '-button', showsTime : settings['showsTime'], - timeFormat : settings['timeFormat'] + timeFormat : settings['timeFormat'], + timestamp : this.form.elements[id + '_jscalendar-timestamp'], + onUpdate : calendarUpdated } ); - } } }); } + +function calendarUpdated(cal) { + // update timestamp hidden value + var timestamp = cal.params.timestamp; + if (timestamp) timestamp.value = cal.date.print('%s'); +} + +// Global Killswitch +if (Drupal.jsEnabled) { + $(document).ready(Drupal.jscalendarAutoAttach); +}