diff --git a/date_popup/date_popup.module b/date_popup/date_popup.module index f219a72..0412301 100644 --- a/date_popup/date_popup.module +++ b/date_popup/date_popup.module @@ -34,6 +34,9 @@ function date_popup_load() { if (variable_get('date_popup_timepicker', 'default') == 'default') { drupal_add_js($path .'/lib/jquery.timeentry.pack.js'); } + elseif (variable_get('date_popup_timepicker', 'default') == 'dropdown') { + drupal_add_js($path .'/lib/date_popup.timedropdown.js'); + } $loaded = TRUE; } @@ -328,6 +331,7 @@ function date_popup_process_time(&$element, $edit = NULL, $date = NULL) { $spinner_text = array(t('Now'), t('Previous field'), t('Next field'), t('Increment'), t('Decrement')); $settings = array( 'show24Hours' => strpos($element['#date_format'], 'H') !== FALSE ? TRUE : FALSE, + 'showMinutes' => (in_array('minute', $granularity) ? TRUE : FALSE), 'showSeconds' => (in_array('second', $granularity) ? TRUE : FALSE), 'timeSteps' => array(1, intval($element['#date_increment']), (in_array('second', $granularity) ? $element['#date_increment'] : 0)), 'spinnerImage' => '', @@ -629,7 +633,12 @@ function date_popup_settings() { $form['date_popup_timepicker'] = array( '#type' => 'select', - '#options' => array('default' => t('Use default jQuery timepicker'), 'none' => t('Manual time entry, no jQuery timepicker')), +# '#options' => array('default' => t('Use default jQuery timepicker'), 'none' => t('Manual time entry, no jQuery timepicker')), + '#options' => array( + 'default' => t('Use default jQuery timepicker'), + 'dropdown' => t('Use dropdown jQuery timepicker'), + 'none' => t('Manual time entry, no jQuery timepicker'), + ), '#title' => t('Timepicker'), '#default_value' => variable_get('date_popup_timepicker', 'default'), '#description' => t("Choose the jQuery timepicker to user."), diff --git a/date_popup/lib/date_popup.timedropdown.js b/date_popup/lib/date_popup.timedropdown.js new file mode 100755 index 0000000..7b9fbdf --- /dev/null +++ b/date_popup/lib/date_popup.timedropdown.js @@ -0,0 +1,103 @@ +// $Id$ + +/** + * Attaches dropdown select behavior to time textfields. + */ +Drupal.behaviors.datePopupTimeDropdown = function (context) { + for (var id in Drupal.settings.datePopup) { + var datePopup = Drupal.settings.datePopup[id]; + var $timeWrapper = $('#' + id).parent(); + if (datePopup.func == 'timeEntry' && !$timeWrapper.hasClass('timeDropdown-processed')) { + $timeWrapper.addClass('timeDropdown-processed').attr('style', 'display:none'); + + // Compute default values. + var def_hours = datePopup.settings.show24Hours ? '00' : '12'; + var def_mins = '00'; + var def_secs = '00'; + var def_ampm = 'AM'; + var current = $('#' + id).val(); + if (current != undefined && current.length) { + def_hours = current.substr(0, 2); + if (datePopup.settings.showMinutes) { + def_mins = current.substr(3, 2); + } + if (datePopup.settings.showSeconds) { + def_secs = current.substr(6, 2); + } + if (!datePopup.settings.show24Hours) { + def_ampm = current.substr(current.length - 2, 2); + } + } + + // Generate the dropdowns. + // Hours + var hours = ''; + + // Minutes + var mins = ''; + if (datePopup.settings.showMinutes) { + mins = ''; + } + + // Seconds + var secs = ''; + if (datePopup.settings.showSeconds) { + secs = ''; + } + + // AM / PM + var ampm = ''; + if (!datePopup.settings.show24Hours) { + ampm = ''; + } + + var dropdowns = '' + Drupal.t('at') + ' ' + hours + mins + secs + ampm; + $timeWrapper.after(dropdowns); + + // Update real time field on dropdown change. + $('#' + id + '-hours, #' + id + '-mins, #' + id + '-secs, #' + id + '-ampm').bind('change', id, function(e) { + var id = e.data; + var time = $('#' + id + '-hours option:selected').val(); + time += ':' + $('#' + id + '-mins option:selected').val(); + if ($('#' + id + '-secs').length != 0) { + time += ':' + $('#' + id + '-secs option:selected').val(); + } + if ($('#' + id + '-ampm').length != 0) { + time += $('#' + id + '-ampm option:selected').val(); + } + $('#' + id).val(time); + }); + } + } +};