You are here

keith_wood.inc in Countdown 7.2

File

plugins/countdown/keith_wood.inc
View source
<?php

/**
 * @file
 * Provides the jQuery Countdown Plugin by Keith Wood.
 */
$plugin = array(
  'label' => t('jQuery Countdown Plugin by Keith Wood'),
  'description' => t('A countdown with various options. Demo at <a href="http://keith-wood.name/countdown.html/">http://keith-wood.name/countdown.html/</a>.'),
  'callback' => 'countdown_keith_wood_build',
  'supported_options' => array(
    'countdown_elements',
    'event_name',
    'event_description',
  ),
);

/**
 * Countdown build callback.
 *
 * @param $plugin
 *  The plugin definition.
 * @param $countdown_options
 *  The array of options from the countdown box plugin.
 *
 * @return
 *  A build array.
 */
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,
  );
}

Functions

Namesort descending Description
countdown_keith_wood_build Countdown build callback.