View source
<?php
$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',
),
);
function countdown_keith_wood_build($plugin, $countdown_options) {
$format = implode('', array_filter($countdown_options['countdown_elements']));
$format = str_replace(array(
'year',
'month',
'day',
'hour',
'minute',
'second',
), array(
'Y',
'O',
'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'],
'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,
);
}