You are here

function countdown_keith_wood_build in Countdown 7.2

Countdown build callback.

Parameters

$plugin: The plugin definition.

$countdown_options: The array of options from the countdown box plugin.

Return value

A build array.

1 string reference to 'countdown_keith_wood_build'
keith_wood.inc in plugins/countdown/keith_wood.inc

File

plugins/countdown/keith_wood.inc, line 30

Code

function countdown_keith_wood_build($plugin, $countdown_options) {

  // Convert the elements array into a format string.
  $format = implode('', array_filter($countdown_options['countdown_elements']));
  $format = str_replace(array(
    'year',
    'month',
    'day',
    'hour',
    'minute',
    'second',
  ), array(
    'Y',
    'O',
    // TODO: 'W',
    'D',
    'H',
    'M',
    'S',
  ), $format);
  $options = array(
    'until' => date("F d, Y g:i a", $countdown_options['countdown_target_timestamp']),
    'format' => $format,
    'description' => $countdown_options['event_description'],
    // TODO: we don't support the expiry event yet.

    //'onExpiry' => 'Drupal.jQueryCountdownEvent',

    // TODO:

    //'expiryText' => check_plain(variable_get('jquery_countdown_exp_txt', ''))

    // String conversion is fine; the script treats '10' the same as '+10'.
    'timezone' => (string) $countdown_options['countdown_target_offset'],
  );
  $id = 'jquery_countdown-' . $countdown_options['css_id'];
  $id = drupal_html_id($id);
  $selector = '#' . $id;
  $path = $plugin['path'] . '/keith_wood';
  $attach = array(
    'js' => array(
      $path . '/jquery_countdown/jquery.countdown.js' => array(
        'type' => 'file',
      ),
      $path . '/jquery_countdown.js' => array(
        'type' => 'file',
      ),
      $path . '/jquery.countdown-drupal.js' => array(
        'type' => 'file',
        'group' => JS_THEME,
      ),
    ),
    'css' => array(
      $path . '/jquery_countdown/jquery.countdown.css' => array(
        'type' => 'file',
        'media' => 'screen',
      ),
    ),
  );
  static $added_selectors = array();
  if (!empty($selector) && !isset($added_selectors[$selector])) {
    $added_selectors[$selector] = TRUE;
    $attach['js'][] = array(
      'data' => array(
        'jquery_countdown' => array(
          $selector => $options,
        ),
      ),
      'type' => 'setting',
    );
  }
  return array(
    '#markup' => '<div id="' . $id . '" class="jquery-countdown"></div>',
    '#attached' => $attach,
  );
}