You are here

function jquery_countdown_add in jQuery Countdown 6

Same name and namespace in other branches
  1. 5 jquery_countdown.module \jquery_countdown_add()
  2. 7.2 jquery_countdown.module \jquery_countdown_add()
  3. 7 jquery_countdown.module \jquery_countdown_add()

Adds a jQuery Countdown JavaScript element to the page.

Parameters

$selector: (optional) The jQuery selector to apply the countdown to. If a selector isn't provided, the jQuery Countdown plugin will just be added to the page.

$options: (optional) The jQuery Countdown parameters to pass to the creation of the element. The available parameters can be found at: http://keith-wood.name/countdown.html#quick

The date arguments (until or since), can either be a number representing the number of seconds, a string used to construct the JavaScript Date object, or the argument list passed to the JavaScript Date object.

The onExpiry and onTick arguments is JavaScript that will be passed through "eval()" when the events are called.

2 calls to jquery_countdown_add()
jquery_countdown_help in ./jquery_countdown.module
Implementation of hook_help().
theme_jquery_countdown in ./jquery_countdown.theme.inc
Constructs a jQuery Countdown element and adds the required JavaScript.
1 string reference to 'jquery_countdown_add'
jquery_countdown_jq in ./jquery_countdown.jq.inc
Implementation of hook_jq().

File

./jquery_countdown.module, line 101
provides the jquery_countdown theme function and serversync callback

Code

function jquery_countdown_add($selector = NULL, $options = array()) {
  global $language;

  // Add jQuery Countdown only if it hasn't been added yet.
  static $jquery_countdown_added = FALSE;
  static $added_selectors = array();
  if ($jquery_countdown_added == FALSE) {

    // Add the stylesheet and the plugin depending on if we wanted the compressed one of not.
    drupal_add_css(jquery_countdown_get_css());
    drupal_add_js(jquery_countdown_get_js());

    // Enable localization if available by uses the drupal localize t function.
    if (isset($language->language)) {
      drupal_add_js(drupal_get_path('module', 'jquery_countdown') . '/jquery.countdown-drupal.js');
    }

    // Register the jQuery Countdown behaviour.
    drupal_add_js(drupal_get_path('module', 'jquery_countdown') . '/jquery_countdown.js');
    $jquery_countdown_added = TRUE;
  }

  // Make sure to only add the same selector once.
  if (!empty($selector) && !isset($added_selectors[$selector])) {

    // store the options directly in our static selector
    $added_selectors[$selector] = $options;

    // Add the countdown element to the settings so that it's processed by the behaviours.
    drupal_add_js(array(
      'jquery_countdown' => array(
        $selector => $options,
      ),
    ), 'setting');
  }
}