You are here

function jquery_calendar_add in jQuery World Calendars API 7

API function to include specified jQuery Calendar library components while trying to take care of dups n' deps.

@todo: Add validation API for component availability.

Parameters

$components: Library components that should be loaded on the page. Either a string with a single filename or comma-separated filenames. Also it accepts an array of filenames. Allowed values are:

  • all: contains base, plus and datepicker components together.
  • base
  • plus
  • picker
  • picker.ext
  • validation
  • taiwan
  • thai
  • julian
  • persian
  • islamic
  • hebrew
  • ethiopian
  • coptic
  • mayan

$locales: Library localization files that should be loaded on the page. This can be an array, a single string or a comma-separated one. Note that compressions for these components are not available. If passed empty automatically adds the languages that are enabled in site Allowed values are:

  • lang: contains all Gregorian calendar locales.
  • picker.lang: contains all datepicker locales.
  • taiwan-zh-TW
  • thai-th
  • persian-fa
  • islamic-ar
  • hebrew-he
  • ethiopian-am
  • gregorian-af
  • gregorian-sq
  • gregorian-ar
  • gregorian-hy
  • gregorian-az
  • gregorian-eu
  • gregorian-bs
  • gregorian-bg
  • gregorian-ca
  • gregorian-zh-HK
  • gregorian-zh-CN
  • gregorian-zh-TW
  • gregorian-hr
  • gregorian-cs
  • gregorian-da
  • gregorian-nl
  • gregorian-nl-BE
  • gregorian-en-GB
  • gregorian-eo
  • gregorian-et
  • gregorian-fo
  • gregorian-fa
  • gregorian-fi
  • gregorian-fr
  • gregorian-fr-CH
  • gregorian-gl
  • gregorian-de
  • gregorian-de-CH
  • gregorian-el
  • gregorian-gu
  • gregorian-he
  • gregorian-hu
  • gregorian-is
  • gregorian-id
  • gregorian-it
  • gregorian-ja
  • gregorian-ko
  • gregorian-lv
  • gregorian-lt
  • gregorian-mk
  • gregorian-ms
  • gregorian-no
  • gregorian-pl
  • gregorian-pt-BR
  • gregorian-ro
  • gregorian-ru
  • gregorian-sr
  • gregorian-sr-SR
  • gregorian-sk
  • gregorian-sl
  • gregorian-es
  • gregorian-es-AR
  • gregorian-sv
  • gregorian-ta
  • gregorian-th
  • gregorian-ar
  • gregorian-uk
  • gregorian-ur
  • gregorian-vi
  • picker-af
  • picker-sq
  • picker-ar
  • picker-hy
  • picker-az
  • picker-eu
  • picker-bs
  • picker-bg
  • picker-ca
  • picker-zh-HK
  • picker-zh-CN
  • picker-zh-TW
  • picker-hr
  • picker-cs
  • picker-da
  • picker-nl
  • picker-nl-BE
  • picker-en-GB
  • picker-eo
  • picker-et
  • picker-fo
  • picker-fa
  • picker-fi
  • picker-fr
  • picker-fr-CH
  • picker-gl
  • picker-de
  • picker-de-CH
  • picker-el
  • picker-gu
  • picker-he
  • picker-hu
  • picker-is
  • picker-id
  • picker-it
  • picker-ja
  • picker-ko
  • picker-lv
  • picker-lt
  • picker-mk
  • picker-ms
  • picker-no
  • picker-pl
  • picker-pt-BR
  • picker-ro
  • picker-ru
  • picker-sr
  • picker-sr-SR
  • picker-sk
  • picker-sl
  • picker-es
  • picker-es-AR
  • picker-sv
  • picker-ta
  • picker-th
  • picker-ar
  • picker-uk
  • picker-ur
  • picker-vi

$theme: Datepicker theme.

$compression: Compression level:

  • normal
  • min
  • pack

See also

http://keith-wood.name/calendars.html

http://keith-wood.name/calendarsPicker.html

1 call to jquery_calendar_add()
jquery_calendar_form_demo in ./jquery_calendar.admin.inc
Form callback for jQuery World Calendars demonstration.

