You are here

function calendar_systems_attach_js_date_picker in Calendar Systems 8

Same name and namespace in other branches
  1. 7 calendar_systems.module \calendar_systems_attach_js_date_picker()
  2. 7.2 calendar_systems.module \calendar_systems_attach_js_date_picker()

Parameters

$element:

$date_format:

null $calendar_system:

null $language:

2 calls to calendar_systems_attach_js_date_picker()
calendar_systems_date_popup_process_alter in ./calendar_systems.module
Supporing date module's date_popup element hook_date_popup_process_alter
calendar_systems_form_alter in ./calendar_systems.module
Implements hook_form_alter().

File

./calendar_systems.module, line 596
Contains Calendar Systems hook implementations and helpers.

Code

function calendar_systems_attach_js_date_picker(&$element, $date_format = NULL, $time_format = NULL, $calendar_system = NULL, $language = NULL) {
  if (module_exists('jquery_calendar')) {
    calendar_systems_load_js_date_picker_library();
    $alignment = 'topLeft';
    if (is_null($language)) {
      $language = _calendar_systems_languages_active();
    }
    $languages = language_list();
    if (isset($languages[$language])) {
      if ($languages[$language]->direction) {
        $alignment = 'topRight';
      }
    }
    if (is_null($calendar_system)) {
      $calendar_system = calendar_systems_get_calendar_system_name($language);
    }
    if ($calendar_system == 'default') {
      $calendar_system = 'gregorian';
    }
    $calendar_system_name_map = array(
      'arabic' => 'islamic',
      'iranian' => 'persian',
      'gregorian' => 'gregorian',
      'thai' => 'thai',
    );
    if (is_null($date_format)) {
      $date_format = 'yyyy-mm-dd';
    }
    $time = '';
    if (!empty($time_format)) {
      $time = calendar_systems_format_date(time(), 'custom', $time_format);
    }
    if (is_null($time_format)) {
      $time_format = '';
    }
    $element['#attributes']['calendar_systems_date_popup'] = 'true';
    $element['#attributes']['calendar_systems_system_name'] = $calendar_system_name_map[$calendar_system];
    $element['#attributes']['calendar_systems_language'] = $language;
    $element['#attributes']['calendar_systems_alignment'] = $alignment;
    $element['#attributes']['calendar_systems_date_format'] = calendar_system_convert_date_format_from_php_to_js($date_format);
    $element['#attributes']['calendar_systems_time_format'] = calendar_system_convert_date_format_from_php_to_js($time_format);
    $element['#attributes']['calendar_systems_time'] = $time;
    $element['#attached']['js'] = array(
      drupal_get_path('module', 'calendar_systems') . '/calendar_systems.js',
    );
  }
}