File

./jquery_calendar.module, line 228
Implements necessary hooks, API and helpers for jQuery World Calendars.

Code

function jquery_calendar_add($components = array(), $locales = array(), $theme = '', $compression = '') {
  static $loaded = array(
    'files' => array(),
  );

  // Add current lang to drupal js settings to be used by data pickers on runtime when nessesary
  global $language;
  $thelang = $language->language;
  $js_variables = array(
    'lang' => $thelang,
  );
  drupal_add_js(array(
    'jquery_calendar' => $js_variables,
  ), "setting");
  $compression = !empty($compression) ? $compression : variable_get('jquery_calendar_compression_level');

  // Convert input parameters to array.
  list($components, $locales) = _jquery_calendar_input_to_array($components, $locales);

  // Check if there's any additional locale available:
  $site_locales = function_exists('locale_language_list') ? locale_language_list('name', TRUE) : NULL;
  if ($site_locales && empty($locales)) {
    foreach ($site_locales as $name => $title) {
      if ($name == 'en') {
        continue;
      }
      $locales[] = 'gregorian-' . $name;
      if (in_array('picker', $components)) {
        $locales[] = 'picker-' . $name;
      }
      if (in_array('persian', $components) && $name == 'fa') {
        $locales[] = 'persian-' . $name;
      }
      if (in_array('thai', $components) && $name == 'th') {
        $locales[] = 'thai-' . $name;
      }
      if (in_array('taiwan', $components) && $name == 'zh-TW') {
        $locales[] = 'taiwan-' . $name;
      }
      if (in_array('islamic', $components) && $name == 'ar') {
        $locales[] = 'islamic-' . $name;
      }
      if (in_array('hebrew', $components) && $name == 'he') {
        $locales[] = 'hebrew-' . $name;
      }
      if (in_array('ethiopian', $components) && $name == 'am') {
        $locales[] = 'ethiopian-' . $name;
      }
    }
  }

  // Clean locales and append 'em to components.
  $length = count($locales);
  for ($i = 0; $i < $length; ++$i) {

    // Remove the gregorian prefix from locale packages.
    if (strpos($locales[$i], 'gregorian') !== FALSE) {
      $locales[$i] = str_replace('gregorian', '', $locales[$i]);
    }
  }

  // Merge components and locales.
  $components = array_merge($components, $locales);

  // See if we should add all of the library components.
  if (!isset($loaded['all']) && in_array('all', $components)) {
    $loaded['all'] = $loaded['base'] = $loaded['plus'] = $loaded['picker'] = $loaded['files']['base'] = $loaded['files']['plus'] = $loaded['files']['picker'] = TRUE;
    jquery_calendar_add(array(
      'all',
    ));
  }
  elseif (!isset($loaded['base'])) {
    $loaded['base'] = TRUE;
    jquery_calendar_add(array(
      'base',
    ));
  }

  // Fulfill dependencies & load library components.
  foreach ($components as $component) {
    if ($component == 'picker' && !isset($loaded['plus'])) {
      $loaded['plus'] = TRUE;
      jquery_calendar_add(array(
        'plus',
      ));
    }
    elseif (($component == 'picker.ext' || $component == 'validation') && !isset($loaded['picker'])) {
      $loaded['picker'] = TRUE;
      jquery_calendar_add(array(
        'picker',
      ));
    }

    // Load the component itself.
    if (!isset($loaded['files'][$component])) {
      $path = _jquery_calendar_component_path($component, $compression);

      // If the component file exists,
      // include and set appropriate flags.
      if (file_exists($path)) {
        drupal_add_js($path);
        $loaded[$component] = TRUE;
        $loaded['files'][$component] = $path;
      }
    }
  }

  // Add datepicker themes, if required.
  // TODO: Add themeroller and jQuery.UI support.
  if (isset($loaded['picker'])) {

    // Override the default theme, if necessary.
    $theme = !empty($theme) ? $theme : variable_get('jquery_calendar_datepicker_theme');

    // Add datepicker theme style.
    $path = _jquery_calendar_component_path('picker', '', 'css', "{$theme}.calendars");
    drupal_add_css($path);
  }
}